Skip to content

Commit a4ce19d

Browse files
snauryblinkov
authored andcommitted
Remove unused virtual actors and related logic (#15563)
1 parent bb3aa38 commit a4ce19d

File tree

13 files changed

+58
-260
lines changed

13 files changed

+58
-260
lines changed

ydb/core/viewer/json_handlers.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ class TJsonHandler : public TJsonHandlerBase {
3838
{}
3939

4040
IActor* CreateRequestActor(IViewer* viewer, NMon::TEvHttpInfo::TPtr& event) override {
41-
return new ActorRequestType(viewer, event);
41+
if constexpr (!std::is_same_v<ActorRequestType, void>) {
42+
return new ActorRequestType(viewer, event);
43+
} else {
44+
return nullptr;
45+
}
4246
}
4347

4448
YAML::Node GetRequestSwagger() override {

ydb/core/viewer/scheme_directory.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
namespace NKikimr::NViewer {
88

9-
class TSchemeDirectory : public IActor {
10-
public:
11-
TSchemeDirectory(IViewer*, NMon::TEvHttpInfo::TPtr&) {}
12-
};
13-
149
using TSchemeDirectoryGetRpc = TJsonLocalRpc<Ydb::Scheme::ListDirectoryRequest,
1510
Ydb::Scheme::ListDirectoryResponse,
1611
Ydb::Scheme::ListDirectoryResult,
@@ -57,10 +52,10 @@ class TSchemeDirectoryRequest : public LocalRpcType {
5752
}
5853
};
5954

60-
class TJsonSchemeDirectoryHandler : public TJsonHandler<TSchemeDirectory> {
55+
class TJsonSchemeDirectoryHandler : public TJsonHandler<void> {
6156
public:
6257
TJsonSchemeDirectoryHandler()
63-
: TJsonHandler<TSchemeDirectory>(GetSwagger())
58+
: TJsonHandler(GetSwagger())
6459
{}
6560

6661
IActor* CreateRequestActor(IViewer* viewer, NMon::TEvHttpInfo::TPtr& event) override {

ydb/library/actors/core/actor.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "actor.h"
22
#include "debug.h"
3-
#include "actor_virtual.h"
43
#include "actorsystem.h"
54
#include "executor_thread.h"
65
#include <ydb/library/actors/util/datetime.h>
@@ -268,15 +267,6 @@ namespace NActors {
268267
return NHPTimer::GetSeconds(ElapsedTicks);
269268
}
270269

271-
void TActorCallbackBehaviour::Receive(IActor* actor, TAutoPtr<IEventHandle>& ev) {
272-
(actor->*StateFunc)(ev);
273-
}
274-
275-
void TActorVirtualBehaviour::Receive(IActor* actor, std::unique_ptr<IEventHandle> ev) {
276-
Y_ABORT_UNLESS(!!ev && ev->GetBase());
277-
ev->GetBase()->Execute(actor, std::move(ev));
278-
}
279-
280270
void IActor::Registered(TActorSystem* sys, const TActorId& owner) {
281271
// fallback to legacy method, do not use it anymore
282272
if (auto eh = AfterRegister(SelfId(), owner)) {

ydb/library/actors/core/actor.h

Lines changed: 40 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,6 @@ namespace NActors {
284284

285285
class TDecorator;
286286

287-
class TActorVirtualBehaviour {
288-
public:
289-
static void Receive(IActor* actor, std::unique_ptr<IEventHandle> ev);
290-
public:
291-
};
292-
293287
class TActorCallbackBehaviour {
294288
private:
295289
using TBase = IActor;
@@ -374,18 +368,14 @@ namespace NActors {
374368
friend class TExecutorPoolBaseMailboxed;
375369
friend class TExecutorThread;
376370

377-
IActor(const ui32 activityType)
378-
: SelfActorId(TActorId())
379-
, ElapsedTicks(0)
380-
, ActivityType(activityType)
381-
, HandledEvents(0) {
382-
}
371+
public:
372+
using TReceiveFunc = void (IActor::*)(TAutoPtr<IEventHandle>& ev);
373+
374+
private:
375+
TReceiveFunc StateFunc_;
383376

384-
protected:
385-
TActorCallbackBehaviour CImpl;
386377
public:
387378
using TEventFlags = IEventHandle::TEventFlags;
388-
using TReceiveFunc = TActorCallbackBehaviour::TReceiveFunc;
389379
/// @sa services.proto NKikimrServices::TActivity::EType
390380
using EActorActivity = EInternalActorType;
391381
using EActivityType = EActorActivity;
@@ -394,23 +384,39 @@ namespace NActors {
394384
protected:
395385
ui64 HandledEvents;
396386

397-
template <typename EEnum = EActivityType, typename std::enable_if<std::is_enum<EEnum>::value, bool>::type v = true>
398-
IActor(const EEnum activityEnumType = EActivityType::OTHER)
399-
: IActor(TEnumProcessKey<TActorActivityTag, EEnum>::GetIndex(activityEnumType)) {
400-
}
401-
402-
IActor(TActorCallbackBehaviour&& cImpl, const ui32 activityType)
387+
IActor(TReceiveFunc stateFunc, const ui32 activityType)
403388
: SelfActorId(TActorId())
404389
, ElapsedTicks(0)
405-
, CImpl(std::move(cImpl))
390+
, StateFunc_(stateFunc)
406391
, ActivityType(activityType)
407392
, HandledEvents(0)
408393
{
409394
}
410395

411396
template <typename EEnum = EActivityType, typename std::enable_if<std::is_enum<EEnum>::value, bool>::type v = true>
412-
IActor(TActorCallbackBehaviour&& cImpl, const EEnum activityEnumType = EActivityType::OTHER)
413-
: IActor(std::move(cImpl), TEnumProcessKey<TActorActivityTag, EEnum>::GetIndex(activityEnumType)) {
397+
IActor(TReceiveFunc stateFunc, const EEnum activityEnumType = EActivityType::OTHER)
398+
: IActor(stateFunc, TEnumProcessKey<TActorActivityTag, EEnum>::GetIndex(activityEnumType)) {
399+
}
400+
401+
template <typename T>
402+
void Become(T stateFunc) {
403+
StateFunc_ = static_cast<TReceiveFunc>(stateFunc);
404+
}
405+
406+
template <typename T, typename... TArgs>
407+
void Become(T stateFunc, TArgs&&... args) {
408+
StateFunc_ = static_cast<TReceiveFunc>(stateFunc);
409+
Schedule(std::forward<TArgs>(args)...);
410+
}
411+
412+
template <typename T, typename... TArgs>
413+
void Become(T stateFunc, const TActorContext& ctx, TArgs&&... args) {
414+
StateFunc_ = static_cast<TReceiveFunc>(stateFunc);
415+
ctx.Schedule(std::forward<TArgs>(args)...);
416+
}
417+
418+
TReceiveFunc CurrentStateFunc() const {
419+
return StateFunc_;
414420
}
415421

416422
public:
@@ -549,11 +555,7 @@ namespace NActors {
549555
#endif
550556
++HandledEvents;
551557
LastReceiveTimestamp = TActivationContext::Monotonic();
552-
if (CImpl.Initialized()) {
553-
CImpl.Receive(this, ev);
554-
} else {
555-
TActorVirtualBehaviour::Receive(this, std::unique_ptr<IEventHandle>(ev.Release()));
556-
}
558+
(this->*StateFunc_)(ev);
557559
}
558560

559561
TActorContext ActorContext() const {
@@ -639,43 +641,11 @@ namespace NActors {
639641
return TLocalProcessKeyState<TActorActivityTag>::GetInstance().GetNameByIndex(index);
640642
}
641643

642-
class IActorCallback: public IActor {
643-
protected:
644-
template <class TEnum = IActor::EActivityType>
645-
IActorCallback(TReceiveFunc stateFunc, const TEnum activityType = IActor::EActivityType::OTHER)
646-
: IActor(TActorCallbackBehaviour(stateFunc), activityType) {
647-
648-
}
649-
650-
IActorCallback(TReceiveFunc stateFunc, const ui32 activityType)
651-
: IActor(TActorCallbackBehaviour(stateFunc), activityType) {
652-
653-
}
654-
655-
public:
656-
template <typename T>
657-
void Become(T stateFunc) {
658-
CImpl.Become(stateFunc);
659-
}
660-
661-
template <typename T, typename... TArgs>
662-
void Become(T stateFunc, const TActorContext& ctx, TArgs&&... args) {
663-
CImpl.Become(stateFunc, ctx, std::forward<TArgs>(args)...);
664-
}
665-
666-
template <typename T, typename... TArgs>
667-
void Become(T stateFunc, TArgs&&... args) {
668-
CImpl.Become(stateFunc);
669-
Schedule(std::forward<TArgs>(args)...);
670-
}
671-
672-
TReceiveFunc CurrentStateFunc() const {
673-
return CImpl.CurrentStateFunc();
674-
}
675-
};
644+
// For compatibility with existing code
645+
using IActorCallback = IActor;
676646

677647
template <typename TDerived>
678-
class TActor: public IActorCallback {
648+
class TActor: public IActor {
679649
private:
680650
using TDerivedReceiveFunc = void (TDerived::*)(TAutoPtr<IEventHandle>& ev);
681651

@@ -729,36 +699,36 @@ namespace NActors {
729699
// UnsafeBecome methods don't verify the bindings of the stateFunc to the TDerived
730700
template <typename T>
731701
void UnsafeBecome(T stateFunc) {
732-
this->IActorCallback::Become(stateFunc);
702+
this->IActor::Become(stateFunc);
733703
}
734704

735705
template <typename T, typename... TArgs>
736706
void UnsafeBecome(T stateFunc, const TActorContext& ctx, TArgs&&... args) {
737-
this->IActorCallback::Become(stateFunc, ctx, std::forward<TArgs>(args)...);
707+
this->IActor::Become(stateFunc, ctx, std::forward<TArgs>(args)...);
738708
}
739709

740710
template <typename T, typename... TArgs>
741711
void UnsafeBecome(T stateFunc, TArgs&&... args) {
742-
this->IActorCallback::Become(stateFunc, std::forward<TArgs>(args)...);
712+
this->IActor::Become(stateFunc, std::forward<TArgs>(args)...);
743713
}
744714

745715
template <typename T>
746716
void Become(T stateFunc) {
747717
// TODO(kruall): have to uncomment asserts after end of sync contrib/ydb
748718
// static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>);
749-
this->IActorCallback::Become(stateFunc);
719+
this->IActor::Become(stateFunc);
750720
}
751721

752722
template <typename T, typename... TArgs>
753723
void Become(T stateFunc, const TActorContext& ctx, TArgs&&... args) {
754724
// static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>);
755-
this->IActorCallback::Become(stateFunc, ctx, std::forward<TArgs>(args)...);
725+
this->IActor::Become(stateFunc, ctx, std::forward<TArgs>(args)...);
756726
}
757727

758728
template <typename T, typename... TArgs>
759729
void Become(T stateFunc, TArgs&&... args) {
760730
// static_assert(std::is_convertible_v<T, TDerivedReceiveFunc>);
761-
this->IActorCallback::Become(stateFunc, std::forward<TArgs>(args)...);
731+
this->IActor::Become(stateFunc, std::forward<TArgs>(args)...);
762732
}
763733
};
764734

ydb/library/actors/core/actor_virtual.cpp

Lines changed: 0 additions & 6 deletions
This file was deleted.

ydb/library/actors/core/actor_virtual.h

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,4 @@
22
#include "event.h"
33
#include "actor.h"
44

5-
namespace NActors {
6-
7-
template <class TEvent>
8-
class TEventContext {
9-
private:
10-
TEvent* Event;
11-
std::unique_ptr<IEventHandle> Handle;
12-
public:
13-
const TEvent* operator->() const {
14-
return Event;
15-
}
16-
const IEventHandle& GetHandle() const {
17-
return *Handle;
18-
}
19-
TEventContext(std::unique_ptr<IEventHandle> handle)
20-
: Handle(std::move(handle))
21-
{
22-
Y_DEBUG_ABORT_UNLESS(dynamic_cast<TEvent*>(Handle->GetBase()));
23-
Event = static_cast<TEvent*>(Handle->GetBase());
24-
Y_ABORT_UNLESS(Event);
25-
}
26-
};
27-
28-
template <class TEvent, class TExpectedActor>
29-
class IEventForActor: public IEventBase {
30-
protected:
31-
virtual bool DoExecute(IActor* actor, std::unique_ptr<IEventHandle> eventPtr) override {
32-
Y_DEBUG_ABORT_UNLESS(dynamic_cast<TExpectedActor*>(actor));
33-
auto* actorCorrect = static_cast<TExpectedActor*>(actor);
34-
TEventContext<TEvent> context(std::move(eventPtr));
35-
actorCorrect->ProcessEvent(context);
36-
return true;
37-
}
38-
public:
39-
};
40-
41-
template <class TBaseEvent, class TEvent, class TExpectedObject>
42-
class IEventForAnything: public TBaseEvent {
43-
protected:
44-
virtual bool DoExecute(IActor* actor, std::unique_ptr<IEventHandle> eventPtr) override {
45-
auto* objImpl = dynamic_cast<TExpectedObject*>(actor);
46-
if (!objImpl) {
47-
return false;
48-
}
49-
TEventContext<TEvent> context(std::move(eventPtr));
50-
objImpl->ProcessEvent(context);
51-
return true;
52-
}
53-
public:
54-
};
55-
56-
template <class TEvent, class TActor>
57-
class TEventLocalForActor: public IEventForActor<TEvent, TActor> {
58-
private:
59-
using TBase = IEventForActor<TEvent, TActor>;
60-
static TString GetClassTitle() {
61-
return TStringBuilder() << typeid(TEvent).name() << "->" << typeid(TActor).name();
62-
}
63-
static i64 LocalClassId;
64-
public:
65-
virtual ui32 Type() const override {
66-
return LocalClassId;
67-
}
68-
virtual TString ToStringHeader() const override {
69-
return GetClassTitle();
70-
}
71-
72-
virtual bool SerializeToArcadiaStream(TChunkSerializer* /*serializer*/) const override {
73-
Y_ABORT("Serialization of local event %s->%s", typeid(TEvent).name(), typeid(TActor).name());
74-
}
75-
76-
virtual bool IsSerializable() const override {
77-
return false;
78-
}
79-
80-
static IEventBase* Load(TEventSerializedData*) {
81-
Y_ABORT("Loading of local event %s->%s", typeid(TEvent).name(), typeid(TActor).name());
82-
}
83-
};
84-
85-
template <class TEvent, class TActor>
86-
i64 TEventLocalForActor<TEvent, TActor>::LocalClassId = Singleton<TAtomicCounter>()->Inc();
87-
88-
}
5+
// NOTE: virtual actors with event callbacks are no longer supported

ydb/library/actors/core/av_bootstrapped.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
11
#pragma once
22
#include "actor_virtual.h"
33

4-
namespace NActors {
5-
6-
class TEventForStart;
7-
8-
class TActorAutoStart: public IActor {
9-
protected:
10-
virtual void DoOnStart(const TActorId& senderActorId) = 0;
11-
TAutoPtr<IEventHandle> AfterRegister(const TActorId& self, const TActorId& parentId) override;
12-
public:
13-
void ProcessEvent(TEventContext<TEventForStart>& ev);
14-
15-
TActorAutoStart()
16-
{}
17-
};
18-
}
4+
// NOTE: virtual actors with event callbacks are no longer supported

ydb/library/actors/core/event.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,6 @@ namespace NActors {
5151
return new TEventSerializedData;
5252
}
5353

54-
bool IEventBase::DoExecute(IActor* /*actor*/, std::unique_ptr<IEventHandle> /*eventPtr*/) {
55-
Y_DEBUG_ABORT_UNLESS(false);
56-
return false;
57-
}
58-
59-
bool IEventBase::Execute(IActor* actor, std::unique_ptr<IEventHandle> eventPtr) {
60-
return DoExecute(actor, std::move(eventPtr));
61-
}
62-
6354
#ifndef NDEBUG
6455
void IEventHandle::DoTrackNextEvent() {
6556
TrackNextEvent = true;

0 commit comments

Comments
 (0)