Skip to content

Commit

Permalink
issue-1384: add force flag to destroy fs (#1554)
Browse files Browse the repository at this point in the history
issue: #1384

1. Add AllowFileStoreForceDestroy flag to storage configuration
2. Add ForceDestroy flag to filestore client

ForceDestroy flag should allow to destroy mounted filestore(with active sessions) if it's allowed in the storage configuration.
  • Loading branch information
antonmyagkov committed Jul 15, 2024
1 parent 9cc7756 commit 12732ce
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 6 deletions.
9 changes: 9 additions & 0 deletions cloud/filestore/apps/client/lib/destroy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ namespace {
class TDestroyCommand final
: public TFileStoreCommand
{
private:
bool ForceDestroy = false;

public:
TDestroyCommand()
{
Opts.AddLongOption("force").StoreTrue(&ForceDestroy);
}

bool Execute() override
{
auto callContext = PrepareCallContext();

auto request = std::make_shared<NProto::TDestroyFileStoreRequest>();
request->SetFileSystemId(FileSystemId);
request->SetForceDestroy(ForceDestroy);

auto response = WaitFor(
Client->DestroyFileStore(
Expand Down
3 changes: 3 additions & 0 deletions cloud/filestore/config/storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,7 @@ message TStorageConfig

// Controls BlobIndexOps' priority over each other.
optional EBlobIndexOpsPriority BlobIndexOpsPriority = 356;

// Allow to destroy filestore with active sessions
optional bool AllowFileStoreForceDestroy = 357;
}
1 change: 1 addition & 0 deletions cloud/filestore/libs/storage/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ namespace {
TDuration::Seconds(10) )\
xxx(PreferredBlockSizeMultiplier, ui32, 1 )\
xxx(MultiTabletForwardingEnabled, bool, false )\
xxx(AllowFileStoreForceDestroy, bool, false )\
// FILESTORE_STORAGE_CONFIG

#define FILESTORE_DECLARE_CONFIG(name, type, value) \
Expand Down
2 changes: 2 additions & 0 deletions cloud/filestore/libs/storage/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class TStorageConfig

NProto::EBlobIndexOpsPriority GetBlobIndexOpsPriority() const;

bool GetAllowFileStoreForceDestroy() const;

void Dump(IOutputStream& out) const;
void DumpHtml(IOutputStream& out) const;
void DumpOverridesHtml(IOutputStream& out) const;
Expand Down
19 changes: 15 additions & 4 deletions cloud/filestore/libs/storage/service/service_actor_destroyfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class TDestroyFileStoreActor final
private:
const TRequestInfoPtr RequestInfo;
const TString FileSystemId;
const bool ForceDestroy;

public:
TDestroyFileStoreActor(
TRequestInfoPtr requestInfo,
TString fileSystemId);
TString fileSystemId,
bool forceDestroy);

void Bootstrap(const TActorContext& ctx);

Expand Down Expand Up @@ -58,14 +60,20 @@ class TDestroyFileStoreActor final

TDestroyFileStoreActor::TDestroyFileStoreActor(
TRequestInfoPtr requestInfo,
TString fileSystemId)
TString fileSystemId,
bool forceDestroy)
: RequestInfo(std::move(requestInfo))
, FileSystemId(std::move(fileSystemId))
, ForceDestroy(forceDestroy)
{}

void TDestroyFileStoreActor::Bootstrap(const TActorContext& ctx)
{
DescribeSessions(ctx);
if (ForceDestroy) {
DestroyFileStore(ctx);
} else {
DescribeSessions(ctx);
}
Become(&TThis::StateWork);
}

Expand Down Expand Up @@ -177,9 +185,12 @@ void TStorageServiceActor::HandleDestroyFileStore(
cookie,
msg->CallContext);

bool forceDestroy = msg->Record.GetForceDestroy() &&
StorageConfig->GetAllowFileStoreForceDestroy();
auto actor = std::make_unique<TDestroyFileStoreActor>(
std::move(requestInfo),
msg->Record.GetFileSystemId());
msg->Record.GetFileSystemId(),
forceDestroy);

NCloud::Register(ctx, std::move(actor));
}
Expand Down
44 changes: 44 additions & 0 deletions cloud/filestore/libs/storage/service/service_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4877,6 +4877,50 @@ Y_UNIT_TEST_SUITE(TStorageServiceTest)
nodeId1,
createHandleResponse->Record.GetNodeAttr().GetId());
}

Y_UNIT_TEST(ShouldForceDestroyWithAllowFileStoreForceDestroyFlag)
{
NProto::TStorageConfig storageConfig;
storageConfig.SetAllowFileStoreForceDestroy(true);
TTestEnv env({}, storageConfig);
env.CreateSubDomain("nfs");
ui32 nodeIdx = env.CreateNode("nfs");
const TString fsId = "test";
const auto initialBlockCount = 1'000;
TServiceClient service(env.GetRuntime(), nodeIdx);
service.CreateFileStore(fsId, initialBlockCount);

auto headers = THeaders{fsId, "client", ""};
auto createSessionResponse = service.CreateSession(headers);
UNIT_ASSERT_VALUES_EQUAL_C(
S_OK,
createSessionResponse->GetStatus(),
createSessionResponse->GetErrorReason());
auto destroyFileStoreResponse = service.DestroyFileStore(fsId, true);
UNIT_ASSERT_VALUES_EQUAL_C(
S_OK,
destroyFileStoreResponse->GetStatus(),
destroyFileStoreResponse->GetErrorReason());
}

Y_UNIT_TEST(ForceDestroyWithoutAllowFileStoreForceDestroyFlagShouldFail)
{
TTestEnv env;
env.CreateSubDomain("nfs");
ui32 nodeIdx = env.CreateNode("nfs");
const TString fsId = "test";
const auto initialBlockCount = 1'000;
TServiceClient service(env.GetRuntime(), nodeIdx);
service.CreateFileStore(fsId, initialBlockCount);

auto headers = THeaders{fsId, "client", ""};
auto createSessionResponse = service.CreateSession(headers);
UNIT_ASSERT_VALUES_EQUAL_C(
S_OK,
createSessionResponse->GetStatus(),
createSessionResponse->GetErrorReason());
service.AssertDestroyFileStoreFailed(fsId, true);
}
}

} // namespace NCloud::NFileStore::NStorage
8 changes: 6 additions & 2 deletions cloud/filestore/libs/storage/testlib/service_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,14 @@ class TServiceClient
return request;
}

auto CreateDestroyFileStoreRequest(const TString& fileSystemId)
auto CreateDestroyFileStoreRequest(
const TString& fileSystemId,
bool forceDestroy = false)
{
auto request = std::make_unique<TEvService::TEvDestroyFileStoreRequest>();
auto request =
std::make_unique<TEvService::TEvDestroyFileStoreRequest>();
request->Record.SetFileSystemId(fileSystemId);
request->Record.SetForceDestroy(forceDestroy);
return request;
}

Expand Down
3 changes: 3 additions & 0 deletions cloud/filestore/public/api/protos/fs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ message TDestroyFileStoreRequest

// FileSystem identifier.
string FileSystemId = 2;

// Destroy mounted filestore
bool ForceDestroy = 3;
}

message TDestroyFileStoreResponse
Expand Down

0 comments on commit 12732ce

Please sign in to comment.