Skip to content

Commit

Permalink
Do the lite reallocation when only IOModeTs is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
komarevtsev-d committed Jan 14, 2025
1 parent c7fd32f commit 32cfa5a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ bool ValidateDevices(
return ok;
}

std::unique_ptr<MessageDifferencer> CreateNodeIdChangeDifferencer()
std::unique_ptr<MessageDifferencer> CreateLiteReallocationDifferencer()
{
const auto* ioModeTsDescriptor =
NProto::TVolumeMeta::GetDescriptor()->FindFieldByName("IOModeTs");
// These are two fields that will change during disk agent blue-green
// deploy.
const auto* nodeIdDescriptor =
NProto::TDeviceConfig::GetDescriptor()->FindFieldByName("NodeId");
const auto* rdmaPortDescriptor =
NProto::TRdmaEndpoint::GetDescriptor()->FindFieldByName("Port");
if (!nodeIdDescriptor || !rdmaPortDescriptor) {
if (!nodeIdDescriptor || !rdmaPortDescriptor || !ioModeTsDescriptor) {
ReportFieldDescriptorNotFound(
TStringBuilder()
<< "Lite reallocation is impossible. nodeIdDescriptor = "
Expand All @@ -129,6 +131,7 @@ std::unique_ptr<MessageDifferencer> CreateNodeIdChangeDifferencer()
}

auto diff = std::make_unique<MessageDifferencer>();
diff->IgnoreField(ioModeTsDescriptor);
diff->IgnoreField(nodeIdDescriptor);
diff->IgnoreField(rdmaPortDescriptor);
diff->set_float_comparison(
Expand Down Expand Up @@ -538,7 +541,7 @@ void TVolumeActor::ExecuteUpdateDevices(

Y_DEBUG_ABORT_UNLESS(State->IsDiskRegistryMediaKind());
if (Config->GetAllowLiteDiskReallocations()) {
auto differencer = CreateNodeIdChangeDifferencer();
auto differencer = CreateLiteReallocationDifferencer();
args.LiteReallocation =
differencer && differencer->Compare(oldMeta, newMeta);
}
Expand Down
39 changes: 36 additions & 3 deletions cloud/blockstore/libs/storage/volume/volume_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5050,10 +5050,12 @@ Y_UNIT_TEST_SUITE(TVolumeTest)

Y_UNIT_TEST(ShouldDoLiteReallocations)
{
auto runtime = PrepareTestActorRuntime();
auto state = MakeIntrusive<TDiskRegistryState>();
auto runtime = PrepareTestActorRuntime(
NProto::TStorageServiceConfig(), state);

const auto expectedBlockCount = DefaultDeviceBlockSize * DefaultDeviceBlockCount
/ DefaultBlockSize;
const auto expectedBlockCount =
DefaultDeviceBlockSize * DefaultDeviceBlockCount / DefaultBlockSize;
const auto expectedDeviceCount = 3;

TVolumeClient volume(*runtime);
Expand All @@ -5077,6 +5079,9 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
auto metaHistory = volume.ReadMetaHistory();
UNIT_ASSERT_VALUES_EQUAL(S_OK, metaHistory->Error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(1, metaHistory->MetaHistory.size());
UNIT_ASSERT_VALUES_EQUAL(
0,
metaHistory->MetaHistory[0].Meta.GetIOModeTs());
}

{
Expand Down Expand Up @@ -5149,6 +5154,34 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
auto metaHistory = volume.ReadMetaHistory();
UNIT_ASSERT_VALUES_EQUAL(S_OK, metaHistory->Error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(2, metaHistory->MetaHistory.size());
UNIT_ASSERT_VALUES_EQUAL(
0,
metaHistory->MetaHistory[1].Meta.GetIOModeTs());
}

runtime->SetEventFilter([](TTestActorRuntimeBase&,
TAutoPtr<IEventHandle>&) { return false; });
auto now = Now();
state->Disks["vol0"].IOModeTs = now;
volume.ReallocateDisk();
{
// Lite reallocation happened. Meta history still contains 2 items.
auto metaHistory = volume.ReadMetaHistory();
UNIT_ASSERT_VALUES_EQUAL(S_OK, metaHistory->Error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(2, metaHistory->MetaHistory.size());
}

state->Disks["vol0"].MuteIOErrors = true;
volume.ReallocateDisk();
{
// No lite reallocation, since MuteIOErrors has changed. Meta
// history contains 3 items now.
auto metaHistory = volume.ReadMetaHistory();
UNIT_ASSERT_VALUES_EQUAL(S_OK, metaHistory->Error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(3, metaHistory->MetaHistory.size());
UNIT_ASSERT_VALUES_EQUAL(
now.MicroSeconds(),
metaHistory->MetaHistory.back().Meta.GetIOModeTs());
}
}

Expand Down

0 comments on commit 32cfa5a

Please sign in to comment.