Skip to content

Commit

Permalink
minor tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpeye committed Sep 27, 2024
1 parent ebf0130 commit 71f8871
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions cloud/blockstore/libs/storage/disk_agent/storage_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class TInitializer
void SaveCurrentConfig();

void ReportDiskAgentConfigMismatchEvent(const TString& error);

void LockDevice(const TString& path);
};

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -419,6 +421,13 @@ void TInitializer::ValidateCurrentConfigs()
<< "broken config: " << FormatError(error));
}

void TInitializer::LockDevice(const TString& path)
{
if (AgentConfig->GetDeviceLockingEnabled() && !Guard.Lock(path)) {
ythrow TServiceError(E_ARGUMENT) << "unable to lock file " << path;
}
}

TFuture<void> TInitializer::Initialize()
{
ScanFileDevices();
Expand Down Expand Up @@ -457,20 +466,14 @@ TFuture<void> TInitializer::Initialize()
try {
SetBlocksCount(device, Configs[i]);

if (AgentConfig->GetDeviceLockingEnabled() &&
!Guard.Lock(Configs[i].GetDeviceName()))
{
ythrow TServiceError(E_ARGUMENT)
<< "unable to lock file "
<< Configs[i].GetDeviceName();
}
LockDevice(Configs[i].GetDeviceName());

auto result = CreateFileStorage(
device.GetPath(),
device.GetOffset() / device.GetBlockSize(),
Configs[i],
Stats[i]
).Subscribe([=] (const auto& future) {
).Subscribe([=, this] (const auto& future) {
try {
Devices[i] = future.GetValue();
} catch (...) {
Expand Down Expand Up @@ -498,7 +501,7 @@ TFuture<void> TInitializer::Initialize()

try {
auto result = CreateMemoryStorage(Configs[i], Stats[i])
.Subscribe([=] (const auto& future) {
.Subscribe([=, this] (const auto& future) {
try {
Devices[i] = future.GetValue();
} catch (...) {
Expand Down

0 comments on commit 71f8871

Please sign in to comment.