diff options
author | single <single@yandex-team.ru> | 2022-02-10 16:50:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:30 +0300 |
commit | f7835298a8840c8e5d98715bf23efa9c7e03b9c4 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/actors | |
parent | 8ae96df130bbede609c3504aa9af1bc6ff5361b3 (diff) | |
download | ydb-f7835298a8840c8e5d98715bf23efa9c7e03b9c4.tar.gz |
Restoring authorship annotation for <single@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/actors')
-rw-r--r-- | library/cpp/actors/core/actor.cpp | 20 | ||||
-rw-r--r-- | library/cpp/actors/core/actor.h | 24 | ||||
-rw-r--r-- | library/cpp/actors/core/event.h | 10 | ||||
-rw-r--r-- | library/cpp/actors/core/events.h | 36 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_pool_base.cpp | 8 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_thread.cpp | 10 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_thread.h | 2 | ||||
-rw-r--r-- | library/cpp/actors/core/log.cpp | 26 | ||||
-rw-r--r-- | library/cpp/actors/core/log.h | 12 | ||||
-rw-r--r-- | library/cpp/actors/core/log_iface.h | 56 | ||||
-rw-r--r-- | library/cpp/actors/core/log_settings.cpp | 6 | ||||
-rw-r--r-- | library/cpp/actors/core/log_settings.h | 22 | ||||
-rw-r--r-- | library/cpp/actors/dnscachelib/dnscache.cpp | 162 | ||||
-rw-r--r-- | library/cpp/actors/dnscachelib/dnscache.h | 20 | ||||
-rw-r--r-- | library/cpp/actors/testlib/test_runtime.cpp | 64 | ||||
-rw-r--r-- | library/cpp/actors/testlib/test_runtime.h | 26 | ||||
-rw-r--r-- | library/cpp/actors/testlib/ya.make | 36 |
17 files changed, 270 insertions, 270 deletions
diff --git a/library/cpp/actors/core/actor.cpp b/library/cpp/actors/core/actor.cpp index 243a3e1a86..6f9ba6a42b 100644 --- a/library/cpp/actors/core/actor.cpp +++ b/library/cpp/actors/core/actor.cpp @@ -16,15 +16,15 @@ namespace NActors { } void IActor::Registered(TActorSystem* sys, const TActorId& owner) { - // fallback to legacy method, do not use it anymore - if (auto eh = AfterRegister(SelfId(), owner)) - sys->Send(eh); - } - - void IActor::Describe(IOutputStream &out) const noexcept { - SelfActorId.Out(out); - } - + // fallback to legacy method, do not use it anymore + if (auto eh = AfterRegister(SelfId(), owner)) + sys->Send(eh); + } + + void IActor::Describe(IOutputStream &out) const noexcept { + SelfActorId.Out(out); + } + bool IActor::Send(const TActorId& recipient, IEventBase* ev, ui32 flags, ui64 cookie, NWilson::TTraceId traceId) const noexcept { return SelfActorId.Send(recipient, ev, flags, cookie, std::move(traceId)); } @@ -123,7 +123,7 @@ namespace NActors { TlsActivationContext->ExecutorThread.Schedule(deadline, new IEventHandle(SelfActorId, TActorId(), ev), cookie); } - void IActor::Schedule(TDuration delta, IEventBase* ev, ISchedulerCookie* cookie) const noexcept { + void IActor::Schedule(TDuration delta, IEventBase* ev, ISchedulerCookie* cookie) const noexcept { TlsActivationContext->ExecutorThread.Schedule(delta, new IEventHandle(SelfActorId, TActorId(), ev), cookie); } diff --git a/library/cpp/actors/core/actor.h b/library/cpp/actors/core/actor.h index 7a414bad1c..ed29bd14b9 100644 --- a/library/cpp/actors/core/actor.h +++ b/library/cpp/actors/core/actor.h @@ -6,7 +6,7 @@ #include <library/cpp/actors/util/local_process_key.h> namespace NActors { - class TActorSystem; + class TActorSystem; class TMailboxTable; struct TMailboxHeader; @@ -169,11 +169,11 @@ namespace NActors { void Schedule(TDuration delta, IEventBase* ev, ISchedulerCookie* cookie = nullptr) const; }; - class IActor; - - class IActorOps : TNonCopyable { + class IActor; + + class IActorOps : TNonCopyable { public: - virtual void Describe(IOutputStream&) const noexcept = 0; + virtual void Describe(IOutputStream&) const noexcept = 0; virtual bool Send(const TActorId& recipient, IEventBase*, ui32 flags = 0, ui64 cookie = 0, NWilson::TTraceId traceId = {}) const noexcept = 0; /** @@ -205,12 +205,12 @@ namespace NActors { virtual TActorId Register(IActor*, TMailboxType::EType mailboxType = TMailboxType::HTSwap, ui32 poolId = Max<ui32>()) const noexcept = 0; virtual TActorId RegisterWithSameMailbox(IActor*) const noexcept = 0; - }; - + }; + class TDecorator; - class IActor : protected IActorOps { - public: + class IActor : protected IActorOps { + public: typedef void (IActor::*TReceiveFunc)(TAutoPtr<IEventHandle>& ev, const TActorContext& ctx); private: @@ -324,7 +324,7 @@ namespace NActors { } virtual void Registered(TActorSystem* sys, const TActorId& owner); - + virtual TAutoPtr<IEventHandle> AfterRegister(const TActorId& self, const TActorId& parentId) { Y_UNUSED(self); Y_UNUSED(parentId); @@ -349,7 +349,7 @@ namespace NActors { } protected: - void Describe(IOutputStream&) const noexcept override; + void Describe(IOutputStream&) const noexcept override; bool Send(const TActorId& recipient, IEventBase* ev, ui32 flags = 0, ui64 cookie = 0, NWilson::TTraceId traceId = {}) const noexcept final; template <typename TEvent> bool Send(const TActorId& recipient, THolder<TEvent> ev, ui32 flags = 0, ui64 cookie = 0, NWilson::TTraceId traceId = {}) const{ @@ -363,7 +363,7 @@ namespace NActors { void Schedule(TInstant deadline, IEventBase* ev, ISchedulerCookie* cookie = nullptr) const noexcept final; void Schedule(TMonotonic deadline, IEventBase* ev, ISchedulerCookie* cookie = nullptr) const noexcept final; - void Schedule(TDuration delta, IEventBase* ev, ISchedulerCookie* cookie = nullptr) const noexcept final; + void Schedule(TDuration delta, IEventBase* ev, ISchedulerCookie* cookie = nullptr) const noexcept final; // register new actor in ActorSystem on new fresh mailbox. TActorId Register(IActor* actor, TMailboxType::EType mailboxType = TMailboxType::HTSwap, ui32 poolId = Max<ui32>()) const noexcept final; diff --git a/library/cpp/actors/core/event.h b/library/cpp/actors/core/event.h index 745bbd28f4..6ff02aaf94 100644 --- a/library/cpp/actors/core/event.h +++ b/library/cpp/actors/core/event.h @@ -59,11 +59,11 @@ namespace NActors { public: template <typename TEv> inline TEv* CastAsLocal() const noexcept { - auto fits = GetTypeRewrite() == TEv::EventType; - - return fits ? static_cast<TEv*>(Event.Get()) : nullptr; - } - + auto fits = GetTypeRewrite() == TEv::EventType; + + return fits ? static_cast<TEv*>(Event.Get()) : nullptr; + } + template <typename TEventType> TEventType* Get() { if (Type != TEventType::EventType) diff --git a/library/cpp/actors/core/events.h b/library/cpp/actors/core/events.h index 984cb51523..702cf50fad 100644 --- a/library/cpp/actors/core/events.h +++ b/library/cpp/actors/core/events.h @@ -85,23 +85,23 @@ namespace NActors { Unsubscribe, // generic unsubscribe from something Delivered, // event delivered Undelivered, // event undelivered - Poison, // request actor to shutdown + Poison, // request actor to shutdown Completed, // generic async job result event - PoisonTaken, // generic Poison taken (reply to PoisonPill event, i.e. died completely) + PoisonTaken, // generic Poison taken (reply to PoisonPill event, i.e. died completely) FlushLog, CallbackCompletion, CallbackException, - Gone, // Generic notification of actor death + Gone, // Generic notification of actor death TrackActor, UntrackActor, InvokeResult, CoroTimeout, InvokeQuery, - End, - + End, + // Compatibility section - PoisonPill = Poison, - ActorDied = Gone, + PoisonPill = Poison, + ActorDied = Gone, }; static_assert(End < EventSpaceEnd(ES_SYSTEM), "expect End < EventSpaceEnd(ES_SYSTEM)"); @@ -111,16 +111,16 @@ namespace NActors { DEFINE_SIMPLE_LOCAL_EVENT(TEvBootstrap, "System: TEvBootstrap") }; - struct TEvPoison : public TEventBase<TEvPoison, TSystem::Poison> { - DEFINE_SIMPLE_NONLOCAL_EVENT(TEvPoison, "System: TEvPoison") + struct TEvPoison : public TEventBase<TEvPoison, TSystem::Poison> { + DEFINE_SIMPLE_NONLOCAL_EVENT(TEvPoison, "System: TEvPoison") }; struct TEvWakeup: public TEventBase<TEvWakeup, TSystem::Wakeup> { DEFINE_SIMPLE_LOCAL_EVENT(TEvWakeup, "System: TEvWakeup") - - TEvWakeup(ui64 tag = 0) : Tag(tag) { } - - const ui64 Tag = 0; + + TEvWakeup(ui64 tag = 0) : Tag(tag) { } + + const ui64 Tag = 0; }; struct TEvSubscribe: public TEventBase<TEvSubscribe, TSystem::Subscribe> { @@ -205,14 +205,14 @@ namespace NActors { } }; - struct TEvGone: public TEventBase<TEvGone, TSystem::Gone> { - DEFINE_SIMPLE_LOCAL_EVENT(TEvGone, "System: TEvGone") + struct TEvGone: public TEventBase<TEvGone, TSystem::Gone> { + DEFINE_SIMPLE_LOCAL_EVENT(TEvGone, "System: TEvGone") }; - + struct TEvInvokeResult; - using TEvPoisonPill = TEvPoison; // Legacy name, deprecated - using TEvActorDied = TEvGone; + using TEvPoisonPill = TEvPoison; // Legacy name, deprecated + using TEvActorDied = TEvGone; }; } diff --git a/library/cpp/actors/core/executor_pool_base.cpp b/library/cpp/actors/core/executor_pool_base.cpp index 1fb66adc61..c3b9999168 100644 --- a/library/cpp/actors/core/executor_pool_base.cpp +++ b/library/cpp/actors/core/executor_pool_base.cpp @@ -8,8 +8,8 @@ namespace NActors { LWTRACE_USING(ACTORLIB_PROVIDER); void DoActorInit(TActorSystem* sys, IActor* actor, const TActorId& self, const TActorId& owner) { - actor->SelfActorId = self; - actor->Registered(sys, owner); + actor->SelfActorId = self; + actor->Registered(sys, owner); } TExecutorPoolBaseMailboxed::TExecutorPoolBaseMailboxed(ui32 poolId, ui32 maxActivityType) @@ -98,7 +98,7 @@ namespace NActors { // do init const TActorId actorId(ActorSystem->NodeId, PoolId, localActorId, hint); - DoActorInit(ActorSystem, actor, actorId, parentId); + DoActorInit(ActorSystem, actor, actorId, parentId); // Once we unlock the mailbox the actor starts running and we cannot use the pointer any more actor = nullptr; @@ -145,7 +145,7 @@ namespace NActors { mailbox->AttachActor(localActorId, actor); const TActorId actorId(ActorSystem->NodeId, PoolId, localActorId, hint); - DoActorInit(ActorSystem, actor, actorId, parentId); + DoActorInit(ActorSystem, actor, actorId, parentId); NHPTimer::STime elapsed = GetCycleCountFast() - hpstart; if (elapsed > 1000000) { LWPROBE(SlowRegisterAdd, PoolId, NHPTimer::GetSeconds(elapsed) * 1000.0); diff --git a/library/cpp/actors/core/executor_thread.cpp b/library/cpp/actors/core/executor_thread.cpp index 7a34944ae2..446b651efd 100644 --- a/library/cpp/actors/core/executor_thread.cpp +++ b/library/cpp/actors/core/executor_thread.cpp @@ -67,10 +67,10 @@ namespace NActors { DyingActors.push_back(THolder(actor)); } - void TExecutorThread::DropUnregistered() { - DyingActors.clear(); // here is actual destruction of actors - } - + void TExecutorThread::DropUnregistered() { + DyingActors.clear(); // here is actual destruction of actors + } + void TExecutorThread::Schedule(TInstant deadline, TAutoPtr<IEventHandle> ev, ISchedulerCookie* cookie) { ++CurrentActorScheduledEventsCounter; Ctx.Executor->Schedule(deadline, ev, cookie, Ctx.WorkerId); @@ -181,7 +181,7 @@ namespace NActors { size_t dyingActorsCnt = DyingActors.size(); Ctx.UpdateActorsStats(dyingActorsCnt); if (dyingActorsCnt) { - DropUnregistered(); + DropUnregistered(); actor = nullptr; } diff --git a/library/cpp/actors/core/executor_thread.h b/library/cpp/actors/core/executor_thread.h index a1ef9786f6..9d3c573f0d 100644 --- a/library/cpp/actors/core/executor_thread.h +++ b/library/cpp/actors/core/executor_thread.h @@ -43,7 +43,7 @@ namespace NActors { const TActorId& parentId = TActorId()); TActorId RegisterActor(IActor* actor, TMailboxHeader* mailbox, ui32 hint, const TActorId& parentId = TActorId()); void UnregisterActor(TMailboxHeader* mailbox, ui64 localActorId); - void DropUnregistered(); + void DropUnregistered(); const std::vector<THolder<IActor>>& GetUnregistered() const { return DyingActors; } void Schedule(TInstant deadline, TAutoPtr<IEventHandle> ev, ISchedulerCookie* cookie = nullptr); diff --git a/library/cpp/actors/core/log.cpp b/library/cpp/actors/core/log.cpp index ca0c6e60ea..5f63b5af58 100644 --- a/library/cpp/actors/core/log.cpp +++ b/library/cpp/actors/core/log.cpp @@ -251,11 +251,11 @@ namespace NActors { const auto prio = ev.Level.ToPrio(); - switch (prio) { - case ::NActors::NLog::EPrio::Alert: + switch (prio) { + case ::NActors::NLog::EPrio::Alert: Metrics->IncAlertMsgs(); break; - case ::NActors::NLog::EPrio::Emerg: + case ::NActors::NLog::EPrio::Emerg: Metrics->IncEmergMsgs(); break; default: @@ -344,10 +344,10 @@ namespace NActors { str << "<a href='logger?c=" << i << "'>" << name << "</a>"; } TABLED() { - str << PriorityToString(EPrio(componentSettings.Raw.X.Level)); + str << PriorityToString(EPrio(componentSettings.Raw.X.Level)); } TABLED() { - str << PriorityToString(EPrio(componentSettings.Raw.X.SamplingLevel)); + str << PriorityToString(EPrio(componentSettings.Raw.X.SamplingLevel)); } TABLED() { str << componentSettings.Raw.X.SamplingRate; @@ -421,11 +421,11 @@ namespace NActors { UL() { LI() { str << "Priority: " - << NLog::PriorityToString(NLog::EPrio(componentSettings.Raw.X.Level)); + << NLog::PriorityToString(NLog::EPrio(componentSettings.Raw.X.Level)); } LI() { str << "Sampling priority: " - << NLog::PriorityToString(NLog::EPrio(componentSettings.Raw.X.SamplingLevel)); + << NLog::PriorityToString(NLog::EPrio(componentSettings.Raw.X.SamplingLevel)); } LI() { str << "Sampling rate: " @@ -444,7 +444,7 @@ namespace NActors { for (int p = NLog::PRI_EMERG; p <= NLog::PRI_TRACE; ++p) { LI() { str << "<a href='logger?c=" << component << "&p=" << p << "'>" - << NLog::PriorityToString(NLog::EPrio(p)) << "</a>"; + << NLog::PriorityToString(NLog::EPrio(p)) << "</a>"; } } } @@ -455,7 +455,7 @@ namespace NActors { for (int p = NLog::PRI_EMERG; p <= NLog::PRI_TRACE; ++p) { LI() { str << "<a href='logger?c=" << component << "&sp=" << p << "'>" - << NLog::PriorityToString(NLog::EPrio(p)) << "</a>"; + << NLog::PriorityToString(NLog::EPrio(p)) << "</a>"; } } } @@ -519,7 +519,7 @@ namespace NActors { TABLER() { TABLED() { str << "<a href = 'logger?c=-1&p=" << p << "'>" - << NLog::PriorityToString(NLog::EPrio(p)) << "</a>"; + << NLog::PriorityToString(NLog::EPrio(p)) << "</a>"; } } } @@ -541,7 +541,7 @@ namespace NActors { TABLER() { TABLED() { str << "<a href = 'logger?c=-1&sp=" << p << "'>" - << NLog::PriorityToString(NLog::EPrio(p)) << "</a>"; + << NLog::PriorityToString(NLog::EPrio(p)) << "</a>"; } } } @@ -576,8 +576,8 @@ namespace NActors { bool TLoggerActor::OutputRecord(TInstant time, NLog::EPrio priority, NLog::EComponent component, const TString& formatted) noexcept try { - const auto logPrio = ::ELogPriority(ui16(priority)); - + const auto logPrio = ::ELogPriority(ui16(priority)); + char buf[TimeBufSize]; switch (Settings->Format) { case NActors::NLog::TSettings::PLAIN_FULL_FORMAT: { diff --git a/library/cpp/actors/core/log.h b/library/cpp/actors/core/log.h index 65e75b9909..c11a7cf3c1 100644 --- a/library/cpp/actors/core/log.h +++ b/library/cpp/actors/core/log.h @@ -2,7 +2,7 @@ #include "defs.h" -#include "log_iface.h" +#include "log_iface.h" #include "log_settings.h" #include "actorsystem.h" #include "events.h" @@ -122,7 +122,7 @@ namespace NActors { //////////////////////////////////////////////////////////////////////////////// // SET LOG LEVEL FOR A COMPONENT //////////////////////////////////////////////////////////////////////////////// - class TLogComponentLevelRequest: public TEventLocal<TLogComponentLevelRequest, int(NLog::EEv::LevelReq)> { + class TLogComponentLevelRequest: public TEventLocal<TLogComponentLevelRequest, int(NLog::EEv::LevelReq)> { public: // set given priority for the component TLogComponentLevelRequest(NLog::EPriority priority, NLog::EComponent component) @@ -145,7 +145,7 @@ namespace NActors { friend class TLoggerActor; }; - class TLogComponentLevelResponse: public TEventLocal<TLogComponentLevelResponse, int(NLog::EEv::LevelResp)> { + class TLogComponentLevelResponse: public TEventLocal<TLogComponentLevelResponse, int(NLog::EEv::LevelResp)> { public: TLogComponentLevelResponse(int code, const TString& explanation) : Code(code) @@ -166,7 +166,7 @@ namespace NActors { TString Explanation; }; - class TLogIgnored: public TEventLocal<TLogIgnored, int(NLog::EEv::Ignored)> { + class TLogIgnored: public TEventLocal<TLogIgnored, int(NLog::EEv::Ignored)> { public: TLogIgnored() { } @@ -213,7 +213,7 @@ namespace NActors { void StateFunc(TAutoPtr<IEventHandle>& ev, const TActorContext& ctx) { switch (ev->GetTypeRewrite()) { HFunc(TLogIgnored, HandleIgnoredEvent); - HFunc(NLog::TEvLog, HandleLogEvent); + HFunc(NLog::TEvLog, HandleLogEvent); HFunc(TLogComponentLevelRequest, HandleLogComponentLevelRequest); HFunc(NMon::TEvHttpInfo, HandleMonInfo); } @@ -246,7 +246,7 @@ namespace NActors { void BecomeDefunct(); void HandleIgnoredEvent(TLogIgnored::TPtr& ev, const NActors::TActorContext& ctx); void HandleIgnoredEventDrop(); - void HandleLogEvent(NLog::TEvLog::TPtr& ev, const TActorContext& ctx); + void HandleLogEvent(NLog::TEvLog::TPtr& ev, const TActorContext& ctx); void HandleLogEventDrop(const NLog::TEvLog::TPtr& ev); void HandleLogComponentLevelRequest(TLogComponentLevelRequest::TPtr& ev, const TActorContext& ctx); void HandleMonInfo(NMon::TEvHttpInfo::TPtr& ev, const TActorContext& ctx); diff --git a/library/cpp/actors/core/log_iface.h b/library/cpp/actors/core/log_iface.h index 0ca9c14b91..b331db9ca8 100644 --- a/library/cpp/actors/core/log_iface.h +++ b/library/cpp/actors/core/log_iface.h @@ -1,12 +1,12 @@ -#pragma once - -#include "events.h" -#include "event_local.h" - -namespace NActors { +#pragma once + +#include "events.h" +#include "event_local.h" + +namespace NActors { namespace NLog { using EComponent = int; - + enum EPriority : ui16 { // migrate it to EPrio whenever possible PRI_EMERG, PRI_ALERT, @@ -18,7 +18,7 @@ namespace NActors { PRI_DEBUG, PRI_TRACE }; - + enum class EPrio : ui16 { Emerg = 0, Alert = 1, @@ -30,39 +30,39 @@ namespace NActors { Debug = 7, Trace = 8, }; - + struct TLevel { TLevel(ui32 raw) : Raw(raw) { } - + TLevel(EPrio prio) : Raw((ui16(prio) + 1) << 8) { } - + EPrio ToPrio() const noexcept { const auto major = Raw >> 8; - + return major > 0 ? EPrio(major - 1) : EPrio::Emerg; } - + bool IsUrgentAbortion() const noexcept { return (Raw >> 8) == 0; } - + /* Generalized monotonic level value composed with major and minor - levels. Minor is used for verbosity within major, basic EPrio - mapped to (EPrio + 1, 0) and Major = 0 is reserved as special - space with meaning like EPrio::Emerg but with extened actions. - Thus logger should map Major = 0 to EPrio::Emerg if it have no - idea how to handle special emergency actions. - */ - + levels. Minor is used for verbosity within major, basic EPrio + mapped to (EPrio + 1, 0) and Major = 0 is reserved as special + space with meaning like EPrio::Emerg but with extened actions. + Thus logger should map Major = 0 to EPrio::Emerg if it have no + idea how to handle special emergency actions. + */ + ui32 Raw = 0; // ((ui16(EPrio) + 1) << 8) | ui8(minor) }; - + enum class EEv { Log = EventSpaceBegin(TEvents::ES_LOGGER), LevelReq, @@ -70,9 +70,9 @@ namespace NActors { Ignored, End }; - + static_assert(int(EEv::End) < EventSpaceEnd(TEvents::ES_LOGGER), ""); - + class TEvLog: public TEventLocal<TEvLog, int(EEv::Log)> { public: TEvLog(TInstant stamp, TLevel level, EComponent comp, const TString &line) @@ -90,7 +90,7 @@ namespace NActors { , Line(std::move(line)) { } - + TEvLog(EPriority prio, EComponent comp, TString line, TInstant time = TInstant::Now()) : Stamp(time) , Level(EPrio(prio)) @@ -98,12 +98,12 @@ namespace NActors { , Line(std::move(line)) { } - + const TInstant Stamp = TInstant::Max(); const TLevel Level; const EComponent Component = 0; TString Line; }; - + } -} +} diff --git a/library/cpp/actors/core/log_settings.cpp b/library/cpp/actors/core/log_settings.cpp index 5a5b66b4ac..f52f2fc5d2 100644 --- a/library/cpp/actors/core/log_settings.cpp +++ b/library/cpp/actors/core/log_settings.cpp @@ -116,7 +116,7 @@ namespace NActors { str << titleName << " for all components has been changed to " - << PriorityToString(EPrio(priority)); + << PriorityToString(EPrio(priority)); explanation = str.Str(); return 0; } else { @@ -136,8 +136,8 @@ namespace NActors { AtomicSet(ComponentInfo[component], settings.Raw.Data); TStringStream str; str << titleName << " for the component " << ComponentNames[component] - << " has been changed from " << PriorityToString(EPrio(oldPriority)) - << " to " << PriorityToString(EPrio(priority)); + << " has been changed from " << PriorityToString(EPrio(oldPriority)) + << " to " << PriorityToString(EPrio(priority)); explanation = str.Str(); return 0; } diff --git a/library/cpp/actors/core/log_settings.h b/library/cpp/actors/core/log_settings.h index 7f9ea16553..7fe4504edd 100644 --- a/library/cpp/actors/core/log_settings.h +++ b/library/cpp/actors/core/log_settings.h @@ -1,32 +1,32 @@ #pragma once #include "actor.h" -#include "log_iface.h" +#include "log_iface.h" #include <util/generic/vector.h> #include <util/digest/murmur.h> #include <util/random/easy.h> namespace NActors { namespace NLog { - inline const char* PriorityToString(EPrio priority) { + inline const char* PriorityToString(EPrio priority) { switch (priority) { - case EPrio::Emerg: + case EPrio::Emerg: return "EMERG"; - case EPrio::Alert: + case EPrio::Alert: return "ALERT"; - case EPrio::Crit: + case EPrio::Crit: return "CRIT"; - case EPrio::Error: + case EPrio::Error: return "ERROR"; - case EPrio::Warn: + case EPrio::Warn: return "WARN"; - case EPrio::Notice: + case EPrio::Notice: return "NOTICE"; - case EPrio::Info: + case EPrio::Info: return "INFO"; - case EPrio::Debug: + case EPrio::Debug: return "DEBUG"; - case EPrio::Trace: + case EPrio::Trace: return "TRACE"; default: return "UNKNOWN"; diff --git a/library/cpp/actors/dnscachelib/dnscache.cpp b/library/cpp/actors/dnscachelib/dnscache.cpp index c966fd7b13..649339ddb2 100644 --- a/library/cpp/actors/dnscachelib/dnscache.cpp +++ b/library/cpp/actors/dnscachelib/dnscache.cpp @@ -7,7 +7,7 @@ #include <util/datetime/systime.h> const TDnsCache::THost TDnsCache::NullHost; - + LWTRACE_USING(DNSCACHELIB_PROVIDER); static_assert(sizeof(ares_channel) == sizeof(void*), "expect sizeof(ares_channel) == sizeof(void *)"); @@ -22,7 +22,7 @@ TDnsCache::TDnsCache(bool allowIpv4, bool allowIpv6, time_t lifetime, time_t neg , ACacheMisses(0) , PtrCacheHits(0) , PtrCacheMisses(0) -{ +{ #ifdef _win_ if (ares_library_init(ARES_LIB_INIT_WIN32) != ARES_SUCCESS) { LWPROBE(AresInitFailed); @@ -53,97 +53,97 @@ TDnsCache::~TDnsCache(void) { } TString TDnsCache::GetHostByAddr(const NAddr::IRemoteAddr& addr) { - in6_addr key; - - if (addr.Addr()->sa_family == AF_INET6) { + in6_addr key; + + if (addr.Addr()->sa_family == AF_INET6) { const struct sockaddr_in6* s6 = (const struct sockaddr_in6*)(addr.Addr()); - memcpy(&key, &s6->sin6_addr, sizeof(s6->sin6_addr)); - } else if (addr.Addr()->sa_family == AF_INET) { + memcpy(&key, &s6->sin6_addr, sizeof(s6->sin6_addr)); + } else if (addr.Addr()->sa_family == AF_INET) { const struct sockaddr_in* s4 = (const struct sockaddr_in*)(addr.Addr()); - memset(&key, 0, sizeof(key)); - memcpy(&key, &s4->sin_addr, sizeof(s4->sin_addr)); - } else { - return ""; - } + memset(&key, 0, sizeof(key)); + memcpy(&key, &s4->sin_addr, sizeof(s4->sin_addr)); + } else { + return ""; + } const TAddr& host = ResolveAddr(key, addr.Addr()->sa_family); - - return host.Hostname; -} - + + return host.Hostname; +} + TIpHost TDnsCache::Get(const TString& hostname) { - if (!AllowIpV4) - return TIpHost(-1); - + if (!AllowIpV4) + return TIpHost(-1); + const THost& addr = Resolve(hostname, AF_INET); - + TGuard<TMutex> lock(CacheMtx); - if (addr.AddrsV4.empty()) { - return TIpHost(-1); - } - return addr.AddrsV4.front(); -} - -NAddr::IRemoteAddrPtr TDnsCache::GetAddr( + if (addr.AddrsV4.empty()) { + return TIpHost(-1); + } + return addr.AddrsV4.front(); +} + +NAddr::IRemoteAddrPtr TDnsCache::GetAddr( const TString& hostname, int family, TIpPort port, bool cacheOnly) { - if (family != AF_INET && AllowIpV6) { + if (family != AF_INET && AllowIpV6) { const THost& addr = Resolve(hostname, AF_INET6, cacheOnly); - + TGuard<TMutex> lock(CacheMtx); - if (!addr.AddrsV6.empty()) { - struct sockaddr_in6 sin6; - Zero(sin6); - sin6.sin6_family = AF_INET6; - sin6.sin6_addr = addr.AddrsV6.front(); - sin6.sin6_port = HostToInet(port); - + if (!addr.AddrsV6.empty()) { + struct sockaddr_in6 sin6; + Zero(sin6); + sin6.sin6_family = AF_INET6; + sin6.sin6_addr = addr.AddrsV6.front(); + sin6.sin6_port = HostToInet(port); + return MakeHolder<NAddr::TIPv6Addr>(sin6); - } - } - - if (family != AF_INET6 && AllowIpV4) { + } + } + + if (family != AF_INET6 && AllowIpV4) { const THost& addr = Resolve(hostname, AF_INET, cacheOnly); - + TGuard<TMutex> lock(CacheMtx); - if (!addr.AddrsV4.empty()) { + if (!addr.AddrsV4.empty()) { return MakeHolder<NAddr::TIPv4Addr>(TIpAddress(addr.AddrsV4.front(), port)); - } - } - + } + } + LWPROBE(FamilyMismatch, family, AllowIpV4, AllowIpV6); return nullptr; -} - -void TDnsCache::GetAllAddresses( +} + +void TDnsCache::GetAllAddresses( const TString& hostname, TVector<NAddr::IRemoteAddrPtr>& addrs) { - if (AllowIpV4) { + if (AllowIpV4) { const THost& addr4 = Resolve(hostname, AF_INET); TGuard<TMutex> lock(CacheMtx); - for (size_t i = 0; i < addr4.AddrsV4.size(); i++) { + for (size_t i = 0; i < addr4.AddrsV4.size(); i++) { addrs.push_back(MakeHolder<NAddr::TIPv4Addr>(TIpAddress(addr4.AddrsV4[i], 0))); - } - } - - if (AllowIpV6) { + } + } + + if (AllowIpV6) { const THost& addr6 = Resolve(hostname, AF_INET6); - struct sockaddr_in6 sin6; - Zero(sin6); - sin6.sin6_family = AF_INET6; + struct sockaddr_in6 sin6; + Zero(sin6); + sin6.sin6_family = AF_INET6; TGuard<TMutex> lock(CacheMtx); - for (size_t i = 0; i < addr6.AddrsV6.size(); i++) { - sin6.sin6_addr = addr6.AddrsV6[i]; - + for (size_t i = 0; i < addr6.AddrsV6.size(); i++) { + sin6.sin6_addr = addr6.AddrsV6[i]; + addrs.push_back(MakeHolder<NAddr::TIPv6Addr>(sin6)); - } - } -} - + } + } +} + void TDnsCache::GetStats(ui64& a_cache_hits, ui64& a_cache_misses, ui64& ptr_cache_hits, ui64& ptr_cache_misses) { TGuard<TMutex> lock(CacheMtx); @@ -169,11 +169,11 @@ bool TDnsCache::THost::IsStale(int family, const TDnsCache* ctx) const noexcept const TDnsCache::THost& TDnsCache::Resolve(const TString& hostname, int family, bool cacheOnly) { - if (!ValidateHName(hostname)) { + if (!ValidateHName(hostname)) { LWPROBE(ResolveNullHost, hostname, family); - return NullHost; - } - + return NullHost; + } + THostCache::iterator p; Y_ASSERT(family == AF_INET || family == AF_INET6); @@ -232,9 +232,9 @@ TDnsCache::Resolve(const TString& hostname, int family, bool cacheOnly) { } bool TDnsCache::ValidateHName(const TString& name) const noexcept { - return name.size() > 0; -} - + return name.size() > 0; +} + const TDnsCache::TAddr& TDnsCache::ResolveAddr(const in6_addr& addr, int family) { TAddrCache::iterator p; @@ -282,7 +282,7 @@ const TDnsCache::TAddr& TDnsCache::ResolveAddr(const in6_addr& addr, int family) } void TDnsCache::WaitTask(TAtomic& flag) { - const TInstant start = TInstant(TTimeKeeper::GetTimeval()); + const TInstant start = TInstant(TTimeKeeper::GetTimeval()); while (AtomicGet(flag)) { ares_channel chan = static_cast<ares_channel>(Channel); @@ -319,11 +319,11 @@ void TDnsCache::WaitTask(TAtomic& flag) { Y_ASSERT(nfds != 0); - const TDuration left = TInstant(TTimeKeeper::GetTimeval()) - start; - const TDuration wait = Max(Timeout - left, TDuration::Zero()); - - int rv = poll(pfd, nfds, wait.MilliSeconds()); - + const TDuration left = TInstant(TTimeKeeper::GetTimeval()) - start; + const TDuration wait = Max(Timeout - left, TDuration::Zero()); + + int rv = poll(pfd, nfds, wait.MilliSeconds()); + if (rv == -1) { if (errno == EINTR) { continue; @@ -351,10 +351,10 @@ void TDnsCache::WaitTask(TAtomic& flag) { : ARES_SOCKET_BAD); } } - - if (start + Timeout <= TInstant(TTimeKeeper::GetTimeval())) { - break; - } + + if (start + Timeout <= TInstant(TTimeKeeper::GetTimeval())) { + break; + } } } diff --git a/library/cpp/actors/dnscachelib/dnscache.h b/library/cpp/actors/dnscachelib/dnscache.h index 2d6adb3a36..3313a251a1 100644 --- a/library/cpp/actors/dnscachelib/dnscache.h +++ b/library/cpp/actors/dnscachelib/dnscache.h @@ -5,7 +5,7 @@ #include <util/generic/vector.h> #include <util/network/address.h> #include <util/system/mutex.h> -#include <util/datetime/base.h> +#include <util/datetime/base.h> /** Asynchronous DNS resolver. * @@ -19,7 +19,7 @@ class TDnsCache { public: TDnsCache(bool allowIpv4 = true, bool allowIpv6 = true, time_t entry_lifetime = 1800, time_t neg_lifetime = 1, ui32 request_timeout = 500000); - ~TDnsCache(); + ~TDnsCache(); TString GetHostByAddr(const NAddr::IRemoteAddr&); @@ -37,9 +37,9 @@ public: void GetStats(ui64& a_cache_hits, ui64& a_cache_misses, ui64& ptr_cache_hits, ui64& ptr_cache_misses); -protected: +protected: bool ValidateHName(const TString& host) const noexcept; - + private: struct TGHBNContext { TDnsCache* Owner; @@ -52,7 +52,7 @@ private: in6_addr Addr; }; - struct THost { + struct THost { THost() noexcept { } @@ -73,8 +73,8 @@ private: }; typedef TMap<TString, THost> THostCache; - - struct TAddr { + + struct TAddr { TString Hostname; time_t Resolved = 0; time_t NotFound = 0; @@ -112,7 +112,7 @@ private: const time_t EntryLifetime; const time_t NegativeLifetime; - const TDuration Timeout; + const TDuration Timeout; const bool AllowIpV4; const bool AllowIpV6; @@ -124,8 +124,8 @@ private: ui64 PtrCacheHits; ui64 PtrCacheMisses; - const static THost NullHost; - + const static THost NullHost; + TMutex AresMtx; void* Channel; diff --git a/library/cpp/actors/testlib/test_runtime.cpp b/library/cpp/actors/testlib/test_runtime.cpp index 7c4871399d..6fa25b9965 100644 --- a/library/cpp/actors/testlib/test_runtime.cpp +++ b/library/cpp/actors/testlib/test_runtime.cpp @@ -1,4 +1,4 @@ -#include "test_runtime.h" +#include "test_runtime.h" #include <library/cpp/actors/core/actor_bootstrapped.h> #include <library/cpp/actors/core/callstack.h> @@ -22,16 +22,16 @@ bool VERBOSE = false; const bool PRINT_EVENT_BODY = false; -namespace { +namespace { + + TString MakeClusterId() { + pid_t pid = getpid(); + TStringBuilder uuid; + uuid << "Cluster for process with id: " << pid; + return uuid; + } +} - TString MakeClusterId() { - pid_t pid = getpid(); - TStringBuilder uuid; - uuid << "Cluster for process with id: " << pid; - return uuid; - } -} - namespace NActors { ui64 TScheduledEventQueueItem::NextUniqueId = 0; @@ -80,7 +80,7 @@ namespace NActors { TTestActorRuntimeBase::TNodeDataBase::~TNodeDataBase() { Stop(); } - + class TTestActorRuntimeBase::TEdgeActor : public TActor<TEdgeActor> { public: @@ -326,7 +326,7 @@ namespace NActors { } TDuration delay = (deadline - now); - if (Runtime->SingleSysEnv || !Runtime->ScheduledEventFilterFunc(*Runtime, ev, delay, deadline)) { + if (Runtime->SingleSysEnv || !Runtime->ScheduledEventFilterFunc(*Runtime, ev, delay, deadline)) { ui32 mailboxHint = ev->GetRecipientRewrite().Hint(); Runtime->GetMailbox(Runtime->FirstNodeId + NodeIndex, mailboxHint).Schedule(TScheduledEventQueueItem(deadline, ev, cookie)); Runtime->MailboxesHasEvents.Signal(); @@ -365,7 +365,7 @@ namespace NActors { } ui32 mailboxHint = ev->GetRecipientRewrite().Hint(); - if (ev->GetTypeRewrite() == ui32(NActors::NLog::EEv::Log)) { + if (ev->GetTypeRewrite() == ui32(NActors::NLog::EEv::Log)) { const NActors::TActorId loggerActorId = NActors::TActorId(nodeId, "logger"); TActorId logger = node->ActorSystem->LookupLocalService(loggerActorId); if (ev->GetRecipientRewrite() == logger) { @@ -451,15 +451,15 @@ namespace NActors { TTestActorRuntimeBase::TTestActorRuntimeBase(THeSingleSystemEnv) : TTestActorRuntimeBase(1, 1, false) - { - SingleSysEnv = true; - } - + { + SingleSysEnv = true; + } + TTestActorRuntimeBase::TTestActorRuntimeBase(ui32 nodeCount, ui32 dataCenterCount, bool useRealThreads) : ScheduledCount(0) , ScheduledLimit(100000) , MainThreadId(TThread::CurrentThreadId()) - , ClusterUUID(MakeClusterId()) + , ClusterUUID(MakeClusterId()) , FirstNodeId(NextNodeId) , NodeCount(nodeCount) , DataCenterCount(dataCenterCount) @@ -741,7 +741,7 @@ namespace NActors { void TTestActorRuntimeBase::InitNodes() { NextNodeId += NodeCount; Y_VERIFY(NodeCount > 0); - + for (ui32 nodeIndex = 0; nodeIndex < NodeCount; ++nodeIndex) { auto nodeIt = Nodes.emplace(FirstNodeId + nodeIndex, GetNodeFactory().CreateNode()).first; TNodeDataBase* node = nodeIt->second.Get(); @@ -900,7 +900,7 @@ namespace NActors { const TActorId actorId(FirstNodeId + nodeIndex, poolId, localActorId, hint); ActorNames[actorId] = TypeName(*actor); RegistrationObserver(*this, parentId ? parentId : CurrentRecipient, actorId); - DoActorInit(node->ActorSystem.Get(), actor, actorId, parentId ? parentId : CurrentRecipient); + DoActorInit(node->ActorSystem.Get(), actor, actorId, parentId ? parentId : CurrentRecipient); switch (mailboxType) { case TMailboxType::Simple: @@ -944,7 +944,7 @@ namespace NActors { const TActorId actorId(FirstNodeId + nodeIndex, poolId, localActorId, hint); ActorNames[actorId] = TypeName(*actor); RegistrationObserver(*this, parentId ? parentId : CurrentRecipient, actorId); - DoActorInit(node->ActorSystem.Get(), actor, actorId, parentId ? parentId : CurrentRecipient); + DoActorInit(node->ActorSystem.Get(), actor, actorId, parentId ? parentId : CurrentRecipient); return actorId; } @@ -1583,7 +1583,7 @@ namespace NActors { TCallstack::GetTlsCallstack().SetLinesToSkip(); #endif recipientActor->Receive(evHolder, ctx); - node->ExecutorThread->DropUnregistered(); + node->ExecutorThread->DropUnregistered(); } CurrentRecipient = TActorId(); TlsActivationContext = prevTlsActivationContext; @@ -1683,24 +1683,24 @@ namespace NActors { NActors::TMailboxType::Simple, InterconnectPoolId())); } - if (!SingleSysEnv) { // Single system env should do this self - TAutoPtr<TLogBackend> logBackend = LogBackend ? LogBackend : NActors::CreateStderrBackend(); - NActors::TLoggerActor *loggerActor = new NActors::TLoggerActor(node->LogSettings, + if (!SingleSysEnv) { // Single system env should do this self + TAutoPtr<TLogBackend> logBackend = LogBackend ? LogBackend : NActors::CreateStderrBackend(); + NActors::TLoggerActor *loggerActor = new NActors::TLoggerActor(node->LogSettings, logBackend, GetCountersForComponent(node->DynamicCounters, "utils")); NActors::TActorSetupCmd loggerActorCmd(loggerActor, NActors::TMailboxType::Simple, node->GetLoggerPoolId()); std::pair<NActors::TActorId, NActors::TActorSetupCmd> loggerActorPair(node->LogSettings->LoggerActorId, loggerActorCmd); - setup->LocalServices.push_back(loggerActorPair); - } + setup->LocalServices.push_back(loggerActorPair); + } return THolder<TActorSystem>(new TActorSystem(setup, node->GetAppData(), node->LogSettings)); } TActorSystem* TTestActorRuntimeBase::SingleSys() const { - Y_VERIFY(Nodes.size() == 1, "Works only for single system env"); - - return Nodes.begin()->second->ActorSystem.Get(); - } - + Y_VERIFY(Nodes.size() == 1, "Works only for single system env"); + + return Nodes.begin()->second->ActorSystem.Get(); + } + TActorSystem* TTestActorRuntimeBase::GetAnyNodeActorSystem() { for (auto& x : Nodes) { return x.second->ActorSystem.Get(); diff --git a/library/cpp/actors/testlib/test_runtime.h b/library/cpp/actors/testlib/test_runtime.h index 38e964835c..26e3b45c98 100644 --- a/library/cpp/actors/testlib/test_runtime.h +++ b/library/cpp/actors/testlib/test_runtime.h @@ -39,8 +39,8 @@ const TDuration DEFAULT_DISPATCH_TIMEOUT = NSan::PlainOrUnderSanitizer( namespace NActors { - struct THeSingleSystemEnv { }; - + struct THeSingleSystemEnv { }; + struct TEventMailboxId { TEventMailboxId() : NodeId(0) @@ -200,7 +200,7 @@ namespace NActors { typedef std::function<bool(TTestActorRuntimeBase& runtime, TAutoPtr<IEventHandle>& event)> TEventFilter; typedef std::function<bool(TTestActorRuntimeBase& runtime, TAutoPtr<IEventHandle>& event, TDuration delay, TInstant& deadline)> TScheduledEventFilter; typedef std::function<void(TTestActorRuntimeBase& runtime, const TActorId& parentId, const TActorId& actorId)> TRegistrationObserver; - + TTestActorRuntimeBase(THeSingleSystemEnv); TTestActorRuntimeBase(ui32 nodeCount, ui32 dataCenterCount, bool UseRealThreads); @@ -284,7 +284,7 @@ namespace NActors { return Nodes[FirstNodeId + nodeIdx]->LogSettings; } - TActorSystem* SingleSys() const; + TActorSystem* SingleSys() const; TActorSystem* GetAnyNodeActorSystem(); TActorSystem* GetActorSystem(ui32 nodeId); template <typename TEvent> @@ -471,12 +471,12 @@ namespace NActors { UseRealInterconnect = true; } - protected: + protected: struct TNodeDataBase; TNodeDataBase* GetRawNode(ui32 node) const { - return Nodes.at(FirstNodeId + node).Get(); - } - + return Nodes.at(FirstNodeId + node).Get(); + } + static IExecutorPool* CreateExecutorPoolStub(TTestActorRuntimeBase* runtime, ui32 nodeIndex, TNodeDataBase* node, ui32 poolId); virtual TIntrusivePtr<NMonitoring::TDynamicCounters> GetCountersForComponent(TIntrusivePtr<NMonitoring::TDynamicCounters> counters, const char* component) { Y_UNUSED(counters); @@ -492,7 +492,7 @@ namespace NActors { Y_UNUSED(setup); } - private: + private: IActor* FindActor(const TActorId& actorId, TNodeDataBase* node) const; void SendInternal(IEventHandle* ev, ui32 nodeIndex, bool viaActorSystem); TEventMailBox& GetMailbox(ui32 nodeId, ui32 hint); @@ -507,12 +507,12 @@ namespace NActors { THolder<TTempDir> TmpDir; const TThread::TId MainThreadId; - protected: + protected: bool UseRealInterconnect = false; TInterconnectMock InterconnectMock; bool IsInitialized = false; bool SingleSysEnv = false; - const TString ClusterUUID; + const TString ClusterUUID; const ui32 FirstNodeId; const ui32 NodeCount; const ui32 DataCenterCount; @@ -535,7 +535,7 @@ namespace NActors { TIntrusivePtr<IRandomProvider> RandomProvider; TIntrusivePtr<ITimeProvider> TimeProvider; - protected: + protected: struct TNodeDataBase: public TThrRefBase { TNodeDataBase(); void Stop(); @@ -598,7 +598,7 @@ namespace NActors { protected: THolder<INodeFactory> NodeFactory{new TDefaultNodeFactory}; - private: + private: void InitNode(TNodeDataBase* node, size_t idx); struct TDispatchContext { diff --git a/library/cpp/actors/testlib/ya.make b/library/cpp/actors/testlib/ya.make index 87dc50175e..1afb3f6059 100644 --- a/library/cpp/actors/testlib/ya.make +++ b/library/cpp/actors/testlib/ya.make @@ -1,26 +1,26 @@ -LIBRARY() - -OWNER( - g:kikimr -) - -SRCS( - test_runtime.cpp -) - -PEERDIR( +LIBRARY() + +OWNER( + g:kikimr +) + +SRCS( + test_runtime.cpp +) + +PEERDIR( library/cpp/actors/core library/cpp/actors/interconnect/mock library/cpp/actors/protos library/cpp/random_provider library/cpp/time_provider -) - -IF (GCC) - CFLAGS(-fno-devirtualize-speculatively) -ENDIF() - -END() +) + +IF (GCC) + CFLAGS(-fno-devirtualize-speculatively) +ENDIF() + +END() RECURSE_FOR_TESTS( ut |