diff options
author | kruall <kruall@ydb.tech> | 2023-11-10 13:05:28 +0300 |
---|---|---|
committer | kruall <kruall@ydb.tech> | 2023-11-10 13:41:58 +0300 |
commit | d84527173e1f76f9a00ffdef14af1c49cb8a502d (patch) | |
tree | 14f3e683744ec9eee2d217e11d02d2257405abc9 | |
parent | 4c800ac80af5ac83fcc772491904d0aa8e87949c (diff) | |
download | ydb-d84527173e1f76f9a00ffdef14af1c49cb8a502d.tar.gz |
Check stateFunc type before assign it, KIKIMR-19280
18 files changed, 70 insertions, 31 deletions
diff --git a/library/cpp/actors/core/actor.h b/library/cpp/actors/core/actor.h index 7452b50571..96a8f5d05a 100644 --- a/library/cpp/actors/core/actor.h +++ b/library/cpp/actors/core/actor.h @@ -651,6 +651,8 @@ namespace NActors { template <typename TDerived> class TActor: public IActorCallback { private: + using TDerivedReceiveFunc = void (TDerived::*)(TAutoPtr<IEventHandle>& ev); + template <typename T, typename = const char*> struct HasActorName: std::false_type {}; template <typename T> @@ -682,21 +684,56 @@ namespace NActors { protected: // static constexpr char ActorName[] = "UNNAMED"; - TActor(void (TDerived::* func)(TAutoPtr<IEventHandle>& ev)) + TActor(TDerivedReceiveFunc func) : IActorCallback(static_cast<TReceiveFunc>(func), GetActivityTypeIndex()) { } template <class TEnum = EActivityType> - TActor(void (TDerived::* func)(TAutoPtr<IEventHandle>& ev), const TEnum activityEnumType = EActivityType::OTHER) + TActor(TDerivedReceiveFunc func, const TEnum activityEnumType = EActivityType::OTHER) : IActorCallback(static_cast<TReceiveFunc>(func), activityEnumType) { } - TActor(void (TDerived::* func)(TAutoPtr<IEventHandle>& ev), const TString& actorName) + TActor(TDerivedReceiveFunc func, const TString& actorName) : IActorCallback(static_cast<TReceiveFunc>(func), TLocalProcessKeyState<TActorActivityTag>::GetInstance().Register(actorName)) { } public: typedef TDerived TThis; + + // UnsafeBecome methods don't verify the bindings of the stateFunc to the TDerived + template <typename T> + void UnsafeBecome(T stateFunc) { + this->IActorCallback::Become(stateFunc); + } + + template <typename T, typename... TArgs> + void UnsafeBecome(T stateFunc, const TActorContext& ctx, TArgs&&... args) { + this->IActorCallback::Become(stateFunc, ctx, std::forward<TArgs>(args)...); + } + + template <typename T, typename... TArgs> + void UnsafeBecome(T stateFunc, TArgs&&... args) { + this->IActorCallback::Become(stateFunc, std::forward<TArgs>(args)...); + } + + template <typename T> + void Become(T stateFunc) { + // TODO(kruall): have to uncomment asserts after end of sync contrib/ydb + // static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>); + this->IActorCallback::Become(stateFunc); + } + + template <typename T, typename... TArgs> + void Become(T stateFunc, const TActorContext& ctx, TArgs&&... args) { + // static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>); + this->IActorCallback::Become(stateFunc, ctx, std::forward<TArgs>(args)...); + } + + template <typename T, typename... TArgs> + void Become(T stateFunc, TArgs&&... args) { + // static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>); + this->IActorCallback::Become(stateFunc, std::forward<TArgs>(args)...); + } }; diff --git a/ydb/core/blobstorage/dsproxy/dsproxy.h b/ydb/core/blobstorage/dsproxy/dsproxy.h index c00de9c3ad..10baf042eb 100644 --- a/ydb/core/blobstorage/dsproxy/dsproxy.h +++ b/ydb/core/blobstorage/dsproxy/dsproxy.h @@ -159,7 +159,7 @@ inline void SetExecutionRelay(IEventBase& ev, std::shared_ptr<TEvBlobStorage::TE } template<typename TDerived> -class TBlobStorageGroupRequestActor : public TActor<TBlobStorageGroupRequestActor<TDerived>> { +class TBlobStorageGroupRequestActor : public TActor<TDerived> { public: static constexpr NKikimrServices::TActivity::EType ActorActivityType() { return NKikimrServices::TActivity::BS_GROUP_REQUEST; @@ -170,7 +170,7 @@ public: NKikimrServices::EServiceKikimr logComponent, bool logAccEnabled, TMaybe<TGroupStat::EKind> latencyQueueKind, TInstant now, TIntrusivePtr<TStoragePoolCounters> &storagePoolCounters, ui32 restartCounter, TString name, std::shared_ptr<TEvBlobStorage::TExecutionRelay> executionRelay) - : TActor<TBlobStorageGroupRequestActor<TDerived>>(&TThis::InitialStateFunc, TDerived::ActorActivityType()) + : TActor<TDerived>(&TThis::InitialStateFunc, TDerived::ActorActivityType()) , Info(std::move(info)) , GroupQueues(std::move(groupQueues)) , Mon(std::move(mon)) diff --git a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_ut_actions.h b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_ut_actions.h index 064ad1f4e7..23112cae51 100644 --- a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_ut_actions.h +++ b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_ut_actions.h @@ -2270,7 +2270,7 @@ public: TActorTestSlayLogWriteRace(const TIntrusivePtr<TTestConfig> &cfg) : TCommonBaseTest(cfg) { - Become(&TActorTestSlayLogWriteRace::StateFunc); + this->UnsafeBecome(&TActorTestSlayLogWriteRace::StateFunc); } private: diff --git a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_ut_base_test.h b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_ut_base_test.h index 11f063691a..da61ab4740 100644 --- a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_ut_base_test.h +++ b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_ut_base_test.h @@ -358,7 +358,7 @@ public: TBaseTest(const TIntrusivePtr<TTestConfig> &cfg) : TCommonBaseTest(cfg) { - Become(&TBaseTest::StateRegister); + this->UnsafeBecome(&TBaseTest::StateRegister); } diff --git a/ydb/core/blobstorage/ut_blobstorage/monitoring.cpp b/ydb/core/blobstorage/ut_blobstorage/monitoring.cpp index 533a9022dc..583380e957 100644 --- a/ydb/core/blobstorage/ut_blobstorage/monitoring.cpp +++ b/ydb/core/blobstorage/ut_blobstorage/monitoring.cpp @@ -11,7 +11,8 @@ TString MakeData(ui32 dataSize) { return data; } -class TInflightActor : public TActorBootstrapped<TInflightActor> { +template <typename TDerived> +class TInflightActor : public TActorBootstrapped<TDerived> { public: TInflightActor(ui32 requests, ui32 inflight) : RequestCount(requests) @@ -59,6 +60,7 @@ public: ui32 Fails = 0; }; +template <typename TInflightActor> void Test(const TBlobStorageGroupInfo::TTopology& topology, TInflightActor* actor) { const ui32 groupSize = topology.TotalVDisks; const auto& groupErasure = topology.GType; @@ -138,7 +140,7 @@ void Test(const TBlobStorageGroupInfo::TTopology& topology, TInflightActor* acto UNIT_ASSERT_VALUES_EQUAL_C(dsproxyCost, vdiskCost, str.Str()); } -class TInflightActorPut : public TInflightActor { +class TInflightActorPut : public TInflightActor<TInflightActorPut> { public: TInflightActorPut(ui32 requests, ui32 inflight, ui32 dataSize = 1024) : TInflightActor(requests, inflight) @@ -194,7 +196,7 @@ Y_UNIT_TEST(Test##requestType##erasure##Requests##requests##Inflight##inflight## Test(topology, actor); \ } -class TInflightActorGet : public TInflightActor { +class TInflightActorGet : public TInflightActor<TInflightActorGet> { public: TInflightActorGet(ui32 requests, ui32 inflight, ui32 dataSize = 1024) : TInflightActor(requests, inflight) @@ -230,7 +232,7 @@ private: ui32 DataSize; }; -class TInflightActorPatch : public TInflightActor { +class TInflightActorPatch : public TInflightActor<TInflightActorPatch> { public: TInflightActorPatch(ui32 requests, ui32 inflight, ui32 dataSize = 1024) : TInflightActor(requests, inflight) diff --git a/ydb/core/fq/libs/control_plane_proxy/actors/request_actor.h b/ydb/core/fq/libs/control_plane_proxy/actors/request_actor.h index 12084c0ce5..c61882bb4a 100644 --- a/ydb/core/fq/libs/control_plane_proxy/actors/request_actor.h +++ b/ydb/core/fq/libs/control_plane_proxy/actors/request_actor.h @@ -205,7 +205,7 @@ public: } void OnBootstrap() override { - Become(&TCreateQueryRequestActor::StateFunc); + this->UnsafeBecome(&TCreateQueryRequestActor::StateFunc); if (RequestProxy->Get()->Quotas) { SendCreateRateLimiterResourceRequest(); } else { diff --git a/ydb/core/grpc_services/grpc_request_check_actor.h b/ydb/core/grpc_services/grpc_request_check_actor.h index 472a2ac34d..b1b06bff32 100644 --- a/ydb/core/grpc_services/grpc_request_check_actor.h +++ b/ydb/core/grpc_services/grpc_request_check_actor.h @@ -104,7 +104,7 @@ public: } void Bootstrap(const TActorContext& ctx) { - TBase::Become(&TSelf::DbAccessStateFunc); + TBase::UnsafeBecome(&TSelf::DbAccessStateFunc); if (AppData()->FeatureFlags.GetEnableDbCounters()) { Counters_ = WrapGRpcProxyDbCounters(Counters_); diff --git a/ydb/core/grpc_services/rpc_rate_limiter_api.cpp b/ydb/core/grpc_services/rpc_rate_limiter_api.cpp index a5a0a2ec81..274f137b09 100644 --- a/ydb/core/grpc_services/rpc_rate_limiter_api.cpp +++ b/ydb/core/grpc_services/rpc_rate_limiter_api.cpp @@ -82,7 +82,7 @@ public: void Bootstrap(const TActorContext& ctx) { TBase::Bootstrap(ctx); - this->Become(&TRateLimiterControlRequest::StateFunc); + this->UnsafeBecome(&TRateLimiterControlRequest::StateFunc); Ydb::StatusIds::StatusCode status = Ydb::StatusIds::STATUS_CODE_UNSPECIFIED; NYql::TIssues issues; @@ -243,7 +243,7 @@ public: } void SendRequest() override { - Become(&TCreateRateLimiterResourceRPC::StateFunc); + UnsafeBecome(&TCreateRateLimiterResourceRPC::StateFunc); THolder<TEvKesus::TEvAddQuoterResource> req = MakeHolder<TEvKesus::TEvAddQuoterResource>(); CopyProps(GetProtoRequest()->resource(), *req->Record.MutableResource()); @@ -274,7 +274,7 @@ public: } void SendRequest() override { - Become(&TAlterRateLimiterResourceRPC::StateFunc); + UnsafeBecome(&TAlterRateLimiterResourceRPC::StateFunc); THolder<TEvKesus::TEvUpdateQuoterResource> req = MakeHolder<TEvKesus::TEvUpdateQuoterResource>(); CopyProps(GetProtoRequest()->resource(), *req->Record.MutableResource()); @@ -305,7 +305,7 @@ public: } void SendRequest() override { - Become(&TDropRateLimiterResourceRPC::StateFunc); + UnsafeBecome(&TDropRateLimiterResourceRPC::StateFunc); THolder<TEvKesus::TEvDeleteQuoterResource> req = MakeHolder<TEvKesus::TEvDeleteQuoterResource>(); req->Record.SetResourcePath(GetProtoRequest()->resource_path()); @@ -339,7 +339,7 @@ public: } void SendRequest() override { - Become(&TListRateLimiterResourcesRPC::StateFunc); + UnsafeBecome(&TListRateLimiterResourcesRPC::StateFunc); THolder<TEvKesus::TEvDescribeQuoterResources> req = MakeHolder<TEvKesus::TEvDescribeQuoterResources>(); if (const TString& path = GetProtoRequest()->resource_path()) { @@ -383,7 +383,7 @@ public: } void SendRequest() override { - Become(&TDescribeRateLimiterResourceRPC::StateFunc); + UnsafeBecome(&TDescribeRateLimiterResourceRPC::StateFunc); THolder<TEvKesus::TEvDescribeQuoterResources> req = MakeHolder<TEvKesus::TEvDescribeQuoterResources>(); req->Record.AddResourcePaths(GetProtoRequest()->resource_path()); @@ -415,7 +415,7 @@ public: void Bootstrap(const TActorContext& ctx) { TBase::Bootstrap(ctx); - Become(&TAcquireRateLimiterResourceRPC::StateFunc); + UnsafeBecome(&TAcquireRateLimiterResourceRPC::StateFunc); Ydb::StatusIds::StatusCode status = Ydb::StatusIds::STATUS_CODE_UNSPECIFIED; NYql::TIssues issues; @@ -459,7 +459,7 @@ public: } void SendRequest() { - Become(&TAcquireRateLimiterResourceRPC::StateFunc); + UnsafeBecome(&TAcquireRateLimiterResourceRPC::StateFunc); if (GetProtoRequest()->units_case() == Ydb::RateLimiter::AcquireResourceRequest::UnitsCase::kRequired) { SendLeaf( diff --git a/ydb/core/kafka_proxy/actors/kafka_topic_offsets_actor.cpp b/ydb/core/kafka_proxy/actors/kafka_topic_offsets_actor.cpp index 9ab6404914..ec6bbcb2c1 100644 --- a/ydb/core/kafka_proxy/actors/kafka_topic_offsets_actor.cpp +++ b/ydb/core/kafka_proxy/actors/kafka_topic_offsets_actor.cpp @@ -18,7 +18,7 @@ TTopicOffsetsActor::TTopicOffsetsActor(const TEvKafka::TGetOffsetsRequest& reque void TTopicOffsetsActor::Bootstrap(const NActors::TActorContext&) { SendDescribeProposeRequest(); - Become(&TTopicOffsetsActor::StateWork); + UnsafeBecome(&TTopicOffsetsActor::StateWork); } void TTopicOffsetsActor::StateWork(TAutoPtr<IEventHandle>& ev) { diff --git a/ydb/core/tx/tiering/rule/ss_checker.h b/ydb/core/tx/tiering/rule/ss_checker.h index 74272ba14d..d1e9e777e5 100644 --- a/ydb/core/tx/tiering/rule/ss_checker.h +++ b/ydb/core/tx/tiering/rule/ss_checker.h @@ -43,7 +43,7 @@ private: void Handle(NSchemeShard::TEvSchemeShard::TEvProcessingResponse::TPtr& ev); protected: virtual void OnBootstrap() override { - Become(&TSSFetchingActor::StateMain); + UnsafeBecome(&TSSFetchingActor::StateMain); TBase::OnBootstrap(); } virtual void OnFail(const TString& errorMessage) override { diff --git a/ydb/core/viewer/browse_db.h b/ydb/core/viewer/browse_db.h index 39098ca62e..a29dca894c 100644 --- a/ydb/core/viewer/browse_db.h +++ b/ydb/core/viewer/browse_db.h @@ -121,7 +121,7 @@ public: request->Record.SetUserToken(BrowseContext.UserToken); ctx.Send(TxProxy, request.Release()); ++Requests; - Become(&TThis::StateWork); + UnsafeBecome(&TThis::StateWork); } virtual void ReplyAndDie(const TActorContext &ctx) override { diff --git a/ydb/core/viewer/browse_pq.h b/ydb/core/viewer/browse_pq.h index 32dc7983e0..0c3a84b45b 100644 --- a/ydb/core/viewer/browse_pq.h +++ b/ydb/core/viewer/browse_pq.h @@ -275,7 +275,7 @@ public: ctx.Send(TxProxy, request.Release()); ++Requests; ctx.Send(BrowseContext.Owner, new NViewerEvents::TEvBrowseRequestSent(TxProxy, TEvTxUserProxy::EvNavigate)); - Become(&TThis::StateWork); + UnsafeBecome(&TThis::StateWork); } void ReplyAndDie(const TActorContext &ctx) override = 0; diff --git a/ydb/core/viewer/json_tabletinfo.h b/ydb/core/viewer/json_tabletinfo.h index d3922f60d9..a973661ae3 100644 --- a/ydb/core/viewer/json_tabletinfo.h +++ b/ydb/core/viewer/json_tabletinfo.h @@ -106,7 +106,7 @@ public: TActorId txproxy = MakeTxProxyID(); TBase::Send(txproxy, request.Release()); - Become(&TThis::StateRequestedDescribe, TDuration::MilliSeconds(TBase::RequestSettings.Timeout), new TEvents::TEvWakeup()); + UnsafeBecome(&TThis::StateRequestedDescribe, TDuration::MilliSeconds(TBase::RequestSettings.Timeout), new TEvents::TEvWakeup()); } else { TBase::Bootstrap(); if (!TBase::RequestSettings.FilterFields.empty()) { diff --git a/ydb/services/metadata/ds_table/accessor_refresh.cpp b/ydb/services/metadata/ds_table/accessor_refresh.cpp index d425e74309..27770a58ab 100644 --- a/ydb/services/metadata/ds_table/accessor_refresh.cpp +++ b/ydb/services/metadata/ds_table/accessor_refresh.cpp @@ -4,7 +4,7 @@ namespace NKikimr::NMetadata::NProvider { void TDSAccessorRefresher::OnBootstrap() { TBase::OnBootstrap(); - Become(&TDSAccessorRefresher::StateMain); + UnsafeBecome(&TDSAccessorRefresher::StateMain); Sender<TEvRefresh>().SendTo(SelfId()); } diff --git a/ydb/services/metadata/ds_table/accessor_snapshot_simple.cpp b/ydb/services/metadata/ds_table/accessor_snapshot_simple.cpp index abeb7d9a5e..5222fb8f3f 100644 --- a/ydb/services/metadata/ds_table/accessor_snapshot_simple.cpp +++ b/ydb/services/metadata/ds_table/accessor_snapshot_simple.cpp @@ -14,7 +14,7 @@ void TDSAccessorSimple::OnConstructSnapshotError(const TString& errorMessage) { } void TDSAccessorSimple::OnBootstrap() { - Become(&TDSAccessorSimple::StateMain); + UnsafeBecome(&TDSAccessorSimple::StateMain); InputController = std::make_shared<TInputController>(SelfId()); for (auto&& i : SnapshotConstructor->GetManagers()) { PathesInCheck.emplace(i->GetStorageTablePath()); diff --git a/ydb/services/metadata/ds_table/accessor_subscribe.cpp b/ydb/services/metadata/ds_table/accessor_subscribe.cpp index b34b6324bd..9151875526 100644 --- a/ydb/services/metadata/ds_table/accessor_subscribe.cpp +++ b/ydb/services/metadata/ds_table/accessor_subscribe.cpp @@ -56,7 +56,7 @@ void TDSAccessorNotifier::OnSnapshotRefresh() { void TDSAccessorNotifier::OnBootstrap() { TBase::OnBootstrap(); - Become(&TDSAccessorNotifier::StateMain); + UnsafeBecome(&TDSAccessorNotifier::StateMain); } } diff --git a/ydb/services/metadata/manager/alter_impl.h b/ydb/services/metadata/manager/alter_impl.h index d1366f401a..d3f6e72d94 100644 --- a/ydb/services/metadata/manager/alter_impl.h +++ b/ydb/services/metadata/manager/alter_impl.h @@ -192,7 +192,7 @@ private: protected: using TBase::Manager; virtual void InitState() override { - TBase::Become(&TModificationActor<TObject>::StateMain); + TBase::UnsafeBecome(&TModificationActor<TObject>::StateMain); } virtual bool BuildRestoreObjectIds() override { diff --git a/ydb/services/persqueue_v1/actors/schema_actors.cpp b/ydb/services/persqueue_v1/actors/schema_actors.cpp index b232a1cf87..cc8bf691ed 100644 --- a/ydb/services/persqueue_v1/actors/schema_actors.cpp +++ b/ydb/services/persqueue_v1/actors/schema_actors.cpp @@ -1406,7 +1406,7 @@ TPartitionsLocationActor::TPartitionsLocationActor(const TGetPartitionsLocationR void TPartitionsLocationActor::Bootstrap(const NActors::TActorContext&) { SendDescribeProposeRequest(); - Become(&TPartitionsLocationActor::StateWork); + UnsafeBecome(&TPartitionsLocationActor::StateWork); SendNodesRequest(); } |