Skip to content

Commit

Permalink
issue-1932: use ceil instead of floor for calculating shards count
Browse files Browse the repository at this point in the history
  • Loading branch information
debnatkh committed Feb 5, 2025
1 parent 251f1d6 commit 5dd0889
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
7 changes: 6 additions & 1 deletion cloud/filestore/libs/storage/core/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,12 @@ ui32 ComputeShardCount(
{
const double fileStoreSize = blocksCount * blockSize;

const ui32 shardCount = std::floor(fileStoreSize / shardAllocationUnit);
if (fileStoreSize < shardAllocationUnit) {
// No need in using sharding for small enough filesystems
return 0;
}

const ui32 shardCount = std::ceil(fileStoreSize / shardAllocationUnit);
return Min(shardCount, MaxShardCount);
}

Expand Down
18 changes: 17 additions & 1 deletion cloud/filestore/libs/storage/core/model_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2293,20 +2293,36 @@ Y_UNIT_TEST_SUITE(TModel)
{
using namespace ::NCloud::NProto;
KikimrConfig.SetBlockSize(4_KB);
KikimrConfig.SetBlocksCount(4_TB / 4_KB);

// Disable media type override.
StorageConfig.SetAutomaticShardCreationEnabled(true);
StorageConfig.SetShardAllocationUnit(4_TB);
StorageConfig.SetAutomaticallyCreatedShardSize(5_TB);

KikimrConfig.SetBlocksCount(4_TB / 4_KB);
auto fs = SetupMultiShardFileStorePerformanceAndChannels(
StorageConfig,
KikimrConfig,
ClientPerformanceProfile,
0);
UNIT_ASSERT_VALUES_EQUAL(1, fs.ShardConfigs.size());

KikimrConfig.SetBlocksCount(4_TB / 4_KB + 1);
fs = SetupMultiShardFileStorePerformanceAndChannels(
StorageConfig,
KikimrConfig,
ClientPerformanceProfile,
0);
UNIT_ASSERT_VALUES_EQUAL(2, fs.ShardConfigs.size());

KikimrConfig.SetBlocksCount(5_TB / 4_KB);
fs = SetupMultiShardFileStorePerformanceAndChannels(
StorageConfig,
KikimrConfig,
ClientPerformanceProfile,
0);
UNIT_ASSERT_VALUES_EQUAL(2, fs.ShardConfigs.size());

KikimrConfig.SetBlocksCount(16_TB / 4_KB);
fs = SetupMultiShardFileStorePerformanceAndChannels(
StorageConfig,
Expand Down
6 changes: 3 additions & 3 deletions cloud/filestore/libs/storage/service/service_ut_sharding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3717,6 +3717,9 @@ Y_UNIT_TEST_SUITE(TStorageServiceShardingTest)

service.ResizeFileStore(fsId, (4_GB - 4_KB) / 4_KB);

expected = TVector<TString>{
fsId, fsId + "_s1", fsId + "_s2", fsId + "_s3", fsId + "_s4"
};
listing = service.ListFileStores();
fsIds = listing->Record.GetFileStores();
ids = TVector<TString>(fsIds.begin(), fsIds.end());
Expand All @@ -3725,9 +3728,6 @@ Y_UNIT_TEST_SUITE(TStorageServiceShardingTest)

service.ResizeFileStore(fsId, 4_GB / 4_KB);

expected = TVector<TString>{
fsId, fsId + "_s1", fsId + "_s2", fsId + "_s3", fsId + "_s4"
};
listing = service.ListFileStores();
fsIds = listing->Record.GetFileStores();
ids = TVector<TString>(fsIds.begin(), fsIds.end());
Expand Down

0 comments on commit 5dd0889

Please sign in to comment.