Skip to content

Commit

Permalink
issue-2404: correct issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vladstepanyuk committed Jan 22, 2025
1 parent b903426 commit 8436e69
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ struct TFinishedMigration
{
TString DeviceId;
ui64 SeqNo = 0;
bool IsCanceled;
bool IsCanceled =
true; // by default, this value is set to true, because
// we may not start migration if this field is set to false
};

////////////////////////////////////////////////////////////////////////////////
Expand Down
43 changes: 20 additions & 23 deletions cloud/blockstore/libs/storage/disk_registry/disk_registry_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5031,12 +5031,7 @@ void TDiskRegistryState::ApplyAgentStateChange(
}

if (agent.GetState() == NProto::AGENT_STATE_WARNING) {
if (disk.MigrationSource2Target.contains(deviceId) ||
FindIfPtr(
disk.FinishedMigrations,
[&](const auto& el)
{ return el.DeviceId == deviceId && !el.IsCanceled; }))
{
if (!NeedToStartMigration(disk, deviceId)) {
// migration already started or finished
continue;
}
Expand Down Expand Up @@ -6032,16 +6027,9 @@ void TDiskRegistryState::ApplyDeviceStateChange(
return;
}

if (disk->MigrationSource2Target.contains(uuid) ||
FindIfPtr(
disk->FinishedMigrations,
[&](const auto& el)
{ return el.DeviceId == uuid && !el.IsCanceled; }))
{
return;
if (NeedToStartMigration(*disk, uuid)) {
AddMigration(*disk, diskId, uuid);
}

AddMigration(*disk, diskId, uuid);
}

bool TDiskRegistryState::RestartDeviceMigration(
Expand Down Expand Up @@ -6112,10 +6100,8 @@ void TDiskRegistryState::CancelDeviceMigration(

const ui64 seqNo = AddReallocateRequest(db, diskId);

disk.FinishedMigrations.emplace_back(TFinishedMigration{
.DeviceId = targetId,
.SeqNo = seqNo,
.IsCanceled = true});
disk.FinishedMigrations.push_back(
{.DeviceId = targetId, .SeqNo = seqNo, .IsCanceled = true});

NProto::TDiskHistoryItem historyItem;
historyItem.SetTimestamp(now.MicroSeconds());
Expand Down Expand Up @@ -6185,10 +6171,8 @@ NProto::TError TDiskRegistryState::FinishDeviceMigration(
const ui64 seqNo = AddReallocateRequest(db, diskId);
*devIt = targetId;

disk.FinishedMigrations.emplace_back(TFinishedMigration{
.DeviceId = sourceId,
.SeqNo = seqNo,
.IsCanceled = false});
disk.FinishedMigrations.push_back(
{.DeviceId = sourceId, .SeqNo = seqNo, .IsCanceled = false});

if (disk.MasterDiskId) {
const bool replaced =
Expand Down Expand Up @@ -7585,4 +7569,17 @@ std::optional<ui64> TDiskRegistryState::GetDiskBlockCount(
return diskInfo.GetBlocksCount();
}

// static
bool TDiskRegistryState::NeedToStartMigration(
const TDiskState& disk,
const TString& deviceUUID)
{
return !(
disk.MigrationSource2Target.contains(deviceUUID) ||
FindIfPtr(
disk.FinishedMigrations,
[&](const auto& el)
{ return el.DeviceId == deviceUUID && !el.IsCanceled; }));
}

} // namespace NCloud::NBlockStore::NStorage
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,10 @@ class TDiskRegistryState
void CleanupAgentConfig(
TDiskRegistryDatabase& db,
const NProto::TAgentConfig& agent);

static bool NeedToStartMigration(
const TDiskState& disk,
const TString& deviceUUID);
};

} // namespace NCloud::NBlockStore::NStorage

0 comments on commit 8436e69

Please sign in to comment.