From ce82bbb9e1241682ebd0d96e32af209761d251fa Mon Sep 17 00:00:00 2001 From: Stepanyuk Vladislav Date: Wed, 22 Jan 2025 07:30:48 +0000 Subject: [PATCH] issue-2542: add timeout and rename request --- cloud/blockstore/config/storage.proto | 5 +- cloud/blockstore/libs/storage/api/volume.h | 46 +++++++-------- cloud/blockstore/libs/storage/core/config.h | 2 + .../libs/storage/protos/volume.proto | 6 +- .../storage/service/service_actor_destroy.cpp | 58 ++++++++++++++----- .../libs/storage/volume/testlib/test_env.cpp | 8 +-- .../libs/storage/volume/testlib/test_env.h | 4 +- .../storage/volume/volume_actor_startstop.cpp | 16 ++--- .../libs/storage/volume/volume_ut.cpp | 6 +- 9 files changed, 89 insertions(+), 62 deletions(-) diff --git a/cloud/blockstore/config/storage.proto b/cloud/blockstore/config/storage.proto index 2fbe1424e4..fee87a6f90 100644 --- a/cloud/blockstore/config/storage.proto +++ b/cloud/blockstore/config/storage.proto @@ -1089,7 +1089,10 @@ message TStorageServiceConfig // Enable buttons for device state changing, when they in error state. optional bool EnableToChangeErrorStatesFromDiskRegistryMonpage = 398; - + // Enabling UsedQuota calculation as UsedIopsQuota + UsedBandwidthQuota optional bool CalculateSplittedUsedQuotaMetric = 399; + + // Timeout for TDestroyVolumeActor (in milliseconds) + optional uint32 DestroyVolumeTimeout = 400; } diff --git a/cloud/blockstore/libs/storage/api/volume.h b/cloud/blockstore/libs/storage/api/volume.h index 123ce988ad..515bf915ae 100644 --- a/cloud/blockstore/libs/storage/api/volume.h +++ b/cloud/blockstore/libs/storage/api/volume.h @@ -15,27 +15,27 @@ namespace NCloud::NBlockStore::NStorage { //////////////////////////////////////////////////////////////////////////////// #define BLOCKSTORE_VOLUME_REQUESTS(xxx, ...) \ - xxx(AddClient, __VA_ARGS__) \ - xxx(RemoveClient, __VA_ARGS__) \ - xxx(WaitReady, __VA_ARGS__) \ - xxx(DescribeBlocks, __VA_ARGS__) \ - xxx(GetPartitionInfo, __VA_ARGS__) \ - xxx(CompactRange, __VA_ARGS__) \ - xxx(GetCompactionStatus, __VA_ARGS__) \ - xxx(ReallocateDisk, __VA_ARGS__) \ - xxx(GetVolumeLoadInfo, __VA_ARGS__) \ - xxx(GetUsedBlocks, __VA_ARGS__) \ - xxx(DeleteCheckpointData, __VA_ARGS__) \ - xxx(UpdateUsedBlocks, __VA_ARGS__) \ - xxx(RebuildMetadata, __VA_ARGS__) \ - xxx(GetRebuildMetadataStatus, __VA_ARGS__) \ - xxx(ScanDisk, __VA_ARGS__) \ - xxx(GetScanDiskStatus, __VA_ARGS__) \ - xxx(GetVolumeInfo, __VA_ARGS__) \ - xxx(UpdateVolumeParams, __VA_ARGS__) \ - xxx(ChangeStorageConfig, __VA_ARGS__) \ - xxx(GetStorageConfig, __VA_ARGS__) \ - xxx(StopPartitionBeforeVolumeDestruction, __VA_ARGS__) \ + xxx(AddClient, __VA_ARGS__) \ + xxx(RemoveClient, __VA_ARGS__) \ + xxx(WaitReady, __VA_ARGS__) \ + xxx(DescribeBlocks, __VA_ARGS__) \ + xxx(GetPartitionInfo, __VA_ARGS__) \ + xxx(CompactRange, __VA_ARGS__) \ + xxx(GetCompactionStatus, __VA_ARGS__) \ + xxx(ReallocateDisk, __VA_ARGS__) \ + xxx(GetVolumeLoadInfo, __VA_ARGS__) \ + xxx(GetUsedBlocks, __VA_ARGS__) \ + xxx(DeleteCheckpointData, __VA_ARGS__) \ + xxx(UpdateUsedBlocks, __VA_ARGS__) \ + xxx(RebuildMetadata, __VA_ARGS__) \ + xxx(GetRebuildMetadataStatus, __VA_ARGS__) \ + xxx(ScanDisk, __VA_ARGS__) \ + xxx(GetScanDiskStatus, __VA_ARGS__) \ + xxx(GetVolumeInfo, __VA_ARGS__) \ + xxx(UpdateVolumeParams, __VA_ARGS__) \ + xxx(ChangeStorageConfig, __VA_ARGS__) \ + xxx(GetStorageConfig, __VA_ARGS__) \ + xxx(GracefulShutdown, __VA_ARGS__) \ // BLOCKSTORE_VOLUME_REQUESTS @@ -332,8 +332,8 @@ struct TEvVolume EvGetStorageConfigRequest = EvBegin + 58, EvGetStorageConfigResponse = EvBegin + 59, - EvStopPartitionBeforeVolumeDestructionRequest = EvBegin + 60, - EvStopPartitionBeforeVolumeDestructionResponse = EvBegin + 61, + EvGracefulShutdownRequest = EvBegin + 60, + EvGracefulShutdownResponse = EvBegin + 61, EvEnd }; diff --git a/cloud/blockstore/libs/storage/core/config.h b/cloud/blockstore/libs/storage/core/config.h index ce6b04e382..599e63e88b 100644 --- a/cloud/blockstore/libs/storage/core/config.h +++ b/cloud/blockstore/libs/storage/core/config.h @@ -627,6 +627,8 @@ class TStorageConfig GetEnableToChangeErrorStatesFromDiskRegistryMonpage() const; [[nodiscard]] bool GetCalculateSplittedUsedQuotaMetric() const; + [[nodiscard]] TDuration GetDestroyVolumeTimeout() const; + }; ui64 GetAllocationUnit( diff --git a/cloud/blockstore/libs/storage/protos/volume.proto b/cloud/blockstore/libs/storage/protos/volume.proto index 03870cf824..c46ab4efae 100644 --- a/cloud/blockstore/libs/storage/protos/volume.proto +++ b/cloud/blockstore/libs/storage/protos/volume.proto @@ -654,9 +654,9 @@ message TGetStorageConfigResponse } //////////////////////////////////////////////////////////////////////////////// -// StopPartitionBeforeVolumeDestruction request/response. +// GracefulShutdown request/response. -message TStopPartitionBeforeVolumeDestructionRequest +message TGracefulShutdownRequest { // Optional request headers. THeaders Headers = 1; @@ -666,7 +666,7 @@ message TStopPartitionBeforeVolumeDestructionRequest string DiskId = 2; } -message TStopPartitionBeforeVolumeDestructionResponse +message TGracefulShutdownResponse { // Optional error, set only if error happened. NCloud.NProto.TError Error = 1; diff --git a/cloud/blockstore/libs/storage/service/service_actor_destroy.cpp b/cloud/blockstore/libs/storage/service/service_actor_destroy.cpp index dbb51e47b7..62ef4b7bf2 100644 --- a/cloud/blockstore/libs/storage/service/service_actor_destroy.cpp +++ b/cloud/blockstore/libs/storage/service/service_actor_destroy.cpp @@ -34,6 +34,7 @@ class TDestroyVolumeActor final const bool DestroyIfBroken; const bool Sync; const ui64 FillGeneration; + const TDuration Timeout; bool IsDiskRegistryBased = false; bool VolumeNotFoundInSS = false; @@ -47,7 +48,8 @@ class TDestroyVolumeActor final TString diskId, bool destroyIfBroken, bool sync, - ui64 fillGeneration); + ui64 fillGeneration, + TDuration timeout); void Bootstrap(const TActorContext& ctx); @@ -57,7 +59,7 @@ class TDestroyVolumeActor final void NotifyDiskRegistry(const TActorContext& ctx); void StatVolume(const TActorContext& ctx); void DeallocateDisk(const TActorContext& ctx); - void StopPartitions(const TActorContext& ctx); + void GracefulShutdown(const TActorContext& ctx); NProto::TError CheckIfDestructionIsAllowed() const; void HandleModifyResponse( @@ -80,11 +82,15 @@ class TDestroyVolumeActor final const TEvDiskRegistry::TEvDeallocateDiskResponse::TPtr& ev, const TActorContext& ctx); - void HandleStopPartitions( - const TEvVolume::TEvStopPartitionBeforeVolumeDestructionResponse::TPtr& + void HandleGracefulShutdownResponse( + const TEvVolume::TEvGracefulShutdownResponse::TPtr& ev, const TActorContext& ctx); + void HandleTimeout( + const TEvents::TEvWakeup::TPtr& ev, + const TActorContext& ctx); + void ReplyAndDie(const TActorContext& ctx, NProto::TError error); private: @@ -101,7 +107,8 @@ TDestroyVolumeActor::TDestroyVolumeActor( TString diskId, bool destroyIfBroken, bool sync, - ui64 fillGeneration) + ui64 fillGeneration, + TDuration timeout) : Sender(sender) , Cookie(cookie) , AttachedDiskDestructionTimeout(attachedDiskDestructionTimeout) @@ -111,10 +118,12 @@ TDestroyVolumeActor::TDestroyVolumeActor( , DestroyIfBroken(destroyIfBroken) , Sync(sync) , FillGeneration(fillGeneration) + , Timeout(timeout) {} void TDestroyVolumeActor::Bootstrap(const TActorContext& ctx) { + ctx.Schedule(Timeout, new TEvents::TEvWakeup()); if (DestroyIfBroken) { WaitReady(ctx); } else { @@ -186,12 +195,12 @@ void TDestroyVolumeActor::DeallocateDisk(const TActorContext& ctx) NCloud::Send(ctx, MakeDiskRegistryProxyServiceId(), std::move(request)); } -void TDestroyVolumeActor::StopPartitions(const TActorContext& ctx) +void TDestroyVolumeActor::GracefulShutdown(const TActorContext& ctx) { - auto stopPartReq = std::make_unique< - TEvVolume::TEvStopPartitionBeforeVolumeDestructionRequest>(); - stopPartReq->Record.SetDiskId(DiskId); - NCloud::Send(ctx, MakeVolumeProxyServiceId(), std::move(stopPartReq)); + auto request = std::make_unique< + TEvVolume::TEvGracefulShutdownRequest>(); + request->Record.SetDiskId(DiskId); + NCloud::Send(ctx, MakeVolumeProxyServiceId(), std::move(request)); } NProto::TError TDestroyVolumeActor::CheckIfDestructionIsAllowed() const @@ -296,7 +305,7 @@ void TDestroyVolumeActor::HandleMarkDiskForCleanupResponse( return; } - StopPartitions(ctx); + GracefulShutdown(ctx); } void TDestroyVolumeActor::HandleDeallocateDiskResponse( @@ -397,14 +406,28 @@ void TDestroyVolumeActor::HandleStatVolumeResponse( } } -void TDestroyVolumeActor::HandleStopPartitions( - const TEvVolume::TEvStopPartitionBeforeVolumeDestructionResponse::TPtr& ev, +void TDestroyVolumeActor::HandleGracefulShutdownResponse( + const TEvVolume::TEvGracefulShutdownResponse::TPtr& ev, const TActorContext& ctx) { Y_UNUSED(ev); DestroyVolume(ctx); } +void TDestroyVolumeActor::HandleTimeout( + const TEvents::TEvWakeup::TPtr& ev, + const TActorContext& ctx) +{ + Y_UNUSED(ev); + + LOG_WARN( + ctx, + TBlockStoreComponents::SERVICE, + "Timeout destroy volume request"); + + ReplyAndDie(ctx, MakeError(E_TIMEOUT, "Timeout")); +} + void TDestroyVolumeActor::ReplyAndDie( const TActorContext& ctx, NProto::TError error) @@ -435,8 +458,10 @@ STFUNC(TDestroyVolumeActor::StateWork) HandleStatVolumeResponse); HFunc( - TEvVolume::TEvStopPartitionBeforeVolumeDestructionResponse, - HandleStopPartitions); + TEvVolume::TEvGracefulShutdownResponse, + HandleGracefulShutdownResponse); + + HFunc(TEvents::TEvWakeup, HandleTimeout); default: HandleUnexpectedEvent(ev, TBlockStoreComponents::SERVICE); @@ -475,7 +500,8 @@ void TServiceActor::HandleDestroyVolume( diskId, destroyIfBroken, sync, - fillGeneration); + fillGeneration, + Config->GetDestroyVolumeTimeout()); } } // namespace NCloud::NBlockStore::NStorage diff --git a/cloud/blockstore/libs/storage/volume/testlib/test_env.cpp b/cloud/blockstore/libs/storage/volume/testlib/test_env.cpp index 1bbb1cac70..98be0f8bc8 100644 --- a/cloud/blockstore/libs/storage/volume/testlib/test_env.cpp +++ b/cloud/blockstore/libs/storage/volume/testlib/test_env.cpp @@ -551,10 +551,10 @@ TVolumeClient::CreateReadMetaHistoryRequest() return std::make_unique(); } -std::unique_ptr -TVolumeClient::CreateStopPartitionBeforeVolumeDestructionRequest() { - return std::make_unique< - TEvVolume::TEvStopPartitionBeforeVolumeDestructionRequest>(); +std::unique_ptr +TVolumeClient::CreateGracefulShutdownRequest() +{ + return std::make_unique(); } void TVolumeClient::SendRemoteHttpInfo( diff --git a/cloud/blockstore/libs/storage/volume/testlib/test_env.h b/cloud/blockstore/libs/storage/volume/testlib/test_env.h index 91406a0a52..f3bef0a49b 100644 --- a/cloud/blockstore/libs/storage/volume/testlib/test_env.h +++ b/cloud/blockstore/libs/storage/volume/testlib/test_env.h @@ -460,8 +460,8 @@ class TVolumeClient std::unique_ptr CreateReadMetaHistoryRequest(); - std::unique_ptr - CreateStopPartitionBeforeVolumeDestructionRequest(); + std::unique_ptr + CreateGracefulShutdownRequest(); void SendRemoteHttpInfo( const TString& params, diff --git a/cloud/blockstore/libs/storage/volume/volume_actor_startstop.cpp b/cloud/blockstore/libs/storage/volume/volume_actor_startstop.cpp index 73ce240d4c..b84d9675eb 100644 --- a/cloud/blockstore/libs/storage/volume/volume_actor_startstop.cpp +++ b/cloud/blockstore/libs/storage/volume/volume_actor_startstop.cpp @@ -346,24 +346,22 @@ void TVolumeActor::StartPartitionsForGc(const TActorContext& ctx) PartitionsStartedReason = EPartitionsStartedReason::STARTED_FOR_GC; } -void TVolumeActor::HandleStopPartitionBeforeVolumeDestruction( - const TEvVolume::TEvStopPartitionBeforeVolumeDestructionRequest::TPtr& ev, +void TVolumeActor::HandleGracefulShutdown( + const TEvVolume::TEvGracefulShutdownRequest::TPtr& ev, const TActorContext& ctx) { if (!State->GetDiskRegistryBasedPartitionActor()) { LOG_ERROR( ctx, TBlockStoreComponents::VOLUME, - "[%lu] StopPartitionBeforeVolumeDestruction request was send to " - "not " - "DR based disk", + "[%lu] GracefulShutdown request was send to " + "not DR based disk", TabletID()); NCloud::Reply( ctx, *ev, - std::make_unique< - TEvVolume::TEvStopPartitionBeforeVolumeDestructionResponse>( + std::make_unique( MakeError(E_NOT_IMPLEMENTED, "request not supported"))); return; } @@ -383,9 +381,7 @@ void TVolumeActor::HandleStopPartitionBeforeVolumeDestruction( NCloud::Reply( ctx, *reqInfo, - std::make_unique< - TEvVolume:: - TEvStopPartitionBeforeVolumeDestructionResponse>()); + std::make_unique()); }); TerminateTransactions(ctx); diff --git a/cloud/blockstore/libs/storage/volume/volume_ut.cpp b/cloud/blockstore/libs/storage/volume/volume_ut.cpp index b295dd5f61..8026751f72 100644 --- a/cloud/blockstore/libs/storage/volume/volume_ut.cpp +++ b/cloud/blockstore/libs/storage/volume/volume_ut.cpp @@ -8175,7 +8175,7 @@ Y_UNIT_TEST_SUITE(TVolumeTest) 0, false, 1, - NCloud::NProto::EStorageMediaKind::STORAGE_MEDIA_SSD_NONREPLICATED, + NCloud::NProto::STORAGE_MEDIA_SSD_NONREPLICATED, 1024, "vol0", "cloud", @@ -8190,10 +8190,10 @@ Y_UNIT_TEST_SUITE(TVolumeTest) false); - volume.StopPartitionBeforeVolumeDestruction(); + volume.GracefulShutdown(); UNIT_ASSERT(partitionsStopped); - // Check that volume after TEvStopPartitionBeforeVolumeDestructionRequest + // Check that volume after TEvGracefulShutdownRequest // in zombie state and rejects requsts. volume.SendGetVolumeInfoRequest(); auto response = volume.RecvGetVolumeInfoResponse();