Skip to content

Commit

Permalink
Deduce MediaKind from PoolKind while creating a disk from device (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
komarevtsev-d committed Sep 18, 2024
1 parent 4b1038b commit 34cf8b3
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6921,7 +6921,7 @@ NProto::TError TDiskRegistryState::CreateDiskFromDevices(
}

TVector<TString> deviceIds;
int poolKind = -1;
std::optional<NProto::EDevicePoolKind> poolKind;

for (auto& device: devices) {
auto [config, error] = FindDevice(device);
Expand All @@ -6937,15 +6937,15 @@ NProto::TError TDiskRegistryState::CreateDiskFromDevices(

const auto& uuid = config.GetDeviceUUID();

if (poolKind == -1) {
poolKind = static_cast<int>(config.GetPoolKind());
if (!poolKind) {
poolKind = config.GetPoolKind();
}

if (static_cast<int>(config.GetPoolKind()) != poolKind) {
if (config.GetPoolKind() != *poolKind) {
return MakeError(E_ARGUMENT, TStringBuilder() <<
"several device pool kinds for one disk: " <<
static_cast<int>(config.GetPoolKind()) << " and " <<
poolKind);
static_cast<int>(*poolKind));
}

if (!force
Expand Down Expand Up @@ -6991,6 +6991,9 @@ NProto::TError TDiskRegistryState::CreateDiskFromDevices(
disk.LogicalBlockSize = blockSize;
disk.StateTs = now;
disk.State = CalculateDiskState(disk);
if (poolKind == NProto::DEVICE_POOL_KIND_LOCAL) {
disk.MediaKind = NProto::STORAGE_MEDIA_SSD_LOCAL;
}

for (auto& uuid: deviceIds) {
DeviceList.MarkDeviceAllocated(diskId, uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,57 @@ Y_UNIT_TEST_SUITE(TDiskRegistryStateCreateTest)
});

const ui32 nativeBlockSize = 512;
const ui64 adjustedBlockCount = 93_GB / nativeBlockSize;
const ui64 adjustedBlockCount = 10_GB / nativeBlockSize;
const ui64 unAdjustedBlockCount = adjustedBlockCount + 100;

auto deviceConfig = [&] (auto name, auto uuid) {
auto deviceConfig = [&] (auto name, auto uuid, bool local) {
NProto::TDeviceConfig config;

config.SetDeviceName(name);
config.SetDeviceUUID(uuid);
config.SetBlockSize(nativeBlockSize);
config.SetBlocksCount(adjustedBlockCount);
config.SetUnadjustedBlockCount(unAdjustedBlockCount);
if (local) {
config.SetPoolKind(NProto::DEVICE_POOL_KIND_LOCAL);
config.SetPoolName("local-ssd");
}

return config;
};

TVector agents {
AgentConfig(1, {
deviceConfig("dev-1", "uuid-1.1"), // disk-1
deviceConfig("dev-2", "uuid-1.2"),
deviceConfig("dev-3", "uuid-1.3"),
deviceConfig("dev-1", "uuid-1.1", false), // disk-1
deviceConfig("dev-2", "uuid-1.2", false),
deviceConfig("dev-3", "uuid-1.3", false),
deviceConfig("dev-4", "uuid-1.4", true),
deviceConfig("dev-5", "uuid-1.5", true),
}),
AgentConfig(2, {
deviceConfig("dev-1", "uuid-2.1"), // dirty
deviceConfig("dev-2", "uuid-2.2"),
deviceConfig("dev-3", "uuid-2.3"),
deviceConfig("dev-4", "uuid-2.4"),
deviceConfig("dev-1", "uuid-2.1", false), // dirty
deviceConfig("dev-2", "uuid-2.2", false),
deviceConfig("dev-3", "uuid-2.3", false),
deviceConfig("dev-4", "uuid-2.4", false),
deviceConfig("dev-5", "uuid-2.5", true),
})
};

TDiskRegistryState state =
TDiskRegistryStateBuilder()
.WithKnownAgents(agents)
.WithAgents(agents)
.WithConfig(
[&]
{
auto config = MakeConfig(agents);
auto* pool = config.AddDevicePoolConfigs();
pool->SetName("local-ssd");
pool->SetKind(NProto::DEVICE_POOL_KIND_LOCAL);
pool->SetAllocationUnit(
adjustedBlockCount * nativeBlockSize);

return config;
}())
.WithDisks({Disk("disk-1", {"uuid-1.1"})})
.WithDirtyDevices({TDirtyDevice{"uuid-2.1", {}}})
.Build();
Expand Down Expand Up @@ -171,6 +190,9 @@ Y_UNIT_TEST_SUITE(TDiskRegistryStateCreateTest)
UNIT_ASSERT_SUCCESS(state.GetDiskInfo("bar", info));

UNIT_ASSERT_EQUAL(NProto::DISK_STATE_ONLINE, info.State);
UNIT_ASSERT_EQUAL(
NProto::STORAGE_MEDIA_SSD_NONREPLICATED,
info.MediaKind);
UNIT_ASSERT_VALUES_EQUAL(1, info.Devices.size());
UNIT_ASSERT_VALUES_EQUAL(unAdjustedBlockCount, info.Devices[0].GetBlocksCount());
UNIT_ASSERT_VALUES_EQUAL("uuid-2.1", info.Devices[0].GetDeviceUUID());
Expand Down Expand Up @@ -203,6 +225,9 @@ Y_UNIT_TEST_SUITE(TDiskRegistryStateCreateTest)
UNIT_ASSERT_SUCCESS(state.GetDiskInfo("baz", info));

UNIT_ASSERT_EQUAL(NProto::DISK_STATE_ONLINE, info.State);
UNIT_ASSERT_EQUAL(
NProto::STORAGE_MEDIA_SSD_NONREPLICATED,
info.MediaKind);
UNIT_ASSERT_VALUES_EQUAL(2, info.Devices.size());
UNIT_ASSERT_VALUES_EQUAL("uuid-1.2", info.Devices[0].GetDeviceUUID());
UNIT_ASSERT_VALUES_EQUAL("uuid-2.2", info.Devices[1].GetDeviceUUID());
Expand Down Expand Up @@ -235,6 +260,9 @@ Y_UNIT_TEST_SUITE(TDiskRegistryStateCreateTest)
UNIT_ASSERT_SUCCESS(state.GetDiskInfo("nonrepl", info));

UNIT_ASSERT_EQUAL(NProto::DISK_STATE_ONLINE, info.State);
UNIT_ASSERT_EQUAL(
NProto::STORAGE_MEDIA_SSD_NONREPLICATED,
info.MediaKind);
UNIT_ASSERT_VALUES_EQUAL(2, info.Devices.size());
UNIT_ASSERT_VALUES_EQUAL("uuid-2.3", info.Devices[0].GetDeviceUUID());
UNIT_ASSERT_VALUES_EQUAL("uuid-1.3", info.Devices[1].GetDeviceUUID());
Expand Down Expand Up @@ -268,6 +296,9 @@ Y_UNIT_TEST_SUITE(TDiskRegistryStateCreateTest)
UNIT_ASSERT_SUCCESS(state.GetDiskInfo("nonrepl-4K", info));

UNIT_ASSERT_EQUAL(NProto::DISK_STATE_ONLINE, info.State);
UNIT_ASSERT_EQUAL(
NProto::STORAGE_MEDIA_SSD_NONREPLICATED,
info.MediaKind);
UNIT_ASSERT_VALUES_EQUAL(1, info.Devices.size());
UNIT_ASSERT_VALUES_EQUAL("uuid-2.4", info.Devices[0].GetDeviceUUID());
UNIT_ASSERT_VALUES_EQUAL(
Expand All @@ -282,6 +313,39 @@ Y_UNIT_TEST_SUITE(TDiskRegistryStateCreateTest)
UNIT_ASSERT_VALUES_EQUAL(4_KB, info.LogicalBlockSize);
UNIT_ASSERT_VALUES_EQUAL(2000, info.StateTs.GetValue());
});

// local
executor.WriteTx([&] (TDiskRegistryDatabase db) {
TDiskRegistryState::TAllocateDiskResult result {};
auto error = state.CreateDiskFromDevices(
TInstant::FromValue(1000),
db,
false, // force
"local",
nativeBlockSize,
{
deviceByUUID("uuid-1.4"),
deviceByUUID("uuid-1.5")
},
&result);

UNIT_ASSERT_VALUES_EQUAL_C(S_OK, error.GetCode(), error.GetMessage());

UNIT_ASSERT_VALUES_EQUAL(2, result.Devices.size());
UNIT_ASSERT_VALUES_EQUAL("uuid-1.4", result.Devices[0].GetDeviceUUID());
UNIT_ASSERT_VALUES_EQUAL("uuid-1.5", result.Devices[1].GetDeviceUUID());

TDiskInfo info;
UNIT_ASSERT_SUCCESS(state.GetDiskInfo("local", info));

UNIT_ASSERT_EQUAL(NProto::DISK_STATE_ONLINE, info.State);
UNIT_ASSERT_EQUAL(NProto::STORAGE_MEDIA_SSD_LOCAL, info.MediaKind);
UNIT_ASSERT_VALUES_EQUAL(2, info.Devices.size());
UNIT_ASSERT_VALUES_EQUAL("uuid-1.4", info.Devices[0].GetDeviceUUID());
UNIT_ASSERT_VALUES_EQUAL("uuid-1.5", info.Devices[1].GetDeviceUUID());
UNIT_ASSERT_VALUES_EQUAL(nativeBlockSize, info.LogicalBlockSize);
UNIT_ASSERT_VALUES_EQUAL(1000, info.StateTs.GetValue());
});
}

Y_UNIT_TEST(ShouldCollectMTBF)
Expand Down

0 comments on commit 34cf8b3

Please sign in to comment.