Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
komarevtsev-d committed Jan 28, 2025
1 parent 73dfaf5 commit 44ea4ba
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 87 deletions.
7 changes: 2 additions & 5 deletions cloud/blockstore/libs/storage/protos/disk.proto
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,13 @@ message TLaggingAgent
// Agent id.
string AgentId = 1;

// Node that agent is running on.
uint32 NodeId = 2;

// Index of the mirror disk replica.
// 0 - main devices
// 1,2 - replica devices
uint32 ReplicaIndex = 3;
uint32 ReplicaIndex = 2;

// A list of devices that belong to the agent.
repeated TLaggingDevice Devices = 4;
repeated TLaggingDevice Devices = 3;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
101 changes: 29 additions & 72 deletions cloud/blockstore/libs/storage/volume/model/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace {
////////////////////////////////////////////////////////////////////////////////

using google::protobuf::RepeatedPtrField;
using TDeviceMatcher = std::function<bool(const NProto::TDeviceConfig& device)>;

struct TLaggingDeviceIndexCmp
{
Expand Down Expand Up @@ -98,10 +97,30 @@ std::optional<TDeviceLocation> FindDeviceLocation(
return std::nullopt;
}

[[nodiscard]] std::optional<ui32> FindReplicaIndex(
} // namespace

////////////////////////////////////////////////////////////////////////////////

const NProto::TDeviceConfig* FindDeviceConfig(
const NProto::TVolumeMeta& meta,
const TDeviceMatcher& deviceMatcher)
TStringBuf deviceUUID)
{
auto deviceLocation = FindDeviceLocation(meta, deviceUUID);
if (!deviceLocation) {
return nullptr;
}
return &GetDeviceConfig(meta, *deviceLocation);
}

std::optional<ui32> FindReplicaIndexByAgentId(
const NProto::TVolumeMeta& meta,
TStringBuf agentId)
{
const auto deviceMatcher = [agentId](const NProto::TDeviceConfig& device)
{
return device.GetAgentId() == agentId;
};

for (size_t i = 0; i <= meta.ReplicasSize(); i++) {
const auto& devices = GetReplicaDevices(meta, i);
if (AnyOf(devices, deviceMatcher)) {
Expand All @@ -122,11 +141,16 @@ std::optional<TDeviceLocation> FindDeviceLocation(
return std::nullopt;
}

[[nodiscard]] TVector<NProto::TLaggingDevice> CollectLaggingDevices(
TVector<NProto::TLaggingDevice> CollectLaggingDevices(
const NProto::TVolumeMeta& meta,
ui32 replicaIndex,
const TDeviceMatcher& deviceMatcher)
TStringBuf agentId)
{
const auto deviceMatcher = [agentId](const NProto::TDeviceConfig& device)
{
return device.GetAgentId() == agentId;
};

TVector<NProto::TLaggingDevice> result;
const auto replicaDevices = GetReplicaDevices(meta, replicaIndex);
for (int i = 0; i < replicaDevices.size(); i++) {
Expand Down Expand Up @@ -163,73 +187,6 @@ std::optional<TDeviceLocation> FindDeviceLocation(
return result;
}

} // namespace

////////////////////////////////////////////////////////////////////////////////

const NProto::TDeviceConfig* FindDeviceConfig(
const NProto::TVolumeMeta& meta,
TStringBuf deviceUUID)
{
auto deviceLocation = FindDeviceLocation(meta, deviceUUID);
if (!deviceLocation) {
return nullptr;
}
return &GetDeviceConfig(meta, *deviceLocation);
}

std::optional<ui32> FindReplicaIndexByAgentNodeId(
const NProto::TVolumeMeta& meta,
ui32 agentNodeId)
{
const auto deviceMatcher =
[agentNodeId](const NProto::TDeviceConfig& device)
{
return device.GetNodeId() == agentNodeId;
};

return FindReplicaIndex(meta, deviceMatcher);
}

std::optional<ui32> FindReplicaIndexByAgentId(
const NProto::TVolumeMeta& meta,
TStringBuf agentId)
{
const auto deviceMatcher = [agentId](const NProto::TDeviceConfig& device)
{
return device.GetAgentId() == agentId;
};

return FindReplicaIndex(meta, deviceMatcher);
}

TVector<NProto::TLaggingDevice> CollectLaggingDevices(
const NProto::TVolumeMeta& meta,
ui32 replicaIndex,
ui32 agentNodeId)
{
const auto deviceMatcher =
[agentNodeId](const NProto::TDeviceConfig& device)
{
return device.GetNodeId() == agentNodeId;
};

return CollectLaggingDevices(meta, replicaIndex, deviceMatcher);
}

TVector<NProto::TLaggingDevice> CollectLaggingDevices(
const NProto::TVolumeMeta& meta,
ui32 replicaIndex,
TStringBuf agentId)
{
const auto deviceMatcher = [agentId](const NProto::TDeviceConfig& device)
{
return device.GetAgentId() == agentId;
};

return CollectLaggingDevices(meta, replicaIndex, deviceMatcher);
}

bool HaveCommonRows(
const TVector<NProto::TLaggingDevice>& laggingCandidates,
const RepeatedPtrField<NProto::TLaggingDevice>& alreadyLagging)
Expand Down
7 changes: 0 additions & 7 deletions cloud/blockstore/libs/storage/volume/model/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,10 @@ namespace NCloud::NBlockStore::NStorage {
const NProto::TVolumeMeta& meta,
TStringBuf deviceUUID);

[[nodiscard]] std::optional<ui32> FindReplicaIndexByAgentNodeId(
const NProto::TVolumeMeta& meta,
ui32 agentNodeId);
[[nodiscard]] std::optional<ui32> FindReplicaIndexByAgentId(
const NProto::TVolumeMeta& meta,
TStringBuf agentId);

[[nodiscard]] TVector<NProto::TLaggingDevice> CollectLaggingDevices(
const NProto::TVolumeMeta& meta,
ui32 replicaIndex,
ui32 agentNodeId);
[[nodiscard]] TVector<NProto::TLaggingDevice> CollectLaggingDevices(
const NProto::TVolumeMeta& meta,
ui32 replicaIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ void TVolumeActor::HandleDeviceTimeouted(
}

const auto timeoutedDeviceReplicaIndex =
FindReplicaIndexByAgentNodeId(meta, timeoutedDeviceConfig->GetNodeId());
FindReplicaIndexByAgentId(meta, timeoutedDeviceConfig->GetAgentId());
Y_DEBUG_ABORT_UNLESS(timeoutedDeviceReplicaIndex);

TVector<NProto::TLaggingDevice> timeoutedAgentDevices =
CollectLaggingDevices(
meta,
*timeoutedDeviceReplicaIndex,
timeoutedDeviceConfig->GetNodeId());
timeoutedDeviceConfig->GetAgentId());
Y_DEBUG_ABORT_UNLESS(!timeoutedAgentDevices.empty());

for (const auto& laggingAgent: meta.GetLaggingAgentsInfo().GetAgents()) {
Expand Down Expand Up @@ -223,7 +223,6 @@ void TVolumeActor::HandleDeviceTimeouted(

NProto::TLaggingAgent unavailableAgent;
unavailableAgent.SetAgentId(timeoutedDeviceConfig->GetAgentId());
unavailableAgent.SetNodeId(timeoutedDeviceConfig->GetNodeId());
unavailableAgent.SetReplicaIndex(*timeoutedDeviceReplicaIndex);
unavailableAgent.MutableDevices()->Assign(
std::make_move_iterator(timeoutedAgentDevices.begin()),
Expand Down

0 comments on commit 44ea4ba

Please sign in to comment.