diff --git a/cloud/blockstore/libs/storage/core/acquire_devices_actor.cpp b/cloud/blockstore/libs/storage/core/acquire_devices_actor.cpp index 8d11435fb2..f267dcbb3c 100644 --- a/cloud/blockstore/libs/storage/core/acquire_devices_actor.cpp +++ b/cloud/blockstore/libs/storage/core/acquire_devices_actor.cpp @@ -1,4 +1,4 @@ -#include "acquire_release_devices.h" +#include "acquire_release_devices_actors.h" #include #include @@ -11,6 +11,9 @@ #include namespace NCloud::NBlockStore::NStorage::NAcquireReleaseDevices { + +//////////////////////////////////////////////////////////////////////////////// + using namespace NActors; namespace { @@ -39,14 +42,7 @@ class TAcquireDevicesActor final public: TAcquireDevicesActor( const TActorId& owner, - TVector devices, - TString diskId, - TString clientId, - NProto::EVolumeAccessMode accessMode, - ui64 mountSeqNumber, - ui32 volumeGeneration, - TDuration requestTimeout, - bool muteIOErrors, + TAcquireReleaseDevicesInfo acquireDevicesInfo, NLog::EComponent component); void Bootstrap(const TActorContext& ctx); @@ -104,24 +100,17 @@ class TAcquireDevicesActor final TAcquireDevicesActor::TAcquireDevicesActor( const TActorId& owner, - TVector devices, - TString diskId, - TString clientId, - NProto::EVolumeAccessMode accessMode, - ui64 mountSeqNumber, - ui32 volumeGeneration, - TDuration requestTimeout, - bool muteIOErrors, + TAcquireReleaseDevicesInfo acquireDevicesInfo, NLog::EComponent component) : Owner(owner) - , Devices(std::move(devices)) - , DiskId(std::move(diskId)) - , ClientId(std::move(clientId)) - , AccessMode(accessMode) - , MountSeqNumber(mountSeqNumber) - , VolumeGeneration(volumeGeneration) - , RequestTimeout(requestTimeout) - , MuteIOErrors(muteIOErrors) + , Devices(std::move(acquireDevicesInfo.Devices)) + , DiskId(std::move(acquireDevicesInfo.DiskId)) + , ClientId(std::move(acquireDevicesInfo.ClientId)) + , AccessMode(acquireDevicesInfo.AccessMode.value()) + , MountSeqNumber(acquireDevicesInfo.MountSeqNumber.value()) + , VolumeGeneration(acquireDevicesInfo.VolumeGeneration) + , RequestTimeout(acquireDevicesInfo.RequestTimeout) + , MuteIOErrors(acquireDevicesInfo.MuteIOErrors) , Component(component) { SortBy(Devices, [](auto& d) { return d.GetNodeId(); }); @@ -375,27 +364,13 @@ STFUNC(TAcquireDevicesActor::StateAcquire) TActorId CreateAcquireDevicesActor( const NActors::TActorContext& ctx, const TActorId& owner, - TVector devices, - TString diskId, - TString clientId, - NProto::EVolumeAccessMode accessMode, - ui64 mountSeqNumber, - ui32 volumeGeneration, - TDuration requestTimeout, - bool muteIOErrors, - NLog::EComponent component) + TAcquireReleaseDevicesInfo acquireDevicesInfo, + NActors::NLog::EComponent component) { return NCloud::Register( ctx, owner, - std::move(devices), - diskId, - std::move(clientId), - accessMode, - mountSeqNumber, - volumeGeneration, - requestTimeout, - muteIOErrors, + std::move(acquireDevicesInfo), component); } diff --git a/cloud/blockstore/libs/storage/core/acquire_release_devices.h b/cloud/blockstore/libs/storage/core/acquire_release_devices_actors.h similarity index 82% rename from cloud/blockstore/libs/storage/core/acquire_release_devices.h rename to cloud/blockstore/libs/storage/core/acquire_release_devices_actors.h index ab4493dea2..582c87b78a 100644 --- a/cloud/blockstore/libs/storage/core/acquire_release_devices.h +++ b/cloud/blockstore/libs/storage/core/acquire_release_devices_actors.h @@ -78,28 +78,29 @@ using TEvDevicesAcquireFinished = using TEvDevicesReleaseFinished = TRequestEvent; +struct TAcquireReleaseDevicesInfo +{ + TVector Devices; + TString DiskId; + TString ClientId; + std::optional + AccessMode; // Only AcquireDevicesActor need it. + std::optional MountSeqNumber; // Only AcquireDevicesActor need it. + ui32 VolumeGeneration; + TDuration RequestTimeout; + bool MuteIOErrors; +}; + TActorId CreateAcquireDevicesActor( const NActors::TActorContext& ctx, const TActorId& owner, - TVector devices, - TString diskId, - TString clientId, - NProto::EVolumeAccessMode accessMode, - ui64 mountSeqNumber, - ui32 volumeGeneration, - TDuration requestTimeout, - bool muteIOErrors, + TAcquireReleaseDevicesInfo acquireDevicesInfo, NActors::NLog::EComponent component); TActorId CreateReleaseDevicesActor( const NActors::TActorContext& ctx, const TActorId& owner, - TString diskId, - TString clientId, - ui32 volumeGeneration, - TDuration requestTimeout, - TVector devices, - bool muteIOErrors, + TAcquireReleaseDevicesInfo releaseDevicesInfo, NActors::NLog::EComponent component); } // namespace NCloud::NBlockStore::NStorage::NAcquireReleaseDevices diff --git a/cloud/blockstore/libs/storage/core/release_devices_actor.cpp b/cloud/blockstore/libs/storage/core/release_devices_actor.cpp index fbd8445c67..de97e1f539 100644 --- a/cloud/blockstore/libs/storage/core/release_devices_actor.cpp +++ b/cloud/blockstore/libs/storage/core/release_devices_actor.cpp @@ -1,4 +1,4 @@ -#include "acquire_release_devices.h" +#include "acquire_release_devices_actors.h" #include #include @@ -10,6 +10,9 @@ #include namespace NCloud::NBlockStore::NStorage::NAcquireReleaseDevices { + +//////////////////////////////////////////////////////////////////////////////// + using namespace NActors; namespace { @@ -21,11 +24,11 @@ class TReleaseDevicesActor final { private: const TActorId Owner; + TVector Devices; const TString DiskId; const TString ClientId; const ui32 VolumeGeneration; const TDuration RequestTimeout; - TVector Devices; bool MuteIOErrors; NLog::EComponent Component; @@ -36,12 +39,7 @@ class TReleaseDevicesActor final public: TReleaseDevicesActor( const TActorId& owner, - TString diskId, - TString clientId, - ui32 volumeGeneration, - TDuration requestTimeout, - TVector devices, - bool muteIoErrors, + TAcquireReleaseDevicesInfo releaseDevicesInfo, NLog::EComponent component); void Bootstrap(const TActorContext& ctx); @@ -81,20 +79,15 @@ class TReleaseDevicesActor final TReleaseDevicesActor::TReleaseDevicesActor( const TActorId& owner, - TString diskId, - TString clientId, - ui32 volumeGeneration, - TDuration requestTimeout, - TVector devices, - bool muteIOErrors, + TAcquireReleaseDevicesInfo releaseDevicesInfo, NLog::EComponent component) : Owner(owner) - , DiskId(std::move(diskId)) - , ClientId(std::move(clientId)) - , VolumeGeneration(volumeGeneration) - , RequestTimeout(requestTimeout) - , Devices(std::move(devices)) - , MuteIOErrors(muteIOErrors) + , Devices(std::move(releaseDevicesInfo.Devices)) + , DiskId(std::move(releaseDevicesInfo.DiskId)) + , ClientId(std::move(releaseDevicesInfo.ClientId)) + , VolumeGeneration(releaseDevicesInfo.VolumeGeneration) + , RequestTimeout(releaseDevicesInfo.RequestTimeout) + , MuteIOErrors(releaseDevicesInfo.MuteIOErrors) , Component(component) {} @@ -249,25 +242,15 @@ TString TReleaseDevicesActor::LogTargets() const } // namespace TActorId CreateReleaseDevicesActor( - const TActorContext& ctx, + const NActors::TActorContext& ctx, const TActorId& owner, - TString diskId, - TString clientId, - ui32 volumeGeneration, - TDuration requestTimeout, - TVector devices, - bool muteIOErrors, + TAcquireReleaseDevicesInfo releaseDevicesInfo, NActors::NLog::EComponent component) { return NCloud::Register( ctx, owner, - std::move(diskId), - std::move(clientId), - volumeGeneration, - requestTimeout, - std::move(devices), - muteIOErrors, + releaseDevicesInfo, component); } } // namespace NCloud::NBlockStore::NStorage::NAcquireReleaseDevices diff --git a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor.cpp b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor.cpp index c18eb9f275..e80bdafa9a 100644 --- a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor.cpp +++ b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor.cpp @@ -188,24 +188,6 @@ void TDiskRegistryActor::BeforeDie(const NActors::TActorContext& ctx) MakeTabletIsDeadError(E_REJECTED, __LOCATION__)); } PendingDiskDeallocationRequests.clear(); - - for (auto& [_, requestInfo]: PendingAcquireDiskRequests) { - NCloud::Reply( - ctx, - *requestInfo, - std::make_unique( - MakeTabletIsDeadError(E_REJECTED, __LOCATION__))); - } - PendingAcquireDiskRequests.clear(); - - for (auto& [_, requestInfo]: PendingReleaseDiskRequests) { - NCloud::Reply( - ctx, - *requestInfo, - std::make_unique( - MakeTabletIsDeadError(E_REJECTED, __LOCATION__))); - } - PendingReleaseDiskRequests.clear(); } void TDiskRegistryActor::OnDetach(const TActorContext& ctx) @@ -726,14 +708,6 @@ STFUNC(TDiskRegistryActor::StateWork) TEvDiskRegistryPrivate::TEvDiskRegistryAgentListExpiredParamsCleanup, TDiskRegistryActor::HandleDiskRegistryAgentListExpiredParamsCleanup); - HFunc( - NAcquireReleaseDevices::TEvDevicesAcquireFinished, - HandleDevicesAcquireFinished); - - HFunc( - NAcquireReleaseDevices::TEvDevicesReleaseFinished, - HandleDevicesReleaseFinished); - default: if (!HandleRequests(ev) && !HandleDefaultEvents(ev, SelfId())) { HandleUnexpectedEvent(ev, TBlockStoreComponents::DISK_REGISTRY); diff --git a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor.h b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor.h index b3739a29a0..56a67c0493 100644 --- a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor.h +++ b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -86,9 +86,6 @@ class TDiskRegistryActor final THashMap> PendingDiskDeallocationRequests; - THashMap PendingAcquireDiskRequests; - THashMap PendingReleaseDiskRequests; - bool BrokenDisksDestructionInProgress = false; bool DisksNotificationInProgress = false; bool UsersNotificationInProgress = false; @@ -246,16 +243,9 @@ class TDiskRegistryActor final NProto::TError error); void ProcessAutomaticallyReplacedDevices(const NActors::TActorContext& ctx); - - void HandleDevicesAcquireFinished( - const NAcquireReleaseDevices::TEvDevicesAcquireFinished::TPtr& ev, - const NActors::TActorContext& ctx); void OnDiskAcquired( TVector sentAcquireRequests); - void HandleDevicesReleaseFinished( - const NAcquireReleaseDevices::TEvDevicesReleaseFinished::TPtr& ev, - const NActors::TActorContext& ctx); void OnDiskReleased( const TVector< NAcquireReleaseDevices::TAgentReleaseDevicesCachedRequest>& diff --git a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_acquire_release.cpp b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_acquire_release.cpp index 6a7cb7467d..4a2e158e3c 100644 --- a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_acquire_release.cpp +++ b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_acquire_release.cpp @@ -7,6 +7,8 @@ #include #include +#include + namespace NCloud::NBlockStore::NStorage { using namespace NActors; @@ -15,6 +17,8 @@ using namespace NKikimr::NTabletFlatExecutor; namespace { +//////////////////////////////////////////////////////////////////////////////// + TVector ExtractDevicesFromDiskInfo(TDiskInfo& diskInfo) { TVector devices = std::move(diskInfo.Devices); @@ -35,6 +39,269 @@ TVector ExtractDevicesFromDiskInfo(TDiskInfo& diskInfo) return devices; } +//////////////////////////////////////////////////////////////////////////////// + +class TAcquireReleaseDiskProxyActor final + : public TActorBootstrapped +{ +public: + enum EOperationType { + ACQUIRE_DISK, + RELEASE_DISK, + }; + +private: + const TActorId Owner; + + NAcquireReleaseDevices::TAcquireReleaseDevicesInfo AcquireReleaseInfo; + + const ui32 LogicalBlockSize; + + TRequestInfoPtr RequestInfo; + + EOperationType OperationType; + + std::optional WorkerId; + + std::optional> + OperationFinishedResponce; + + +public: + TAcquireReleaseDiskProxyActor( + const TActorId& owner, + NAcquireReleaseDevices::TAcquireReleaseDevicesInfo acquireReleaseInfo, + ui32 logicalBlockSize, + TRequestInfoPtr requestInfo, + EOperationType operationType); + + void Bootstrap(const TActorContext& ctx); + +private: + template + void SendOperationFinishedToOwner( + const TActorContext& ctx, + const TEventType& ev) + { + auto* msg = ev->Get(); + + WorkerId = std::nullopt; + + OperationFinishedResponce = *msg; + auto request = std::make_unique( + msg->DiskId, + msg->ClientId, + msg->SentRequests); + NCloud::Send(ctx, Owner, std::move(request)); + } + + void ReplyAndDie(const TActorContext& ctx, NProto::TError error); + + void ReplyAndDieAcquire(const TActorContext& ctx, NProto::TError error); + + void ReplyAndDieRelease(const TActorContext& ctx, NProto::TError error); + +private: + STFUNC(StateWork); + + void HandlePoisonPill( + const TEvents::TEvPoisonPill::TPtr& ev, + const TActorContext& ctx); + + void HandleDevicesAcquireFinished( + const NAcquireReleaseDevices::TEvDevicesAcquireFinished::TPtr& ev, + const NActors::TActorContext& ctx); + + void HandleFinishAcquireDiskResponse( + const TEvDiskRegistryPrivate::TEvFinishAcquireDiskResponse::TPtr& ev, + const TActorContext& ctx); + + void HandleDevicesReleaseFinished( + const NAcquireReleaseDevices::TEvDevicesReleaseFinished::TPtr& ev, + const NActors::TActorContext& ctx); + + void HandleRemoveDiskSessionResponse( + const TEvDiskRegistryPrivate::TEvRemoveDiskSessionResponse::TPtr& ev, + const TActorContext& ctx); +}; + +//////////////////////////////////////////////////////////////////////////////// + +TAcquireReleaseDiskProxyActor::TAcquireReleaseDiskProxyActor( + const TActorId& owner, + NAcquireReleaseDevices::TAcquireReleaseDevicesInfo acquireReleaseInfo, + ui32 logicalBlockSize, + TRequestInfoPtr requestInfo, + EOperationType operationType) + : Owner(owner) + , AcquireReleaseInfo(std::move(acquireReleaseInfo)) + , LogicalBlockSize(logicalBlockSize) + , RequestInfo(std::move(requestInfo)) + , OperationType(operationType) +{ +} + +void TAcquireReleaseDiskProxyActor::Bootstrap(const TActorContext& ctx) +{ + Become(&TThis::StateWork); + + WorkerId = [&]() + { + switch (OperationType) { + case ACQUIRE_DISK: + return NAcquireReleaseDevices::CreateAcquireDevicesActor( + ctx, + ctx.SelfID, + std::move(AcquireReleaseInfo), + TBlockStoreComponents::DISK_REGISTRY_WORKER); + case RELEASE_DISK: + return NAcquireReleaseDevices::CreateReleaseDevicesActor( + ctx, + ctx.SelfID, + std::move(AcquireReleaseInfo), + TBlockStoreComponents::DISK_REGISTRY_WORKER); + } + }(); +} + +void TAcquireReleaseDiskProxyActor::ReplyAndDie( + const TActorContext& ctx, + NProto::TError error) +{ + switch (OperationType) { + case ACQUIRE_DISK: + ReplyAndDieAcquire(ctx, std::move(error)); + return; + case RELEASE_DISK: + ReplyAndDieRelease(ctx, std::move(error)); + return; + } +} + +void TAcquireReleaseDiskProxyActor::ReplyAndDieAcquire( + const TActorContext& ctx, + NProto::TError error) +{ + auto* msg = + OperationFinishedResponce.has_value() + ? &std::get( + OperationFinishedResponce.value()) + : nullptr; + + auto response = std::make_unique( + !HasError(error) && msg ? std::move(msg->Error) : std::move(error)); + + if (!HasError(response->GetError()) && msg) { + response->Record.MutableDevices()->Reserve(msg->Devices.size()); + + for (auto& device: msg->Devices) { + ToLogicalBlocks(device, LogicalBlockSize); + *response->Record.AddDevices() = std::move(device); + } + } + + NCloud::Reply(ctx, *RequestInfo, std::move(response)); + NCloud::Send( + ctx, + Owner, + std::make_unique()); + Die(ctx); +} + +void TAcquireReleaseDiskProxyActor::ReplyAndDieRelease( + const TActorContext& ctx, + NProto::TError error) +{ + auto response = std::make_unique( + std::move(error)); + NCloud::Reply(ctx, *RequestInfo, std::move(response)); + + NCloud::Send( + ctx, + Owner, + std::make_unique()); + Die(ctx); +} + +STFUNC(TAcquireReleaseDiskProxyActor::StateWork) +{ + switch (ev->GetTypeRewrite()) { + HFunc(TEvents::TEvPoisonPill, HandlePoisonPill); + + HFunc( + NAcquireReleaseDevices::TEvDevicesAcquireFinished, + HandleDevicesAcquireFinished); + HFunc( + TEvDiskRegistryPrivate::TEvFinishAcquireDiskResponse, + HandleFinishAcquireDiskResponse); + + HFunc( + NAcquireReleaseDevices::TEvDevicesReleaseFinished, + HandleDevicesReleaseFinished); + HFunc( + TEvDiskRegistryPrivate::TEvRemoveDiskSessionResponse, + HandleRemoveDiskSessionResponse); + + default: + HandleUnexpectedEvent(ev, TBlockStoreComponents::DISK_REGISTRY_WORKER); + break; + } +} + +void TAcquireReleaseDiskProxyActor::HandlePoisonPill( + const TEvents::TEvPoisonPill::TPtr& ev, + const TActorContext& ctx) +{ + Y_UNUSED(ev); + + if (WorkerId) { + NCloud::Send( + ctx, + WorkerId.value(), + std::make_unique()); + } + + ReplyAndDie(ctx, MakeTabletIsDeadError(E_REJECTED, __LOCATION__)); +} + +void TAcquireReleaseDiskProxyActor::HandleDevicesAcquireFinished( + const NAcquireReleaseDevices::TEvDevicesAcquireFinished::TPtr& ev, + const TActorContext& ctx) +{ + Y_ABORT_UNLESS(OperationType == ACQUIRE_DISK); + SendOperationFinishedToOwner< + TEvDiskRegistryPrivate::TEvFinishAcquireDiskRequest>(ctx, ev); +} + +void TAcquireReleaseDiskProxyActor::HandleFinishAcquireDiskResponse( + const TEvDiskRegistryPrivate::TEvFinishAcquireDiskResponse::TPtr& ev, + const TActorContext& ctx) +{ + Y_ABORT_UNLESS(OperationType == ACQUIRE_DISK); + Y_UNUSED(ev); + + ReplyAndDie(ctx, {}); +} + +void TAcquireReleaseDiskProxyActor::HandleDevicesReleaseFinished( + const NAcquireReleaseDevices::TEvDevicesReleaseFinished::TPtr& ev, + const NActors::TActorContext& ctx) +{ + Y_ABORT_UNLESS(OperationType == RELEASE_DISK); + SendOperationFinishedToOwner< + TEvDiskRegistryPrivate::TEvRemoveDiskSessionRequest>(ctx, ev); +} + +void TAcquireReleaseDiskProxyActor::HandleRemoveDiskSessionResponse( + const TEvDiskRegistryPrivate::TEvRemoveDiskSessionResponse::TPtr& ev, + const TActorContext& ctx) +{ + Y_ABORT_UNLESS(OperationType == RELEASE_DISK); + ReplyAndDie(ctx, ev->Get()->GetError()); +} + } // namespace //////////////////////////////////////////////////////////////////////////////// @@ -72,9 +339,8 @@ void TDiskRegistryActor::HandleAcquireDisk( msg->Record.GetVolumeGeneration()); TDiskInfo diskInfo; - auto error = State->StartAcquireDisk(diskId, diskInfo); - - if (HasError(error)) { + if (auto error = State->StartAcquireDisk(diskId, diskInfo); HasError(error)) + { LOG_ERROR( ctx, TBlockStoreComponents::DISK_REGISTRY, @@ -94,70 +360,43 @@ void TDiskRegistryActor::HandleAcquireDisk( "AcquireeDisk %s. Nothing to acquire", diskId.c_str()); - replyWithError(std::move(error)); + replyWithError(MakeError(S_ALREADY, {})); return; } TVector devices = ExtractDevicesFromDiskInfo(diskInfo); - - auto actor = NAcquireReleaseDevices::CreateAcquireDevicesActor( + auto actor = NCloud::Register( ctx, ctx.SelfID, - std::move(devices), - std::move(diskId), - std::move(clientId), - msg->Record.GetAccessMode(), - msg->Record.GetMountSeqNumber(), - msg->Record.GetVolumeGeneration(), - Config->GetAgentRequestTimeout(), - /*muteIOErrors=*/false, - TBlockStoreComponents::DISK_REGISTRY_WORKER); + NAcquireReleaseDevices::TAcquireReleaseDevicesInfo{ + .Devices = std::move(devices), + .DiskId = std::move(diskId), + .ClientId = std::move(clientId), + .AccessMode = msg->Record.GetAccessMode(), + .MountSeqNumber = msg->Record.GetMountSeqNumber(), + .VolumeGeneration = msg->Record.GetVolumeGeneration(), + .RequestTimeout = Config->GetAgentRequestTimeout(), + .MuteIOErrors = false, + }, + diskInfo.LogicalBlockSize, + TBlockStoreComponents::DISK_REGISTRY_WORKER, + TAcquireReleaseDiskProxyActor::ACQUIRE_DISK); Actors.insert(actor); - PendingAcquireDiskRequests[actor] = - CreateRequestInfo(ev->Sender, ev->Cookie, msg->CallContext); } -void TDiskRegistryActor::HandleDevicesAcquireFinished( - const NAcquireReleaseDevices::TEvDevicesAcquireFinished::TPtr& ev, - const NActors::TActorContext& ctx) +void TDiskRegistryActor::HandleFinishAcquireDisk( + const TEvDiskRegistryPrivate::TEvFinishAcquireDiskRequest::TPtr& ev, + const TActorContext& ctx) { auto* msg = ev->Get(); - if (HasError(msg->Error)) { - LOG_ERROR( - ctx, - TBlockStoreComponents::DISK_REGISTRY, - "[%s] AcquireDisk %s targets %s error: %s", - msg->ClientId.c_str(), - msg->DiskId.c_str(), - LogDevices(msg->Devices).c_str(), - FormatError(msg->Error).c_str()); - } + State->FinishAcquireDisk(msg->DiskId); OnDiskAcquired(std::move(msg->SentRequests)); - auto* reqInfo = PendingAcquireDiskRequests.FindPtr(ev->Sender); - if (!reqInfo) { - return; - } - - auto response = std::make_unique( - std::move(msg->Error)); - const auto* disk = State->FinishAcquireDisk(msg->DiskId); - if (!HasError(response->GetError())) { - response->Record.MutableDevices()->Reserve(msg->Devices.size()); - - for (auto& device: msg->Devices) { - if (disk) { - ToLogicalBlocks(device, disk->LogicalBlockSize); - } - *response->Record.AddDevices() = std::move(device); - } - } - - NCloud::Reply(ctx, **reqInfo, std::move(response)); - Actors.erase(ev->Sender); - PendingAcquireDiskRequests.erase(ev->Sender); + auto response = std::make_unique< + TEvDiskRegistryPrivate::TEvFinishAcquireDiskResponse>(); + NCloud::Reply(ctx, *ev, std::move(response)); } //////////////////////////////////////////////////////////////////////////////// @@ -202,8 +441,10 @@ void TDiskRegistryActor::HandleReleaseDisk( } TDiskInfo diskInfo; - const auto error = State->GetDiskInfo(diskId, diskInfo); - if (HasError(error)) { + + if (const auto error = State->GetDiskInfo(diskId, diskInfo); + HasError(error)) + { LOG_ERROR( ctx, TBlockStoreComponents::DISK_REGISTRY, @@ -226,42 +467,41 @@ void TDiskRegistryActor::HandleReleaseDisk( return; } - TVector devices = - ExtractDevicesFromDiskInfo(diskInfo); - - auto actor = NAcquireReleaseDevices::CreateReleaseDevicesActor( + auto actor = NCloud::Register( ctx, ctx.SelfID, - std::move(diskId), - std::move(clientId), - volumeGeneration, - Config->GetAgentRequestTimeout(), - std::move(devices), - /*muteIOErrors=*/false, - TBlockStoreComponents::DISK_REGISTRY_WORKER); - + NAcquireReleaseDevices::TAcquireReleaseDevicesInfo{ + .Devices = ExtractDevicesFromDiskInfo(diskInfo), + .DiskId = std::move(diskId), + .ClientId = std::move(clientId), + .AccessMode = std::nullopt, + .MountSeqNumber = std::nullopt, + .VolumeGeneration = msg->Record.GetVolumeGeneration(), + .RequestTimeout = Config->GetAgentRequestTimeout(), + .MuteIOErrors = false, + }, + TBlockStoreComponents::DISK_REGISTRY_WORKER, + TAcquireReleaseDiskProxyActor::RELEASE_DISK); Actors.insert(actor); - PendingReleaseDiskRequests[actor] = - CreateRequestInfo(ev->Sender, ev->Cookie, msg->CallContext); } -void TDiskRegistryActor::HandleDevicesReleaseFinished( - const NAcquireReleaseDevices::TEvDevicesReleaseFinished::TPtr& ev, - const NActors::TActorContext& ctx) +void TDiskRegistryActor::HandleRemoveDiskSession( + const TEvDiskRegistryPrivate::TEvRemoveDiskSessionRequest::TPtr& ev, + const TActorContext& ctx) { const auto* msg = ev->Get(); OnDiskReleased(msg->SentRequests); - State->FinishAcquireDisk(msg->DiskId); - auto reqInfo = PendingReleaseDiskRequests.at(ev->Sender); + auto requestInfo = CreateRequestInfo( + ev->Sender, + ev->Cookie, + msg->CallContext); + State->FinishAcquireDisk(msg->DiskId); auto response = - std::make_unique(msg->Error); - NCloud::Reply(ctx, *reqInfo, std::move(response)); - - Actors.erase(ev->Sender); - PendingReleaseDiskRequests.erase(ev->Sender); + std::make_unique(); + NCloud::Reply(ctx, *ev, std::move(response)); } } // namespace NCloud::NBlockStore::NStorage diff --git a/cloud/blockstore/libs/storage/disk_registry/disk_registry_private.h b/cloud/blockstore/libs/storage/disk_registry/disk_registry_private.h index be27a49619..f91bee7b1a 100644 --- a/cloud/blockstore/libs/storage/disk_registry/disk_registry_private.h +++ b/cloud/blockstore/libs/storage/disk_registry/disk_registry_private.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include @@ -168,6 +168,8 @@ using TVolumeConfig = NKikimrBlockStore::TVolumeConfig; xxx(CleanupDisks, __VA_ARGS__) \ xxx(SecureErase, __VA_ARGS__) \ xxx(CleanupDevices, __VA_ARGS__) \ + xxx(FinishAcquireDisk, __VA_ARGS__) \ + xxx(RemoveDiskSession, __VA_ARGS__) \ xxx(DestroyBrokenDisks, __VA_ARGS__) \ xxx(ListBrokenDisks, __VA_ARGS__) \ xxx(NotifyDisks, __VA_ARGS__) \ @@ -191,6 +193,56 @@ using TVolumeConfig = NKikimrBlockStore::TVolumeConfig; struct TEvDiskRegistryPrivate { + // + // FinishAcquireDisk + // + + struct TFinishAcquireDiskRequest + { + TString DiskId; + TString ClientId; + TVector + SentRequests; + + TFinishAcquireDiskRequest( + TString diskId, + TString clientId, + TVector + sentRequests) + : DiskId(std::move(diskId)) + , ClientId(std::move(clientId)) + , SentRequests(std::move(sentRequests)) + {} + }; + + struct TFinishAcquireDiskResponse + {}; + + // + // RemoveDiskSession + // + + struct TRemoveDiskSessionRequest + { + TString DiskId; + TString ClientId; + TVector + SentRequests; + + TRemoveDiskSessionRequest( + TString diskId, + TString clientId, + TVector + sentRequests) + : DiskId(std::move(diskId)) + , ClientId(std::move(clientId)) + , SentRequests(std::move(sentRequests)) + {} + }; + + struct TRemoveDiskSessionResponse + {}; + // // CleanupDisks // diff --git a/cloud/blockstore/libs/storage/disk_registry/disk_registry_state.cpp b/cloud/blockstore/libs/storage/disk_registry/disk_registry_state.cpp index b18965c0dd..7c2fc1d3d7 100644 --- a/cloud/blockstore/libs/storage/disk_registry/disk_registry_state.cpp +++ b/cloud/blockstore/libs/storage/disk_registry/disk_registry_state.cpp @@ -3468,17 +3468,15 @@ NProto::TError TDiskRegistryState::StartAcquireDisk( return {}; } -const TDiskRegistryState::TDiskState* TDiskRegistryState::FinishAcquireDisk( - const TString& diskId) +void TDiskRegistryState::FinishAcquireDisk(const TString& diskId) { auto* diskPtr = Disks.FindPtr(diskId); if (!diskPtr) { - return nullptr; + return; } diskPtr->AcquireInProgress = false; - return diskPtr; } bool TDiskRegistryState::IsAcquireInProgress(const TString& diskId) const diff --git a/cloud/blockstore/libs/storage/disk_registry/disk_registry_state.h b/cloud/blockstore/libs/storage/disk_registry/disk_registry_state.h index 435b00b521..3b78b8786f 100644 --- a/cloud/blockstore/libs/storage/disk_registry/disk_registry_state.h +++ b/cloud/blockstore/libs/storage/disk_registry/disk_registry_state.h @@ -464,7 +464,7 @@ class TDiskRegistryState bool HasPendingCleanup(const TDiskId& diskId) const; - const TDiskState* FinishAcquireDisk(const TString& diskId); + void FinishAcquireDisk(const TString& diskId); bool IsAcquireInProgress(const TString& diskId) const;