Skip to content

Commit 775968a

Browse files
authored
issue-4138: Fix downsizing of a multishard filesystem to a size that less ShardAllocationUnit if StrictFileSystemSizeEnforcementEnabled (#4574)
Fix downsizing of a multisharded filesystem to a size that less than ShardAllocationUnit if StrictFileSystemSizeEnforcementEnabled
1 parent 1aa104a commit 775968a

File tree

2 files changed

+75
-40
lines changed

2 files changed

+75
-40
lines changed

cloud/filestore/libs/storage/service/service_actor_alterfs.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,14 @@ void TAlterFileStoreActor::HandleDescribeFileStoreResponse(
324324
FileStoreConfig.MainFileSystemConfig.SetVersion(version);
325325
}
326326

327-
FileStoreConfig.MainFileSystemConfig.ClearBlockSize();
328-
329327
GetFileSystemTopology(ctx);
330328
}
331329

332330
////////////////////////////////////////////////////////////////////////////////
333331

334332
void TAlterFileStoreActor::AlterFileStore(const TActorContext& ctx)
335333
{
334+
FileStoreConfig.MainFileSystemConfig.ClearBlockSize();
336335
FileStoreConfig.MainFileSystemConfig.SetAlterTs(ctx.Now().MicroSeconds());
337336
auto request = std::make_unique<TEvSSProxy::TEvAlterFileStoreRequest>(
338337
FileStoreConfig.MainFileSystemConfig);
@@ -446,17 +445,16 @@ void TAlterFileStoreActor::HandleGetFileSystemTopologyResponse(
446445
MakeError(E_ARGUMENT, "Cannot decrease number of shards"));
447446
return;
448447
} else {
449-
// In strict mode we just resize all the shards
450-
const auto oldSize = FileStoreConfig.ShardConfigs.size();
451-
Y_ABORT_UNLESS(oldSize);
452-
FileStoreConfig.ShardConfigs.resize(ExistingShardIds.size());
453-
for (auto i = oldSize; i < FileStoreConfig.ShardConfigs.size(); ++i)
454-
{
455-
FileStoreConfig.ShardConfigs[i] =
456-
FileStoreConfig.ShardConfigs[oldSize - 1];
457-
FileStoreConfig.ShardConfigs[i].SetFileSystemId(
458-
ExistingShardIds[i]);
459-
}
448+
// We can't reduce shards count but in strict mode we should resize
449+
// all the shards to have the same size as the main filesystem.
450+
// So, FileStoreConfig.ShardConfigs should have the same size as
451+
// ExistingShardIds.
452+
FileStoreConfig.ShardConfigs.clear();
453+
FileStoreConfig = SetupMultiShardFileStorePerformanceAndChannels(
454+
*StorageConfig,
455+
FileStoreConfig.MainFileSystemConfig,
456+
PerformanceProfile,
457+
ExistingShardIds.size());
460458
}
461459
}
462460

@@ -509,6 +507,16 @@ void TAlterFileStoreActor::HandleGetFileSystemTopologyResponse(
509507
ShardsToAlter == 0 && ShardsToDescribe == 0 &&
510508
!ShouldConfigureMainFileStore);
511509

510+
if (StrictFileSystemSizeEnforcementEnabled) {
511+
ReplyAndDie(
512+
ctx,
513+
MakeError(
514+
E_ARGUMENT,
515+
"Cannot change shard size if "
516+
"'StrictFileSystemSizeEnforcementEnabled'"));
517+
return;
518+
}
519+
512520
FileStoreConfig.ShardConfigs.clear();
513521

514522
} else {

cloud/filestore/libs/storage/service/service_ut_sharding.cpp

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@ NProtoPrivate::TGetStorageStatsResponse GetStorageStats(
8989
return response;
9090
}
9191

92+
void CheckShardsSize(
93+
const TShardedFileSystemConfig& fsConfig,
94+
TServiceClient& service,
95+
const ui64 blocksCount)
96+
{
97+
const auto mainStats =
98+
GetStorageStats(service, fsConfig.FsId, false /* allowCache */);
99+
const auto shard1Stats = GetStorageStats(
100+
service,
101+
fsConfig.Shard1Id,
102+
false /* allowCache */,
103+
NProtoPrivate::STATS_REQUEST_MODE_FORCE_FETCH_SHARDS);
104+
const auto shard2Stats = GetStorageStats(
105+
service,
106+
fsConfig.Shard2Id,
107+
false /* allowCache */,
108+
NProtoPrivate::STATS_REQUEST_MODE_FORCE_FETCH_SHARDS);
109+
UNIT_ASSERT_EQUAL(blocksCount, mainStats.GetStats().GetTotalBlocksCount());
110+
UNIT_ASSERT_EQUAL(
111+
blocksCount,
112+
shard1Stats.GetStats().GetTotalBlocksCount());
113+
UNIT_ASSERT_EQUAL(
114+
blocksCount,
115+
shard2Stats.GetStats().GetTotalBlocksCount());
116+
}
117+
92118
} // namespace
93119

94120
////////////////////////////////////////////////////////////////////////////////
@@ -2548,35 +2574,10 @@ Y_UNIT_TEST_SUITE(TStorageServiceShardingTest)
25482574
UNIT_ASSERT_EQUAL(2, shard2Topology.ShardFileSystemIdsSize());
25492575
}
25502576

2551-
auto checkShardsSize = [&](const ui64 blocksCount)
2552-
{
2553-
const auto mainStats =
2554-
GetStorageStats(service, fsConfig.FsId, false /* allowCache */);
2555-
const auto shard1Stats = GetStorageStats(
2556-
service,
2557-
fsConfig.Shard1Id,
2558-
false /* allowCache */,
2559-
NProtoPrivate::STATS_REQUEST_MODE_FORCE_FETCH_SHARDS);
2560-
const auto shard2Stats = GetStorageStats(
2561-
service,
2562-
fsConfig.Shard2Id,
2563-
false /* allowCache */,
2564-
NProtoPrivate::STATS_REQUEST_MODE_FORCE_FETCH_SHARDS);
2565-
UNIT_ASSERT_EQUAL(
2566-
blocksCount,
2567-
mainStats.GetStats().GetTotalBlocksCount());
2568-
UNIT_ASSERT_EQUAL(
2569-
blocksCount,
2570-
shard1Stats.GetStats().GetTotalBlocksCount());
2571-
UNIT_ASSERT_EQUAL(
2572-
blocksCount,
2573-
shard2Stats.GetStats().GetTotalBlocksCount());
2574-
};
2575-
25762577
// After resizing and turning on StrictFileSystemSizeEnforcement every
25772578
// shard should have the same TotalBytesCount equal to that of the main
25782579
// filesystem
2579-
checkShardsSize(fsConfig.MainFsBlockCount());
2580+
CheckShardsSize(fsConfig, service, fsConfig.MainFsBlockCount());
25802581

25812582
// Downsize the filesystem by force
25822583
const auto newBlocksCount = fsConfig.MainFsBlockCount() / 2;
@@ -2585,7 +2586,7 @@ Y_UNIT_TEST_SUITE(TStorageServiceShardingTest)
25852586
newBlocksCount,
25862587
true /* force */);
25872588

2588-
checkShardsSize(newBlocksCount);
2589+
CheckShardsSize(fsConfig, service, newBlocksCount);
25892590

25902591
// Attempt to write one more file should fail
25912592
const auto file = createFile("notEnoughSpace");
@@ -2598,6 +2599,32 @@ Y_UNIT_TEST_SUITE(TStorageServiceShardingTest)
25982599
GenerateValidateData(fileSize, 0xBADF00D));
25992600
}
26002601

2602+
SERVICE_TEST_SIMPLE(
2603+
ShouldResizeShardsInStrictWithStrictFileSystemSizeEnforcement)
2604+
{
2605+
// Create file system with two shards 1000 * 4 * 1024 bytes each
2606+
config.SetMultiTabletForwardingEnabled(true);
2607+
config.SetStrictFileSystemSizeEnforcementEnabled(true);
2608+
TShardedFileSystemConfig fsConfig;
2609+
CREATE_ENV_AND_SHARDED_FILESYSTEM();
2610+
2611+
// Downsize the filesystem by force to a size that less than
2612+
// ShardAllocationUnit
2613+
const auto newBlocksCount = config.GetShardAllocationUnit() / 2;
2614+
service.ResizeFileStore(
2615+
fsConfig.FsId,
2616+
newBlocksCount,
2617+
true /* force */);
2618+
2619+
CheckShardsSize(fsConfig, service, newBlocksCount);
2620+
2621+
// It is prohibited to resize an individual shard if
2622+
// StrictFileSystemSizeEnforcementEnabled
2623+
service.AssertResizeFileStoreFailed(
2624+
fsConfig.Shard1Id,
2625+
newBlocksCount * 2);
2626+
}
2627+
26012628
SERVICE_TEST_SIMPLE(ShouldRetryFileSystemResize)
26022629
{
26032630
// Create a filsystem with two shards.

0 commit comments

Comments
 (0)