diff options
author | Alexander Rutkovsky <alexvru@mail.ru> | 2022-02-10 16:47:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:39 +0300 |
commit | f3646f91e0de459836a7800b9ce3e8dc57a2ab3a (patch) | |
tree | 25c1423200152570c1f8307e5b8304b9bc3840c5 /library/cpp/actors/core/interconnect.h | |
parent | fccc62e9bfdce9be2fe7e0f23479da3a5512211a (diff) | |
download | ydb-f3646f91e0de459836a7800b9ce3e8dc57a2ab3a.tar.gz |
Restoring authorship annotation for Alexander Rutkovsky <alexvru@mail.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/actors/core/interconnect.h')
-rw-r--r-- | library/cpp/actors/core/interconnect.h | 252 |
1 files changed, 126 insertions, 126 deletions
diff --git a/library/cpp/actors/core/interconnect.h b/library/cpp/actors/core/interconnect.h index 679a4b8cc6..60151eba48 100644 --- a/library/cpp/actors/core/interconnect.h +++ b/library/cpp/actors/core/interconnect.h @@ -1,118 +1,118 @@ #pragma once - -#include "events.h" -#include "event_local.h" + +#include "events.h" +#include "event_local.h" #include <library/cpp/actors/protos/interconnect.pb.h> -#include <util/string/cast.h> -#include <util/string/builder.h> +#include <util/string/cast.h> +#include <util/string/builder.h> namespace NActors { - class TNodeLocation { - public: - struct TKeys { - enum E : int { - DataCenter = 10, - Module = 20, - Rack = 30, - Unit = 40, - }; - }; - - struct TLegacyValue { - ui32 DataCenter; - ui32 Room; - ui32 Rack; - ui32 Body; - - auto ConvertToTuple() const { return std::make_tuple(DataCenter, Room, Rack, Body); } - - int Compare(const TLegacyValue& other) const { - const auto x = ConvertToTuple(); - const auto y = other.ConvertToTuple(); - if (x < y) { - return -1; - } else if (y < x) { - return 1; - } else { - return 0; - } - } - - friend bool operator ==(const TLegacyValue& x, const TLegacyValue& y) { return x.Compare(y) == 0; } - - void Serialize(NActorsInterconnect::TNodeLocation *pb) const { - pb->SetDataCenterNum(DataCenter); - pb->SetRoomNum(Room); - pb->SetRackNum(Rack); - pb->SetBodyNum(Body); - } - }; - - private: - std::optional<TLegacyValue> LegacyValue; - std::vector<std::pair<TKeys::E, TString>> Items; - + class TNodeLocation { public: - // generic ctors - TNodeLocation() = default; - TNodeLocation(const TNodeLocation&) = default; - TNodeLocation(TNodeLocation&&) = default; - - // protobuf-parser ctor - explicit TNodeLocation(const NActorsInterconnect::TNodeLocation& location); - - // serialized protobuf ctor - static constexpr struct TFromSerialized {} FromSerialized {}; - TNodeLocation(TFromSerialized, const TString& s); - - // parser helper function - static NActorsInterconnect::TNodeLocation ParseLocation(const TString& s); - - // assignment operators - TNodeLocation& operator =(const TNodeLocation&) = default; - TNodeLocation& operator =(TNodeLocation&&) = default; - - void Serialize(NActorsInterconnect::TNodeLocation *pb) const; - TString GetSerializedLocation() const; - - TString GetDataCenterId() const { return ToStringUpTo(TKeys::DataCenter); } - TString GetModuleId() const { return ToStringUpTo(TKeys::Module); } - TString GetRackId() const { return ToStringUpTo(TKeys::Rack); } - TString ToString() const { return ToStringUpTo(TKeys::E(Max<int>())); } - TString ToStringUpTo(TKeys::E upToKey) const; - - TLegacyValue GetLegacyValue() const; - - const std::vector<std::pair<TKeys::E, TString>>& GetItems() const { return Items; } - - bool HasKey(TKeys::E key) const { - auto comp = [](const auto& p, TKeys::E value) { return p.first < value; }; - const auto it = std::lower_bound(Items.begin(), Items.end(), key, comp); - return it != Items.end() && it->first == key; - } - - int Compare(const TNodeLocation& other) const { - if (LegacyValue || other.LegacyValue) { - return GetLegacyValue().Compare(other.GetLegacyValue()); - } else if (Items < other.Items) { - return -1; - } else if (other.Items < Items) { - return 1; - } else { - return 0; - } - } - - void InheritLegacyValue(const TNodeLocation& other) { - LegacyValue = other.GetLegacyValue(); - } - - friend bool operator ==(const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) == 0; } - friend bool operator !=(const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) != 0; } - friend bool operator < (const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) < 0; } - friend bool operator <=(const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) <= 0; } - friend bool operator > (const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) > 0; } - friend bool operator >=(const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) >= 0; } + struct TKeys { + enum E : int { + DataCenter = 10, + Module = 20, + Rack = 30, + Unit = 40, + }; + }; + + struct TLegacyValue { + ui32 DataCenter; + ui32 Room; + ui32 Rack; + ui32 Body; + + auto ConvertToTuple() const { return std::make_tuple(DataCenter, Room, Rack, Body); } + + int Compare(const TLegacyValue& other) const { + const auto x = ConvertToTuple(); + const auto y = other.ConvertToTuple(); + if (x < y) { + return -1; + } else if (y < x) { + return 1; + } else { + return 0; + } + } + + friend bool operator ==(const TLegacyValue& x, const TLegacyValue& y) { return x.Compare(y) == 0; } + + void Serialize(NActorsInterconnect::TNodeLocation *pb) const { + pb->SetDataCenterNum(DataCenter); + pb->SetRoomNum(Room); + pb->SetRackNum(Rack); + pb->SetBodyNum(Body); + } + }; + + private: + std::optional<TLegacyValue> LegacyValue; + std::vector<std::pair<TKeys::E, TString>> Items; + + public: + // generic ctors + TNodeLocation() = default; + TNodeLocation(const TNodeLocation&) = default; + TNodeLocation(TNodeLocation&&) = default; + + // protobuf-parser ctor + explicit TNodeLocation(const NActorsInterconnect::TNodeLocation& location); + + // serialized protobuf ctor + static constexpr struct TFromSerialized {} FromSerialized {}; + TNodeLocation(TFromSerialized, const TString& s); + + // parser helper function + static NActorsInterconnect::TNodeLocation ParseLocation(const TString& s); + + // assignment operators + TNodeLocation& operator =(const TNodeLocation&) = default; + TNodeLocation& operator =(TNodeLocation&&) = default; + + void Serialize(NActorsInterconnect::TNodeLocation *pb) const; + TString GetSerializedLocation() const; + + TString GetDataCenterId() const { return ToStringUpTo(TKeys::DataCenter); } + TString GetModuleId() const { return ToStringUpTo(TKeys::Module); } + TString GetRackId() const { return ToStringUpTo(TKeys::Rack); } + TString ToString() const { return ToStringUpTo(TKeys::E(Max<int>())); } + TString ToStringUpTo(TKeys::E upToKey) const; + + TLegacyValue GetLegacyValue() const; + + const std::vector<std::pair<TKeys::E, TString>>& GetItems() const { return Items; } + + bool HasKey(TKeys::E key) const { + auto comp = [](const auto& p, TKeys::E value) { return p.first < value; }; + const auto it = std::lower_bound(Items.begin(), Items.end(), key, comp); + return it != Items.end() && it->first == key; + } + + int Compare(const TNodeLocation& other) const { + if (LegacyValue || other.LegacyValue) { + return GetLegacyValue().Compare(other.GetLegacyValue()); + } else if (Items < other.Items) { + return -1; + } else if (other.Items < Items) { + return 1; + } else { + return 0; + } + } + + void InheritLegacyValue(const TNodeLocation& other) { + LegacyValue = other.GetLegacyValue(); + } + + friend bool operator ==(const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) == 0; } + friend bool operator !=(const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) != 0; } + friend bool operator < (const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) < 0; } + friend bool operator <=(const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) <= 0; } + friend bool operator > (const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) > 0; } + friend bool operator >=(const TNodeLocation& x, const TNodeLocation& y) { return x.Compare(y) >= 0; } }; struct TEvInterconnect { @@ -131,13 +131,13 @@ namespace NActors { EvDisconnect, EvGetNode, EvNodeInfo, - EvClosePeerSocket, - EvCloseInputSession, - EvPoisonSession, - EvTerminate, + EvClosePeerSocket, + EvCloseInputSession, + EvPoisonSession, + EvTerminate, EvEnd }; - + enum ESubscribes { SubConnected, SubDisconnected, @@ -184,7 +184,7 @@ namespace NActors { TString Host; TString ResolveHost; ui16 Port; - TNodeLocation Location; + TNodeLocation Location; TNodeInfo() = default; TNodeInfo(const TNodeInfo&) = default; @@ -194,7 +194,7 @@ namespace NActors { const TString& host, const TString& resolveHost, ui16 port, - const TNodeLocation& location) + const TNodeLocation& location) : NodeId(nodeId) , Address(address) , Host(host) @@ -225,11 +225,11 @@ namespace NActors { struct TEvGetNode: public TEventLocal<TEvGetNode, EvGetNode> { ui32 NodeId; - TInstant Deadline; + TInstant Deadline; - TEvGetNode(ui32 nodeId, TInstant deadline = TInstant::Max()) + TEvGetNode(ui32 nodeId, TInstant deadline = TInstant::Max()) : NodeId(nodeId) - , Deadline(deadline) + , Deadline(deadline) { } }; @@ -243,13 +243,13 @@ namespace NActors { ui32 NodeId; THolder<TNodeInfo> Node; }; - + struct TEvClosePeerSocket : TEventLocal<TEvClosePeerSocket, EvClosePeerSocket> {}; - + struct TEvCloseInputSession : TEventLocal<TEvCloseInputSession, EvCloseInputSession> {}; - - struct TEvPoisonSession : TEventLocal<TEvPoisonSession, EvPoisonSession> {}; - - struct TEvTerminate : TEventLocal<TEvTerminate, EvTerminate> {}; + + struct TEvPoisonSession : TEventLocal<TEvPoisonSession, EvPoisonSession> {}; + + struct TEvTerminate : TEventLocal<TEvTerminate, EvTerminate> {}; }; } |