diff --git a/cloud/blockstore/libs/storage/partition_nonrepl/part_nonrepl_migration_common_actor.h b/cloud/blockstore/libs/storage/partition_nonrepl/part_nonrepl_migration_common_actor.h index dc930598503..34b60b0057b 100644 --- a/cloud/blockstore/libs/storage/partition_nonrepl/part_nonrepl_migration_common_actor.h +++ b/cloud/blockstore/libs/storage/partition_nonrepl/part_nonrepl_migration_common_actor.h @@ -65,8 +65,12 @@ class IMigrationOwner class TNonreplicatedPartitionMigrationCommonActor : public NActors::TActorBootstrapped< TNonreplicatedPartitionMigrationCommonActor> + , IPoisonPillHelperOwner { private: + using TBase = NActors::TActorBootstrapped< + TNonreplicatedPartitionMigrationCommonActor>; + IMigrationOwner* const MigrationOwner = nullptr; const TStorageConfigPtr Config; const IProfileLogPtr ProfileLog; @@ -131,6 +135,12 @@ class TNonreplicatedPartitionMigrationCommonActor // Called from the inheritor to get the next processing range. TBlockRange64 GetNextProcessingRange() const; + // IPoisonPillHelperOwner implementation + void Die(const NActors::TActorContext& ctx) override + { + TBase::Die(ctx); + } + private: void ScheduleCountersUpdate(const NActors::TActorContext& ctx); void SendStats(const NActors::TActorContext& ctx); diff --git a/cloud/storage/core/libs/actors/poison_pill_helper.cpp b/cloud/storage/core/libs/actors/poison_pill_helper.cpp index acd1603b308..d4b0a436f6c 100644 --- a/cloud/storage/core/libs/actors/poison_pill_helper.cpp +++ b/cloud/storage/core/libs/actors/poison_pill_helper.cpp @@ -5,26 +5,10 @@ using namespace NActors; namespace NCloud { -namespace { //////////////////////////////////////////////////////////////////////////////// -// Helps to call protected methods of IActor. -class IActorHelper: public IActor -{ -public: - static void CallDie(IActor* actor, const TActorContext& ctx) - { - Y_DEBUG_ABORT_UNLESS(actor); - static_cast(actor)->Die(ctx); - } -}; - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// - -TPoisonPillHelper::TPoisonPillHelper(NActors::IActor* owner) +TPoisonPillHelper::TPoisonPillHelper(IPoisonPillHelperOwner* owner) : Owner(owner) {} @@ -90,8 +74,7 @@ void TPoisonPillHelper::ReplyAndDie(const TActorContext& ctx) std::make_unique(), 0, // flags Poisoner->Cookie); - - IActorHelper::CallDie(Owner, ctx); + Owner->Die(ctx); } } // namespace NCloud diff --git a/cloud/storage/core/libs/actors/poison_pill_helper.h b/cloud/storage/core/libs/actors/poison_pill_helper.h index 0e8fa8e5a7f..08c9f8e4afd 100644 --- a/cloud/storage/core/libs/actors/poison_pill_helper.h +++ b/cloud/storage/core/libs/actors/poison_pill_helper.h @@ -9,6 +9,14 @@ namespace NCloud { //////////////////////////////////////////////////////////////////////////////// +// The owner of TPoisonPillHelper must implement this interface to make it +// possible to kill the parent actor. +class IPoisonPillHelperOwner +{ +public: + virtual void Die(const NActors::TActorContext& ctx) = 0; +}; + // Helps to handle the TEvPoisonPill for actor who owns other actors. The helper // sends TEvPoisonPill to all owned actors and waits for a response // TEvPoisonTaken from everyone. After that, it responds with the TEvPoisonTaken @@ -22,12 +30,12 @@ class TPoisonPillHelper ui64 Cookie = 0; }; - NActors::IActor* Owner; + IPoisonPillHelperOwner* Owner; TSet OwnedActors; std::optional Poisoner; public: - explicit TPoisonPillHelper(NActors::IActor* owner); + explicit TPoisonPillHelper(IPoisonPillHelperOwner* owner); virtual ~TPoisonPillHelper(); void TakeOwnership( diff --git a/cloud/storage/core/libs/actors/poison_pill_helper_ut.cpp b/cloud/storage/core/libs/actors/poison_pill_helper_ut.cpp index 8900be531c8..2a93d41f2cf 100644 --- a/cloud/storage/core/libs/actors/poison_pill_helper_ut.cpp +++ b/cloud/storage/core/libs/actors/poison_pill_helper_ut.cpp @@ -87,9 +87,12 @@ class TChildActor: public TActor //////////////////////////////////////////////////////////////////////////////// -class TParentActor: public TActor +class TParentActor + : public TActor + , IPoisonPillHelperOwner { private: + using TBase = TActor; TPoisonPillHelper PoisonPillHelper; ui32 ChildCount; @@ -100,6 +103,11 @@ class TParentActor: public TActor , ChildCount(childCount) {} + void Die(const NActors::TActorContext& ctx) override + { + TBase::Die(ctx); + } + private: void Main(TAutoPtr& ev) {