Skip to content

Commit

Permalink
Disk registry benchmarks (#2852)
Browse files Browse the repository at this point in the history
* DiskRegistry benchmarks

* DiskRegistry state generator tool

* Prepare backup in recipe

* Make generation like real cluster
  • Loading branch information
drbasic authored Jan 15, 2025
1 parent f0dc0bb commit e165141
Show file tree
Hide file tree
Showing 15 changed files with 773 additions and 115 deletions.
1 change: 1 addition & 0 deletions cloud/blockstore/libs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ storage/disk_agent/ut/cloud-blockstore-libs-storage-disk_agent-ut
storage/disk_registry_proxy/ut/blockstore-libs-storage-disk_registry_proxy-ut
storage/disk_registry/actors/ut/libs-storage-disk_registry-actors-ut
storage/disk_registry/model/ut/blockstore-libs-storage-disk_registry-model-ut
storage/disk_registry/benchmark/benchmark
storage/disk_registry/ut_allocation/libs-storage-disk_registry-ut_allocation
storage/disk_registry/ut_checkpoint/libs-storage-disk_registry-ut_checkpoint
storage/disk_registry/ut_cms/blockstore-libs-storage-disk_registry-ut_cms
Expand Down
19 changes: 19 additions & 0 deletions cloud/blockstore/libs/storage/disk_registry/benchmark/ya.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
G_BENCHMARK()

INCLUDE(${ARCADIA_ROOT}/cloud/blockstore/tests/recipes/disk-registry-state/recipe.inc)

IF (SANITIZER_TYPE)
INCLUDE(${ARCADIA_ROOT}/cloud/storage/core/tests/recipes/large.inc)
ELSE()
INCLUDE(${ARCADIA_ROOT}/cloud/storage/core/tests/recipes/medium.inc)
ENDIF()

SRCS(
../disk_registry_state_benchmark.cpp
)

PEERDIR(
cloud/blockstore/libs/storage/disk_registry/testlib
)

END()
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ class TDiskRegistryActor final
} \
// BLOCKSTORE_DISK_REGISTRY_COUNTER

TDiskRegistryStateSnapshot MakeNewLoadState(
NProto::TDiskRegistryStateBackup&& backup);
bool ToLogicalBlocks(NProto::TDeviceConfig& device, ui32 logicalBlockSize);
TString LogDevices(const TVector<NProto::TDeviceConfig>& devices);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,120 +15,6 @@ namespace {

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

TDiskRegistryStateSnapshot MakeNewLoadState(
NProto::TDiskRegistryStateBackup&& backup)
{
auto move = [] (auto& src, auto& dst) {
dst.reserve(src.size());
dst.assign(
std::make_move_iterator(src.begin()),
std::make_move_iterator(src.end()));
src.Clear();
};

auto transform = [] (auto& src, auto& dst, auto func) {
dst.resize(src.size());
for (int i = 0; i < src.size(); ++i) {
func(src[i], dst[i]);
}
src.Clear();
};

TDiskRegistryStateSnapshot newLoadState;
// if new fields are added to TDiskRegistryStateSnapshot
// there will be a compilation error.
auto& [
config,
dirtyDevices,
agents,
disks,
placementGroups,
brokenDisks,
disksToReallocate,
diskStateChanges,
lastDiskStateSeqNo,
writableState,
disksToCleanup,
errorNotifications,
userNotifications,
outdatedVolumeConfigs,
suspendedDevices,
automaticallyReplacedDevices,
diskRegistryAgentListParams
] = newLoadState;

if (backup.DirtyDevicesSize()) {
transform(
*backup.MutableDirtyDevices(),
dirtyDevices,
[] (auto& src, auto& dst) {
dst.Id = src.GetId();
dst.DiskId = src.GetDiskId();
});
} else {
transform(
*backup.MutableOldDirtyDevices(),
dirtyDevices,
[] (auto& src, auto& dst) {
dst.Id = src;
});
}

move(*backup.MutableAgents(), agents);
move(*backup.MutableDisks(), disks);
move(*backup.MutablePlacementGroups(), placementGroups);
move(*backup.MutableDisksToNotify(), disksToReallocate);
move(*backup.MutableDisksToCleanup(), disksToCleanup);

move(*backup.MutableErrorNotifications(), errorNotifications);
move(*backup.MutableUserNotifications(), userNotifications);
// Filter out unknown events for future version rollback compatibility
std::erase_if(userNotifications, [] (const auto& notif) {
return notif.GetEventCase()
== NProto::TUserNotification::EventCase::EVENT_NOT_SET;
});

move(*backup.MutableOutdatedVolumeConfigs(), outdatedVolumeConfigs);
move(*backup.MutableSuspendedDevices(), suspendedDevices);

transform(
*backup.MutableBrokenDisks(),
brokenDisks,
[] (auto& src, auto& dst) {
dst.DiskId = src.GetDiskId();
dst.TsToDestroy = TInstant::MicroSeconds(src.GetTsToDestroy());
});
transform(
*backup.MutableDiskStateChanges(),
diskStateChanges,
[] (auto& src, auto& dst) {
if (src.HasState()) {
dst.State.Swap(src.MutableState());
}
dst.SeqNo = src.GetSeqNo();
});
transform(
*backup.MutableAutomaticallyReplacedDevices(),
automaticallyReplacedDevices,
[] (auto& src, auto& dst) {
dst.DeviceId = src.GetDeviceId();
dst.ReplacementTs = TInstant::MicroSeconds(src.GetReplacementTs());
});

diskRegistryAgentListParams.insert(
backup.MutableDiskRegistryAgentListParams()->begin(),
backup.MutableDiskRegistryAgentListParams()->end());

if (backup.HasConfig()) {
config.Swap(backup.MutableConfig());
}

lastDiskStateSeqNo = config.GetLastDiskStateSeqNo();
writableState = config.GetWritableState();

return newLoadState;
}

using TOperations = TQueue<std::function<void(TDiskRegistryDatabase&)>>;

void RestoreConfig(
Expand Down Expand Up @@ -440,6 +326,122 @@ void RestoreDiskRegistryAgentListParams(

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

TDiskRegistryStateSnapshot MakeNewLoadState(
NProto::TDiskRegistryStateBackup&& backup)
{
auto move = [] (auto& src, auto& dst) {
dst.reserve(src.size());
dst.assign(
std::make_move_iterator(src.begin()),
std::make_move_iterator(src.end()));
src.Clear();
};

auto transform = [] (auto& src, auto& dst, auto func) {
dst.resize(src.size());
for (int i = 0; i < src.size(); ++i) {
func(src[i], dst[i]);
}
src.Clear();
};

TDiskRegistryStateSnapshot newLoadState;
// if new fields are added to TDiskRegistryStateSnapshot
// there will be a compilation error.
auto& [
config,
dirtyDevices,
agents,
disks,
placementGroups,
brokenDisks,
disksToReallocate,
diskStateChanges,
lastDiskStateSeqNo,
writableState,
disksToCleanup,
errorNotifications,
userNotifications,
outdatedVolumeConfigs,
suspendedDevices,
automaticallyReplacedDevices,
diskRegistryAgentListParams
] = newLoadState;

if (backup.DirtyDevicesSize()) {
transform(
*backup.MutableDirtyDevices(),
dirtyDevices,
[] (auto& src, auto& dst) {
dst.Id = src.GetId();
dst.DiskId = src.GetDiskId();
});
} else {
transform(
*backup.MutableOldDirtyDevices(),
dirtyDevices,
[] (auto& src, auto& dst) {
dst.Id = src;
});
}

move(*backup.MutableAgents(), agents);
move(*backup.MutableDisks(), disks);
move(*backup.MutablePlacementGroups(), placementGroups);
move(*backup.MutableDisksToNotify(), disksToReallocate);
move(*backup.MutableDisksToCleanup(), disksToCleanup);

move(*backup.MutableErrorNotifications(), errorNotifications);
move(*backup.MutableUserNotifications(), userNotifications);
// Filter out unknown events for future version rollback compatibility
std::erase_if(userNotifications, [] (const auto& notif) {
return notif.GetEventCase()
== NProto::TUserNotification::EventCase::EVENT_NOT_SET;
});

move(*backup.MutableOutdatedVolumeConfigs(), outdatedVolumeConfigs);
move(*backup.MutableSuspendedDevices(), suspendedDevices);

transform(
*backup.MutableBrokenDisks(),
brokenDisks,
[] (auto& src, auto& dst) {
dst.DiskId = src.GetDiskId();
dst.TsToDestroy = TInstant::MicroSeconds(src.GetTsToDestroy());
});
transform(
*backup.MutableDiskStateChanges(),
diskStateChanges,
[] (auto& src, auto& dst) {
if (src.HasState()) {
dst.State.Swap(src.MutableState());
}
dst.SeqNo = src.GetSeqNo();
});
transform(
*backup.MutableAutomaticallyReplacedDevices(),
automaticallyReplacedDevices,
[] (auto& src, auto& dst) {
dst.DeviceId = src.GetDeviceId();
dst.ReplacementTs = TInstant::MicroSeconds(src.GetReplacementTs());
});

diskRegistryAgentListParams.insert(
backup.MutableDiskRegistryAgentListParams()->begin(),
backup.MutableDiskRegistryAgentListParams()->end());

if (backup.HasConfig()) {
config.Swap(backup.MutableConfig());
}

lastDiskStateSeqNo = config.GetLastDiskStateSeqNo();
writableState = config.GetWritableState();

return newLoadState;
}

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

void TDiskRegistryActor::HandleRestoreDiskRegistryState(
const TEvDiskRegistry::TEvRestoreDiskRegistryStateRequest::TPtr& ev,
const TActorContext& ctx)
Expand Down
Loading

0 comments on commit e165141

Please sign in to comment.