Skip to content

Commit

Permalink
NBS-4358: a blocksize parameter for a pool config (#171) (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpeye authored Jan 19, 2024
1 parent 0a8e91c commit 694bac7
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 26 deletions.
6 changes: 6 additions & 0 deletions cloud/blockstore/config/disk.proto
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ message TStorageDiscoveryConfig

// The maximum number of devices.
optional uint32 MaxDeviceCount = 6;

// Block size.
optional uint32 BlockSize = 7;
}

message TPathConfig
Expand All @@ -130,6 +133,9 @@ message TStorageDiscoveryConfig
optional uint32 MaxDeviceCount = 2;

repeated TPoolConfig PoolConfigs = 3;

// Default block size.
optional uint32 BlockSize = 4;
}

repeated TPathConfig PathConfigs = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ Y_UNIT_TEST_SUITE(TDeviceGeneratorTest)
layout.SetDeviceSize(93_GB);
}

NProto::TStorageDiscoveryConfig::TPoolConfig local;
local.SetPoolName("local");
local.SetHashSuffix("-local");
local.SetBlockSize(512);

TDeviceGenerator gen { Log, AgentId };

{
Expand Down Expand Up @@ -145,6 +150,22 @@ Y_UNIT_TEST_SUITE(TDeviceGeneratorTest)
"eb5e46284e440d7bb5a6aafe067fc7bc", r[139].GetDeviceId(), r[139]);
UNIT_ASSERT_VALUES_EQUAL_C(13885998366720, r[139].GetOffset(), r[139]);
}

{
gen("/dev/disk/by-partlabel/NVMECOMPUTE01", local, 1, 1, local.GetBlockSize(), 367_GB);

auto r = gen.ExtractResult();
UNIT_ASSERT_VALUES_EQUAL(1, r.size());

const auto& d = r[0];

UNIT_ASSERT_VALUES_EQUAL_C("local", d.GetPoolName(), d);
UNIT_ASSERT_VALUES_EQUAL_C(512, d.GetBlockSize(), d);
UNIT_ASSERT_VALUES_EQUAL_C(0, d.GetFileSize(), d); // the file size is set only when a layout is used

UNIT_ASSERT_VALUES_EQUAL_C(
"c7f55aef7b99489f8a47d2f94f85a88b", d.GetDeviceId(), d);
}
}

Y_UNIT_TEST_F(ShouldGenerateStableUUIDs, TFixture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ NProto::TError FindDevices(
std::regex_constants::ECMAScript
};

const ui32 defaultBlockSize = p.GetBlockSize();

for (const auto& entry: NFs::directory_iterator {pathRegExp.parent_path()}) {
const auto& path = entry.path();
const auto filename = path.filename().string();
Expand Down Expand Up @@ -119,14 +121,20 @@ NProto::TError FindDevices(
<< "unable to find the appropriate pool for " << path);
}

const ui32 blockSize = pool->GetBlockSize()
? pool->GetBlockSize()
: defaultBlockSize
? defaultBlockSize
: GetBlockSize(path);

auto error = cb(
TString {path.string()},
*pool,
deviceNumber,
pool->GetMaxDeviceCount()
? pool->GetMaxDeviceCount()
: p.GetMaxDeviceCount(),
GetBlockSize(path),
blockSize,
size);
if (HasError(error)) {
return error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ Y_UNIT_TEST_SUITE(TDeviceScannerTest)
Y_UNIT_TEST_F(ShouldScanDevices, TFixture)
{
PrepareFiles({
{ "dev/disk/by-partlabel/DEVNBS01", 160_KB }, // bs16K
{ "dev/disk/by-partlabel/DEVNBS02", 160_KB }, // bs16K
{ "dev/disk/by-partlabel/DEVNBS03", 160_KB }, // bs16K
{ "dev/disk/by-partlabel/NVMECOMPUTE01", 1_KB }, // v1
{ "dev/disk/by-partlabel/NVMECOMPUTE02", 1_KB }, // v1
{ "dev/disk/by-partlabel/NVMECOMPUTE03", 2_KB }, // v2
Expand Down Expand Up @@ -174,14 +177,27 @@ Y_UNIT_TEST_SUITE(TDeviceScannerTest)

auto& raw = *Config.AddPathConfigs();
raw.SetPathRegExp(RootDir / "dev/nvme([0-9])n1");
raw.SetBlockSize(512);

auto& rawPool = *raw.AddPoolConfigs();
rawPool.SetPoolName("raw");
rawPool.SetMinSize(1_KB);
rawPool.SetMaxSize(1_KB);

auto& bs16K = *Config.AddPathConfigs();
bs16K.SetPathRegExp(RootDir / "dev/disk/by-partlabel/DEVNBS([0-9]{2})");

auto& bs16KPool = *bs16K.AddPoolConfigs();
bs16KPool.SetPoolName("bs16K");
bs16KPool.SetMinSize(160_KB);
bs16KPool.SetMaxSize(160_KB);
bs16KPool.SetBlockSize(16_KB);
}

const std::tuple<TString, TString, ui32> expected[] {
{ RootDir / "dev/disk/by-partlabel/DEVNBS01", "bs16K", 1 },
{ RootDir / "dev/disk/by-partlabel/DEVNBS02", "bs16K", 2 },
{ RootDir / "dev/disk/by-partlabel/DEVNBS03", "bs16K", 3 },
{ RootDir / "dev/disk/by-partlabel/NVMECOMPUTE01", "v1", 1 },
{ RootDir / "dev/disk/by-partlabel/NVMECOMPUTE02", "v1", 2 },
{ RootDir / "dev/disk/by-partlabel/NVMECOMPUTE03", "v2", 3 },
Expand Down Expand Up @@ -235,7 +251,13 @@ Y_UNIT_TEST_SUITE(TDeviceScannerTest)
auto& [f, pathIndex] = r[i];
UNIT_ASSERT_VALUES_EQUAL(path, f.GetPath());
UNIT_ASSERT_VALUES_EQUAL_C(poolName, f.GetPoolName(), f);
UNIT_ASSERT_VALUES_EQUAL_C(4_KB, f.GetBlockSize(), f);
if (poolName == "bs16K") {
UNIT_ASSERT_VALUES_EQUAL_C(16_KB, f.GetBlockSize(), f);
} else if (poolName == "raw") {
UNIT_ASSERT_VALUES_EQUAL_C(512, f.GetBlockSize(), f);
} else {
UNIT_ASSERT_VALUES_EQUAL_C(4_KB, f.GetBlockSize(), f);
}
UNIT_ASSERT_VALUES_EQUAL_C(expectedPathIndex, pathIndex, f);
}
}
Expand Down
Loading

0 comments on commit 694bac7

Please sign in to comment.