-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lagging agent concept to the volume
- Loading branch information
1 parent
afefb4a
commit 21ff8af
Showing
16 changed files
with
779 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include "helpers.h" | ||
|
||
#include <cloud/storage/core/libs/common/media.h> | ||
|
||
#include <util/generic/algorithm.h> | ||
#include <util/generic/vector.h> | ||
|
||
namespace NCloud::NBlockStore::NStorage { | ||
|
||
bool TLaggingDeviceIndexCmp::operator()( | ||
const NProto::TLaggingDevice& lhs, | ||
const NProto::TLaggingDevice& rhs) const | ||
{ | ||
return lhs.GetDeviceIndex() < rhs.GetDeviceIndex(); | ||
} | ||
|
||
TVector<TString> ClearLaggingDevices(NProto::TVolumeMeta& meta) | ||
{ | ||
TVector<TString> result; | ||
if (!IsReliableDiskRegistryMediaKind( | ||
meta.GetConfig().GetStorageMediaKind()) || | ||
meta.GetLaggingAgentsInfo().GetAgents().empty()) | ||
{ | ||
return result; | ||
} | ||
|
||
auto getReplicaDevices = [&meta](i32 replicaIndex) | ||
{ | ||
if (replicaIndex == 0) { | ||
return meta.GetDevices(); | ||
} | ||
Y_DEBUG_ABORT_UNLESS(meta.GetReplicas().size() > replicaIndex - 1); | ||
return meta.GetReplicas()[replicaIndex - 1].GetDevices(); | ||
}; | ||
|
||
for (const auto& agent: meta.GetLaggingAgentsInfo().GetAgents()) { | ||
const auto& devices = getReplicaDevices(agent.GetReplicaIndex()); | ||
|
||
for (const auto& laggingDevice: agent.GetDevices()) { | ||
const i32 index = laggingDevice.GetDeviceIndex(); | ||
Y_DEBUG_ABORT_UNLESS(devices.size() > index); | ||
result.push_back(devices[index].GetDeviceUUID()); | ||
} | ||
} | ||
|
||
meta.MutableLaggingAgentsInfo()->MutableAgents()->Clear(); | ||
meta.MutableLaggingAgentsInfo()->SetNeedToSyncFreshDevicesWithDR(true); | ||
return result; | ||
} | ||
|
||
std::optional<ui32> GetAgentDevicesIndexes( | ||
const NProto::TVolumeMeta& meta, | ||
const TString& agentId, | ||
TVector<NProto::TLaggingDevice>& laggingDevices) | ||
{ | ||
std::optional<ui32> replicaIndex; | ||
const google::protobuf::RepeatedPtrField<NProto::TDeviceConfig>* | ||
replicaDevices = nullptr; | ||
const auto agentIdPred = [&agentId](const NProto::TDeviceConfig& device) | ||
{ | ||
return device.GetAgentId() == agentId; | ||
}; | ||
if (AnyOf(meta.GetDevices().begin(), meta.GetDevices().end(), agentIdPred)) | ||
{ | ||
replicaIndex = 0; | ||
replicaDevices = &meta.GetDevices(); | ||
} | ||
|
||
for (int i = 0; !replicaIndex && i < meta.GetReplicas().size(); i++) { | ||
if (AnyOf( | ||
meta.GetReplicas()[i].GetDevices().begin(), | ||
meta.GetReplicas()[i].GetDevices().end(), | ||
agentIdPred)) | ||
{ | ||
replicaIndex = i + 1; | ||
replicaDevices = &meta.GetReplicas()[i].GetDevices(); | ||
break; | ||
} | ||
} | ||
|
||
// There is no devices from desired agent. | ||
if (!replicaIndex) { | ||
return replicaIndex; | ||
} | ||
|
||
for (int i = 0; i < replicaDevices->size(); i++) { | ||
const auto& device = (*replicaDevices)[i]; | ||
if (device.GetAgentId() == agentId) { | ||
NProto::TLaggingDevice laggingDevice; | ||
laggingDevice.SetDeviceIndex(i); | ||
laggingDevice.SetDeviceUUID(device.GetDeviceUUID()); | ||
laggingDevices.push_back(std::move(laggingDevice)); | ||
} | ||
} | ||
|
||
return replicaIndex; | ||
} | ||
|
||
} // namespace NCloud::NBlockStore::NStorage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "cloud/blockstore/libs/storage/protos_ydb/volume.pb.h" | ||
|
||
#include <cloud/blockstore/libs/storage/protos/disk.pb.h> | ||
|
||
namespace NCloud::NBlockStore::NStorage { | ||
|
||
struct TLaggingDeviceIndexCmp | ||
{ | ||
bool operator()( | ||
const NProto::TLaggingDevice& lhs, | ||
const NProto::TLaggingDevice& rhs) const; | ||
}; | ||
|
||
[[nodiscard]] TVector<TString> ClearLaggingDevices( | ||
NProto::TVolumeMeta& meta); | ||
|
||
[[nodiscard]] std::optional<ui32> GetAgentDevicesIndexes( | ||
const NProto::TVolumeMeta& meta, | ||
const TString& agentId, | ||
TVector<NProto::TLaggingDevice>& laggingDevices); | ||
|
||
} // namespace NCloud::NBlockStore::NStorage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.