diff options
author | yegorskii <yegorskii@yandex-team.ru> | 2022-02-10 16:49:10 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:10 +0300 |
commit | 6c7ed19fb4e807d81f39d5b370b1dba604558a17 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 | |
parent | 7902ff9c26a2eacba73e7137a81aed2df9b3e9c1 (diff) | |
download | ydb-6c7ed19fb4e807d81f39d5b370b1dba604558a17.tar.gz |
Restoring authorship annotation for <yegorskii@yandex-team.ru>. Commit 2 of 2.
42 files changed, 1141 insertions, 1141 deletions
diff --git a/library/cpp/actors/core/log_settings.cpp b/library/cpp/actors/core/log_settings.cpp index e49abf4717..f52f2fc5d2 100644 --- a/library/cpp/actors/core/log_settings.cpp +++ b/library/cpp/actors/core/log_settings.cpp @@ -6,11 +6,11 @@ namespace NActors { namespace NLog { TSettings::TSettings(const TActorId& loggerActorId, const EComponent loggerComponent, EComponent minVal, EComponent maxVal, EComponentToStringFunc func, - EPriority defPriority, EPriority defSamplingPriority, - ui32 defSamplingRate, ui64 timeThresholdMs) + EPriority defPriority, EPriority defSamplingPriority, + ui32 defSamplingRate, ui64 timeThresholdMs) : LoggerActorId(loggerActorId) , LoggerComponent(loggerComponent) - , TimeThresholdMs(timeThresholdMs) + , TimeThresholdMs(timeThresholdMs) , AllowDrop(true) , ThrottleDelay(TDuration::MilliSeconds(100)) , MinVal(0) @@ -28,11 +28,11 @@ namespace NActors { } TSettings::TSettings(const TActorId& loggerActorId, const EComponent loggerComponent, - EPriority defPriority, EPriority defSamplingPriority, - ui32 defSamplingRate, ui64 timeThresholdMs) + EPriority defPriority, EPriority defSamplingPriority, + ui32 defSamplingRate, ui64 timeThresholdMs) : LoggerActorId(loggerActorId) , LoggerComponent(loggerComponent) - , TimeThresholdMs(timeThresholdMs) + , TimeThresholdMs(timeThresholdMs) , AllowDrop(true) , ThrottleDelay(TDuration::MilliSeconds(100)) , MinVal(0) diff --git a/library/cpp/actors/core/log_settings.h b/library/cpp/actors/core/log_settings.h index ebb689be09..7fe4504edd 100644 --- a/library/cpp/actors/core/log_settings.h +++ b/library/cpp/actors/core/log_settings.h @@ -100,12 +100,12 @@ namespace NActors { // YOURTYPE_Name for you. TSettings(const TActorId& loggerActorId, const EComponent loggerComponent, EComponent minVal, EComponent maxVal, EComponentToStringFunc func, - EPriority defPriority, EPriority defSamplingPriority = PRI_DEBUG, - ui32 defSamplingRate = 0, ui64 timeThresholdMs = 1000); + EPriority defPriority, EPriority defSamplingPriority = PRI_DEBUG, + ui32 defSamplingRate = 0, ui64 timeThresholdMs = 1000); TSettings(const TActorId& loggerActorId, const EComponent loggerComponent, - EPriority defPriority, EPriority defSamplingPriority = PRI_DEBUG, - ui32 defSamplingRate = 0, ui64 timeThresholdMs = 1000); + EPriority defPriority, EPriority defSamplingPriority = PRI_DEBUG, + ui32 defSamplingRate = 0, ui64 timeThresholdMs = 1000); void Append(EComponent minVal, EComponent maxVal, EComponentToStringFunc func); diff --git a/library/cpp/actors/core/log_ut.cpp b/library/cpp/actors/core/log_ut.cpp index d742357e3f..09b5f88ea2 100644 --- a/library/cpp/actors/core/log_ut.cpp +++ b/library/cpp/actors/core/log_ut.cpp @@ -22,19 +22,19 @@ namespace { return s; } - TIntrusivePtr<TSettings> DroppingSettings(ui64 timeThresholdMs) { - auto loggerId = TActorId{0, "Logger"}; - auto s = MakeIntrusive<TSettings>( - loggerId, - 0, - EPriority::PRI_TRACE, - EPriority::PRI_DEBUG, - (ui32)0, - timeThresholdMs); - s->Append(0, 1, ServiceToString); - return s; - } - + TIntrusivePtr<TSettings> DroppingSettings(ui64 timeThresholdMs) { + auto loggerId = TActorId{0, "Logger"}; + auto s = MakeIntrusive<TSettings>( + loggerId, + 0, + EPriority::PRI_TRACE, + EPriority::PRI_DEBUG, + (ui32)0, + timeThresholdMs); + s->Append(0, 1, ServiceToString); + return s; + } + class TMockBackend: public TLogBackend { public: using TWriteImpl = std::function<void(const TLogRecord&)>; @@ -68,30 +68,30 @@ namespace { }; struct TFixture { - TFixture( - TIntrusivePtr<TSettings> settings, - TMockBackend::TWriteImpl writeImpl = ThrowAlways) - { + TFixture( + TIntrusivePtr<TSettings> settings, + TMockBackend::TWriteImpl writeImpl = ThrowAlways) + { Runtime.Initialize(); LogBackend.reset(new TMockBackend{writeImpl}); - LoggerActor = Runtime.Register(new TLoggerActor{settings, LogBackend, Counters}); + LoggerActor = Runtime.Register(new TLoggerActor{settings, LogBackend, Counters}); Runtime.SetScheduledEventFilter([] (auto&&, auto&&, auto&&, auto) { return false; }); } - TFixture(TMockBackend::TWriteImpl writeImpl = ThrowAlways) - : TFixture(DefaultSettings(), writeImpl) - {} - + TFixture(TMockBackend::TWriteImpl writeImpl = ThrowAlways) + : TFixture(DefaultSettings(), writeImpl) + {} + void WriteLog() { Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(TInstant::Zero(), TLevel{EPrio::Emerg}, 0, "foo")}); } - void WriteLog(TInstant ts) { - Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(ts, TLevel{EPrio::Emerg}, 0, "foo")}); - } - + void WriteLog(TInstant ts) { + Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(ts, TLevel{EPrio::Emerg}, 0, "foo")}); + } + void Wakeup() { Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvents::TEvWakeup}); } @@ -152,34 +152,34 @@ Y_UNIT_TEST_SUITE(TLoggerActorTest) { UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT); } - - Y_UNIT_TEST(ShouldObeyTimeThresholdMsWhenOverloaded) { - TFixture test{DroppingSettings(5000)}; - - TVector<TString> messages; - auto acceptWrites = [&] (const TLogRecord& r) { - messages.emplace_back(r.Data, r.Len); - }; - - test.LogBackend->SetWriteImpl(acceptWrites); - test.Wakeup(); - - const auto COUNT = 11; - for (auto i = 0; i < COUNT; ++i) { - test.WriteLog(); - } - - UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT); - - test.Runtime.AdvanceCurrentTime(TDuration::Seconds(20)); - auto now = test.Runtime.GetCurrentTime(); - - test.WriteLog(now - TDuration::Seconds(5)); - - UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT + 1); - - test.WriteLog(now - TDuration::Seconds(6)); - - UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT + 1); - } + + Y_UNIT_TEST(ShouldObeyTimeThresholdMsWhenOverloaded) { + TFixture test{DroppingSettings(5000)}; + + TVector<TString> messages; + auto acceptWrites = [&] (const TLogRecord& r) { + messages.emplace_back(r.Data, r.Len); + }; + + test.LogBackend->SetWriteImpl(acceptWrites); + test.Wakeup(); + + const auto COUNT = 11; + for (auto i = 0; i < COUNT; ++i) { + test.WriteLog(); + } + + UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT); + + test.Runtime.AdvanceCurrentTime(TDuration::Seconds(20)); + auto now = test.Runtime.GetCurrentTime(); + + test.WriteLog(now - TDuration::Seconds(5)); + + UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT + 1); + + test.WriteLog(now - TDuration::Seconds(6)); + + UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT + 1); + } } diff --git a/library/cpp/actors/core/mon.h b/library/cpp/actors/core/mon.h index 3854356fa8..c450f2338e 100644 --- a/library/cpp/actors/core/mon.h +++ b/library/cpp/actors/core/mon.h @@ -88,14 +88,14 @@ namespace NActors { { } - TEvRemoteHttpInfo(const TString& query, HTTP_METHOD method) - : Query(query) - , Method(method) - { - } - + TEvRemoteHttpInfo(const TString& query, HTTP_METHOD method) + : Query(query) + , Method(method) + { + } + TString Query; - HTTP_METHOD Method; + HTTP_METHOD Method; TString PathInfo() const { const size_t pos = Query.find('?'); @@ -126,11 +126,11 @@ namespace NActors { static IEventBase* Load(TEventSerializedData* bufs) { return new TEvRemoteHttpInfo(bufs->GetString()); } - - HTTP_METHOD GetMethod() const - { - return Method; - } + + HTTP_METHOD GetMethod() const + { + return Method; + } }; struct TEvRemoteHttpInfoRes: public NActors::TEventBase<TEvRemoteHttpInfoRes, RemoteHttpInfoRes> { diff --git a/library/cpp/logger/system.cpp b/library/cpp/logger/system.cpp index 172719c716..42233f63d2 100644 --- a/library/cpp/logger/system.cpp +++ b/library/cpp/logger/system.cpp @@ -4,7 +4,7 @@ #include <util/system/yassert.h> #include <util/system/defaults.h> #include <util/generic/singleton.h> -#include <util/generic/utility.h> +#include <util/generic/utility.h> #if defined(_unix_) #include <syslog.h> @@ -64,12 +64,12 @@ void TSysLogBackend::ReopenLog() { } int TSysLogBackend::ELogPriority2SyslogPriority(ELogPriority priority) { -#if defined(_unix_) - return Min(int(priority), (int)LOG_PRIMASK); -#else +#if defined(_unix_) + return Min(int(priority), (int)LOG_PRIMASK); +#else // trivial conversion return int(priority); -#endif +#endif } namespace { diff --git a/library/cpp/lwtrace/control.cpp b/library/cpp/lwtrace/control.cpp index ffed939922..d9404ff269 100644 --- a/library/cpp/lwtrace/control.cpp +++ b/library/cpp/lwtrace/control.cpp @@ -1,97 +1,97 @@ -#include "probes.h" - -#include <library/cpp/lwtrace/protos/lwtrace.pb.h> - -#include <util/generic/string.h> - -namespace NLWTrace { - -LWTRACE_USING(LWTRACE_INTERNAL_PROVIDER); - -TProbeMap TManager::GetProbesMap() { - class TProbeReader - { - private: - TProbeMap& Result; - - public: - TProbeReader(TProbeMap& result) - : Result(result) - {} - - void Push(NLWTrace::TProbe* probe) - { - Result[std::make_pair(probe->Event.Name, probe->Event.GetProvider())] = probe; - } - }; - - TProbeMap result; - - auto reader = TProbeReader(result); - ReadProbes(reader); - return result; -} - -void TManager::CreateTraceRequest(TTraceRequest& msg, TOrbit& orbit) -{ - msg.SetIsTraced(orbit.HasShuttles()); -} - -bool TManager::HandleTraceRequest( - const TTraceRequest& msg, - TOrbit& orbit) -{ - if (!msg.GetIsTraced()) { - return false; - } - TParams params; - SerializingExecutor->Execute(orbit, params); - return true; -} - -TTraceDeserializeStatus TManager::HandleTraceResponse( - const TTraceResponse& msg, - const TProbeMap& probesMap, - TOrbit& orbit, - i64 timeOffset, - double timeScale) -{ - TTraceDeserializeStatus result; - if (!msg.GetTrace().GetEvents().size()) { - return result; - } - - ui64 prev = EpochNanosecondsToCycles( - msg.GetTrace().GetEvents()[0].GetTimestampNanosec()); - - for (auto& v : msg.GetTrace().GetEvents()) { - auto it = probesMap.find(std::make_pair(v.GetName(), v.GetProvider())); - if (it != probesMap.end()) { - TProbe* probe = it->second; - TParams params; - if(!probe->Event.Signature.DeserializeFromPb(params, v.GetParams())) { - LWTRACK(DeserializationError, orbit, probe->Event.Name, probe->Event.GetProvider()); - result.AddFailedEventName(v.GetName()); - } else { - ui64 timestamp = EpochNanosecondsToCycles(v.GetTimestampNanosec()); - orbit.AddProbe( - probe, - params, - prev + (timestamp-prev)*timeScale + timeOffset); - probe->Event.Signature.DestroyParams(params); - prev = timestamp; - } - } else { - result.AddFailedEventName(v.GetName()); - } - } - return result; -} - -void TManager::CreateTraceResponse(TTraceResponse& msg, TOrbit& orbit) -{ - orbit.Serialize(0, *msg.MutableTrace()); -} - -} - +#include "probes.h" + +#include <library/cpp/lwtrace/protos/lwtrace.pb.h> + +#include <util/generic/string.h> + +namespace NLWTrace { + +LWTRACE_USING(LWTRACE_INTERNAL_PROVIDER); + +TProbeMap TManager::GetProbesMap() { + class TProbeReader + { + private: + TProbeMap& Result; + + public: + TProbeReader(TProbeMap& result) + : Result(result) + {} + + void Push(NLWTrace::TProbe* probe) + { + Result[std::make_pair(probe->Event.Name, probe->Event.GetProvider())] = probe; + } + }; + + TProbeMap result; + + auto reader = TProbeReader(result); + ReadProbes(reader); + return result; +} + +void TManager::CreateTraceRequest(TTraceRequest& msg, TOrbit& orbit) +{ + msg.SetIsTraced(orbit.HasShuttles()); +} + +bool TManager::HandleTraceRequest( + const TTraceRequest& msg, + TOrbit& orbit) +{ + if (!msg.GetIsTraced()) { + return false; + } + TParams params; + SerializingExecutor->Execute(orbit, params); + return true; +} + +TTraceDeserializeStatus TManager::HandleTraceResponse( + const TTraceResponse& msg, + const TProbeMap& probesMap, + TOrbit& orbit, + i64 timeOffset, + double timeScale) +{ + TTraceDeserializeStatus result; + if (!msg.GetTrace().GetEvents().size()) { + return result; + } + + ui64 prev = EpochNanosecondsToCycles( + msg.GetTrace().GetEvents()[0].GetTimestampNanosec()); + + for (auto& v : msg.GetTrace().GetEvents()) { + auto it = probesMap.find(std::make_pair(v.GetName(), v.GetProvider())); + if (it != probesMap.end()) { + TProbe* probe = it->second; + TParams params; + if(!probe->Event.Signature.DeserializeFromPb(params, v.GetParams())) { + LWTRACK(DeserializationError, orbit, probe->Event.Name, probe->Event.GetProvider()); + result.AddFailedEventName(v.GetName()); + } else { + ui64 timestamp = EpochNanosecondsToCycles(v.GetTimestampNanosec()); + orbit.AddProbe( + probe, + params, + prev + (timestamp-prev)*timeScale + timeOffset); + probe->Event.Signature.DestroyParams(params); + prev = timestamp; + } + } else { + result.AddFailedEventName(v.GetName()); + } + } + return result; +} + +void TManager::CreateTraceResponse(TTraceResponse& msg, TOrbit& orbit) +{ + orbit.Serialize(0, *msg.MutableTrace()); +} + +} + diff --git a/library/cpp/lwtrace/control.h b/library/cpp/lwtrace/control.h index b85e8468be..16b24eafd2 100644 --- a/library/cpp/lwtrace/control.h +++ b/library/cpp/lwtrace/control.h @@ -3,7 +3,7 @@ #include "custom_action.h" #include "event.h" #include "log.h" -#include "log_shuttle.h" +#include "log_shuttle.h" #include "probe.h" #include <library/cpp/lwtrace/protos/lwtrace.pb.h> @@ -18,9 +18,9 @@ #include <util/generic/vector.h> namespace NLWTrace { - - using TProbeMap = THashMap<std::pair<TString, TString>, TProbe*>; - + + using TProbeMap = THashMap<std::pair<TString, TString>, TProbe*>; + // Interface for probe ownership management class IBox: public virtual TThrRefBase { private: @@ -203,38 +203,38 @@ namespace NLWTrace { void ToProtobuf(TLogPb& pb) const; }; - // Deserialization result. - // Either IsSuccess is true or FailedEventNames contains event names - // we were not able to deserialize. - struct TTraceDeserializeStatus - { - bool IsSuccess = true; - TVector<TString> FailedEventNames; - - void AddFailedEventName(const TString& name) - { - IsSuccess = false; - FailedEventNames.emplace_back(name); - } - }; - + // Deserialization result. + // Either IsSuccess is true or FailedEventNames contains event names + // we were not able to deserialize. + struct TTraceDeserializeStatus + { + bool IsSuccess = true; + TVector<TString> FailedEventNames; + + void AddFailedEventName(const TString& name) + { + IsSuccess = false; + FailedEventNames.emplace_back(name); + } + }; + // Just a registry of all active trace queries // Facade for all interactions with probes/traces class TManager: public TNonCopyable { private: TProbeRegistry& Registry; TMutex Mtx; - ui64 LastTraceIdx = 1; + ui64 LastTraceIdx = 1; typedef THashMap<TString, TSession*> TTraces; // traceId -> TSession TTraces Traces; bool DestructiveActionsAllowed; TCustomActionFactory CustomActionFactory; - THolder<TRunLogShuttleActionExecutor<TCyclicDepot>> SerializingExecutor; + THolder<TRunLogShuttleActionExecutor<TCyclicDepot>> SerializingExecutor; + + public: + static constexpr ui64 RemoteTraceIdx = 0; public: - static constexpr ui64 RemoteTraceIdx = 0; - - public: TManager(TProbeRegistry& registry, bool allowDestructiveActions); ~TManager(); bool HasTrace(const TString& id) const; @@ -324,28 +324,28 @@ namespace NLWTrace { return new T(probe, action, trace); }); } - - TProbeMap GetProbesMap(); - - void CreateTraceRequest(TTraceRequest& msg, TOrbit& orbit); - - bool HandleTraceRequest( - const TTraceRequest& msg, - TOrbit& orbit); - - TTraceDeserializeStatus HandleTraceResponse( - const TTraceResponse& msg, - const TProbeMap& probesMap, - TOrbit& orbit, - i64 timeOffset = 0, - double timeScale = 1); - - void CreateTraceResponse( - TTraceResponse& msg, - TOrbit& orbit); - - bool IsTraced(TOrbit& orbit) { - return orbit.HasShuttle(TManager::RemoteTraceIdx); - } + + TProbeMap GetProbesMap(); + + void CreateTraceRequest(TTraceRequest& msg, TOrbit& orbit); + + bool HandleTraceRequest( + const TTraceRequest& msg, + TOrbit& orbit); + + TTraceDeserializeStatus HandleTraceResponse( + const TTraceResponse& msg, + const TProbeMap& probesMap, + TOrbit& orbit, + i64 timeOffset = 0, + double timeScale = 1); + + void CreateTraceResponse( + TTraceResponse& msg, + TOrbit& orbit); + + bool IsTraced(TOrbit& orbit) { + return orbit.HasShuttle(TManager::RemoteTraceIdx); + } }; } diff --git a/library/cpp/lwtrace/log_shuttle.h b/library/cpp/lwtrace/log_shuttle.h index d3d5fe0bde..729a38615f 100644 --- a/library/cpp/lwtrace/log_shuttle.h +++ b/library/cpp/lwtrace/log_shuttle.h @@ -3,8 +3,8 @@ #include "log.h" #include "probe.h" -#include <library/cpp/lwtrace/protos/lwtrace.pb.h> - +#include <library/cpp/lwtrace/protos/lwtrace.pb.h> + #include <util/system/spinlock.h> namespace NLWTrace { @@ -14,35 +14,35 @@ namespace NLWTrace { //////////////////////////////////////////////////////////////////////////////// struct THostTimeCalculator { - double K = 0; - ui64 B = 0; - + double K = 0; + ui64 B = 0; + THostTimeCalculator() { - TInstant now = TInstant::Now(); - ui64 tsNow = GetCycleCount(); - K = 1000000000 / NHPTimer::GetClockRate(); - B = now.NanoSeconds() - K * tsNow; - } - + TInstant now = TInstant::Now(); + ui64 tsNow = GetCycleCount(); + K = 1000000000 / NHPTimer::GetClockRate(); + B = now.NanoSeconds() - K * tsNow; + } + ui64 CyclesToEpochNanoseconds(ui64 cycles) const { - return K*cycles + B; - } - + return K*cycles + B; + } + ui64 EpochNanosecondsToCycles(ui64 ns) const { - return (ns - B) / K; - } - }; - + return (ns - B) / K; + } + }; + inline ui64 CyclesToEpochNanoseconds(ui64 cycles) { - return Singleton<THostTimeCalculator>()->CyclesToEpochNanoseconds(cycles); - } - + return Singleton<THostTimeCalculator>()->CyclesToEpochNanoseconds(cycles); + } + inline ui64 EpochNanosecondsToCycles(ui64 ns) { - return Singleton<THostTimeCalculator>()->EpochNanosecondsToCycles(ns); - } - - //////////////////////////////////////////////////////////////////////////////// - + return Singleton<THostTimeCalculator>()->EpochNanosecondsToCycles(ns); + } + + //////////////////////////////////////////////////////////////////////////////// + template <class TDepot> class TLogShuttle: public IShuttle { private: @@ -62,10 +62,10 @@ namespace NLWTrace { { } - bool DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) override; + bool DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) override; void DoEndOfTrack() override; void DoDrop() override; - void DoSerialize(TShuttleTrace& msg) override; + void DoSerialize(TShuttleTrace& msg) override; bool DoFork(TShuttlePtr& child) override; bool DoJoin(const TShuttlePtr& child) override; @@ -155,7 +155,7 @@ namespace NLWTrace { //////////////////////////////////////////////////////////////////////////////// template <class TDepot> - bool TLogShuttle<TDepot>::DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) { + bool TLogShuttle<TDepot>::DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) { with_lock (Lock) { if (TrackLog.Items.size() >= MaxTrackLength) { TrackLog.Truncated = true; @@ -168,7 +168,7 @@ namespace NLWTrace { if ((item->SavedParamsCount = probe->Event.Signature.ParamCount) > 0) { probe->Event.Signature.CloneParams(item->Params, params); } - item->TimestampCycles = timestamp ? timestamp : GetCycleCount(); + item->TimestampCycles = timestamp ? timestamp : GetCycleCount(); } return true; @@ -204,25 +204,25 @@ namespace NLWTrace { } template <class TDepot> - void TLogShuttle<TDepot>::DoSerialize(TShuttleTrace& msg) - { - with_lock (Lock) - { - if (!GetTrackLog().Items.size()) { - return ; - } - for (auto& record : GetTrackLog().Items) { - auto *rec = msg.AddEvents(); - rec->SetName(record.Probe->Event.Name); - rec->SetProvider(record.Probe->Event.GetProvider()); - rec->SetTimestampNanosec( - CyclesToEpochNanoseconds(record.TimestampCycles)); - record.Probe->Event.Signature.SerializeToPb(record.Params, *rec->MutableParams()); - } - } - } - - template <class TDepot> + void TLogShuttle<TDepot>::DoSerialize(TShuttleTrace& msg) + { + with_lock (Lock) + { + if (!GetTrackLog().Items.size()) { + return ; + } + for (auto& record : GetTrackLog().Items) { + auto *rec = msg.AddEvents(); + rec->SetName(record.Probe->Event.Name); + rec->SetProvider(record.Probe->Event.GetProvider()); + rec->SetTimestampNanosec( + CyclesToEpochNanoseconds(record.TimestampCycles)); + record.Probe->Event.Signature.SerializeToPb(record.Params, *rec->MutableParams()); + } + } + } + + template <class TDepot> TLogShuttle<TDepot>* TLogShuttleActionBase<TDepot>::Cast(const TShuttlePtr& shuttle) { return static_cast<TLogShuttle<TDepot>*>(shuttle.Get()); } @@ -247,7 +247,7 @@ namespace NLWTrace { , LastTrackId(lastTrackId) , LastSpanId(lastSpanId) { - ui64 size = Min<ui64>(Action.GetShuttlesCount() ? Action.GetShuttlesCount() : 1000, MaxShuttles); // Do not allow to allocate too much memory + ui64 size = Min<ui64>(Action.GetShuttlesCount() ? Action.GetShuttlesCount() : 1000, MaxShuttles); // Do not allow to allocate too much memory AllShuttles.reserve(size); Parking.reserve(size); for (ui64 i = 0; i < size; i++) { @@ -283,9 +283,9 @@ namespace NLWTrace { template <class TDepot> void TRunLogShuttleActionExecutor<TDepot>::RecordShuttle(TLogShuttle<TDepot>* shuttle) { - if (Depot == nullptr) { - return; - } + if (Depot == nullptr) { + return; + } typename TDepot::TAccessor a(*Depot); if (TTrackLog* trackLog = a.Add()) { *trackLog = shuttle->GetTrackLog(); diff --git a/library/cpp/lwtrace/lwprobe.h b/library/cpp/lwtrace/lwprobe.h index 021a580b2e..801fc3861b 100644 --- a/library/cpp/lwtrace/lwprobe.h +++ b/library/cpp/lwtrace/lwprobe.h @@ -61,8 +61,8 @@ namespace NLWTrace { signature.SerializeParamsFunc = &TUsrSign::SerializeParams; signature.CloneParamsFunc = &TUsrSign::CloneParams; signature.DestroyParamsFunc = &TUsrSign::DestroyParams; - signature.SerializeToPbFunc = &TUsrSign::SerializeToPb; - signature.DeserializeFromPbFunc = &TUsrSign::DeserializeFromPb; + signature.SerializeToPbFunc = &TUsrSign::SerializeToPb; + signature.DeserializeFromPbFunc = &TUsrSign::DeserializeFromPb; // register probe in global registry Register(*Singleton<NLWTrace::TProbeRegistry>()); diff --git a/library/cpp/lwtrace/mon/mon_lwtrace.cpp b/library/cpp/lwtrace/mon/mon_lwtrace.cpp index 4ca9ff15f0..a61ee9ce22 100644 --- a/library/cpp/lwtrace/mon/mon_lwtrace.cpp +++ b/library/cpp/lwtrace/mon/mon_lwtrace.cpp @@ -511,9 +511,9 @@ struct TAdHocTraceConfig { } auto block = Cfg.GetBlocks(blockIdx); auto pdesc = block.GetProbeDesc(); - if (pdesc.GetProvider()) { + if (pdesc.GetProvider()) { ss << "." << pdesc.GetProvider() << "." << pdesc.GetName(); - } else if (pdesc.GetGroup()) { + } else if (pdesc.GetGroup()) { ss << ".Group." << pdesc.GetGroup(); } // TODO[serxa]: handle predicate @@ -525,10 +525,10 @@ struct TAdHocTraceConfig { if (ls.GetIgnore()) { ss << "-i"; } - if (ls.GetShuttlesCount()) { + if (ls.GetShuttlesCount()) { ss << "-s" << ls.GetShuttlesCount(); } - if (ls.GetMaxTrackLength()) { + if (ls.GetMaxTrackLength()) { ss << "-t" << ls.GetMaxTrackLength(); } } else if (action.HasEditLogShuttleAction()) { @@ -542,10 +542,10 @@ struct TAdHocTraceConfig { } } } - if (Cfg.GetPerThreadLogSize()) { + if (Cfg.GetPerThreadLogSize()) { ss << ".l" << Cfg.GetPerThreadLogSize(); } - if (Cfg.GetLogDurationUs()) { + if (Cfg.GetLogDurationUs()) { ui64 logDurationUs = Cfg.GetLogDurationUs(); if (logDurationUs % (60 * 1000 * 1000) == 0) ss << ".d" << logDurationUs / (60 * 1000 * 1000) << "m"; diff --git a/library/cpp/lwtrace/preprocessor.h b/library/cpp/lwtrace/preprocessor.h index 1945a55c18..40865467b2 100644 --- a/library/cpp/lwtrace/preprocessor.h +++ b/library/cpp/lwtrace/preprocessor.h @@ -172,9 +172,9 @@ namespace NLWTrace { /* ParamCount */ ::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::ParamCount, \ /* SerializeParams */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::SerializeParams, \ /* CloneParams */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::CloneParams, \ - /* DestroyParams */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::DestroyParams, \ - /* SerializeToPb */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::SerializeToPb, \ - /* DeserializeFromPb */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::DeserializeFromPb\ + /* DestroyParams */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::DestroyParams, \ + /* SerializeToPb */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::SerializeToPb, \ + /* DeserializeFromPb */ &::NLWTrace::TUserSignature<LWTRACE_EXPAND(LWTRACE_UNROLL types)>::DeserializeFromPb\ } // Macro for TEvent POD structure static initialization diff --git a/library/cpp/lwtrace/probes.h b/library/cpp/lwtrace/probes.h index 4adcf7d00d..68810bd118 100644 --- a/library/cpp/lwtrace/probes.h +++ b/library/cpp/lwtrace/probes.h @@ -7,8 +7,8 @@ TYPES(double, double, double, double), \ NAMES("probeShare", "probeMinMs", "probeMaxMs", "probeAvgMs")) \ PROBE(DeserializationError, GROUPS("LWTraceError"), \ - TYPES(TString, TString), \ - NAMES("probeName", "providerName")) \ + TYPES(TString, TString), \ + NAMES("probeName", "providerName")) \ PROBE(Fork, GROUPS(), \ TYPES(ui64), \ NAMES("spanId")) \ diff --git a/library/cpp/lwtrace/protos/lwtrace.proto b/library/cpp/lwtrace/protos/lwtrace.proto index bdf6551a48..0051095719 100644 --- a/library/cpp/lwtrace/protos/lwtrace.proto +++ b/library/cpp/lwtrace/protos/lwtrace.proto @@ -1,35 +1,35 @@ /* * This file defines language for trace queries and serialization format for trace logs */ -syntax = "proto3"; - +syntax = "proto3"; + package NLWTrace; -option go_package = "a.yandex-team.ru/library/cpp/lwtrace/protos"; - +option go_package = "a.yandex-team.ru/library/cpp/lwtrace/protos"; + message TProbeDesc { - string Name = 1; // Use either name+provider - string Provider = 3; - string Group = 2; // or group + string Name = 1; // Use either name+provider + string Provider = 3; + string Group = 2; // or group } enum EOperatorType { - OT_EQ = 0; - OT_NE = 1; - OT_LT = 2; - OT_LE = 3; - OT_GT = 4; - OT_GE = 5; + OT_EQ = 0; + OT_NE = 1; + OT_LT = 2; + OT_LE = 3; + OT_GT = 4; + OT_GE = 5; } message TArgument { - string Param = 1; + string Param = 1; bytes Value = 2; - string Variable = 3; + string Variable = 3; } message TOperator { - EOperatorType Type = 1; + EOperatorType Type = 1; repeated TArgument Argument = 8; } @@ -39,9 +39,9 @@ message TPredicate { } message TLogAction { - bool DoNotLogParams = 2; - bool LogTimestamp = 3; - uint32 MaxRecords = 4; // Do not write more than MaxRecords records to the log (count from the trace beginning, not start) + bool DoNotLogParams = 2; + bool LogTimestamp = 3; + uint32 MaxRecords = 4; // Do not write more than MaxRecords records to the log (count from the trace beginning, not start) } message TPrintToStderrAction { @@ -51,72 +51,72 @@ message TKillAction { } message TSleepAction { - uint64 NanoSeconds = 1; + uint64 NanoSeconds = 1; } message TCustomAction { - string Name = 1; + string Name = 1; repeated string Opts = 2; } enum EStatementType { - ST_MOV = 0; - ST_ADD = 1; - ST_SUB = 2; - ST_MUL = 3; - ST_DIV = 4; - ST_MOD = 5; - ST_ADD_EQ = 6; - ST_SUB_EQ = 7; - ST_INC = 8; - ST_DEC = 9; + ST_MOV = 0; + ST_ADD = 1; + ST_SUB = 2; + ST_MUL = 3; + ST_DIV = 4; + ST_MOD = 5; + ST_ADD_EQ = 6; + ST_SUB_EQ = 7; + ST_INC = 8; + ST_DEC = 9; } message TStatementAction { - EStatementType Type = 1; + EStatementType Type = 1; repeated TArgument Argument = 2; } message TRunLogShuttleAction { - bool Ignore = 1; - uint64 ShuttlesCount = 2; - uint64 MaxTrackLength = 3; + bool Ignore = 1; + uint64 ShuttlesCount = 2; + uint64 MaxTrackLength = 3; } message TEditLogShuttleAction { - bool Ignore = 1; + bool Ignore = 1; } message TDropLogShuttleAction { } message TAction { - TLogAction LogAction = 2; - TPrintToStderrAction PrintToStderrAction = 3; - TCustomAction CustomAction = 4; - TKillAction KillAction = 6; - TSleepAction SleepAction = 7; - TStatementAction StatementAction = 8; - - TRunLogShuttleAction RunLogShuttleAction = 100; - TEditLogShuttleAction EditLogShuttleAction = 101; - TDropLogShuttleAction DropLogShuttleAction = 102; + TLogAction LogAction = 2; + TPrintToStderrAction PrintToStderrAction = 3; + TCustomAction CustomAction = 4; + TKillAction KillAction = 6; + TSleepAction SleepAction = 7; + TStatementAction StatementAction = 8; + + TRunLogShuttleAction RunLogShuttleAction = 100; + TEditLogShuttleAction EditLogShuttleAction = 101; + TDropLogShuttleAction DropLogShuttleAction = 102; } message TBlock { - TProbeDesc ProbeDesc = 1; - TPredicate Predicate = 2; + TProbeDesc ProbeDesc = 1; + TPredicate Predicate = 2; repeated TAction Action = 3; } message TQuery { // Number of events to hold for every thread in cyclic buffer // (Won't be used if LogDurationUs is set to non-zero value) - uint32 PerThreadLogSize = 1; + uint32 PerThreadLogSize = 1; // Hold events for last Duration microseconds // (If zero, than per-thread cyclic buffer will be used to store events) - uint64 LogDurationUs = 2; + uint64 LogDurationUs = 2; repeated TBlock Blocks = 3; } @@ -153,114 +153,114 @@ enum EParamTypePb { } message TEventPb { - string Name = 1; + string Name = 1; repeated string Groups = 2; // First group is provider repeated EParamTypePb ParamTypes = 3; repeated string ParamNames = 4; } message TLogItemPb { - uint64 Thread = 1; - string Name = 2; - string Provider = 3; + uint64 Thread = 1; + string Name = 2; + string Provider = 3; repeated bytes Params = 4; - uint64 Timestamp = 5; // microseconds since epoch - uint64 TimestampCycles = 6; // cycles since machine boot + uint64 Timestamp = 5; // microseconds since epoch + uint64 TimestampCycles = 6; // cycles since machine boot } message TThreadLogPb { - uint64 ThreadId = 1; + uint64 ThreadId = 1; repeated TLogItemPb LogItems = 2; } message TLogPb { // Trace info - string Name = 1; - string Description = 2; - uint64 EventsCount = 3; - uint64 CrtTime = 4; // Log creation time (seconds since epoch) + string Name = 1; + string Description = 2; + uint64 EventsCount = 3; + uint64 CrtTime = 4; // Log creation time (seconds since epoch) // Traced host info - string Hostname = 101; + string Hostname = 101; // Traced process info - string ProcessName = 201; + string ProcessName = 201; bytes CommandLine = 202; - uint64 ProcessStartTime = 203; - uint64 Pid = 204; - string VersionInfo = 205; // Svn info + uint64 ProcessStartTime = 203; + uint64 Pid = 204; + string VersionInfo = 205; // Svn info // Trace query and results - TQuery Query = 301; + TQuery Query = 301; repeated TEventPb Events = 302; repeated TThreadLogPb ThreadLogs = 303; } message TShuttlePb { repeated TLogPb Parts = 1; - TQuery Query = 2; + TQuery Query = 2; } message TOrbitPb { repeated TShuttlePb Shuttles = 1; } - -//////////////////////////////////////////////////////////////////////////////// -// Trace parameter. - -message TTraceParam -{ - // Value. - oneof Value - { - int64 IntValue = 2; - uint64 UintValue = 3; - double DoubleValue = 4; + +//////////////////////////////////////////////////////////////////////////////// +// Trace parameter. + +message TTraceParam +{ + // Value. + oneof Value + { + int64 IntValue = 2; + uint64 UintValue = 3; + double DoubleValue = 4; bytes StrValue = 5; - } -} - -//////////////////////////////////////////////////////////////////////////////// -// Trace Event . - -message TTraceEvent -{ - // Probe name. - string Name = 1; - - // Provider name. - string Provider = 2; - - // Probe parameters. - repeated TTraceParam Params = 3; - - // Event timestamp in nanosec since epoch. - uint64 TimestampNanosec = 4; -} - -//////////////////////////////////////////////////////////////////////////////// -// Shuttle trace . - -message TShuttleTrace -{ - // Request events. - repeated TTraceEvent Events = 1; -} - -//////////////////////////////////////////////////////////////////////////////// -// Trace request. - -message TTraceRequest -{ - // trace id of remote trace session - bool IsTraced = 1; -} - -//////////////////////////////////////////////////////////////////////////////// -// Trace response. - -message TTraceResponse -{ - // traced events - TShuttleTrace Trace = 1; -} + } +} + +//////////////////////////////////////////////////////////////////////////////// +// Trace Event . + +message TTraceEvent +{ + // Probe name. + string Name = 1; + + // Provider name. + string Provider = 2; + + // Probe parameters. + repeated TTraceParam Params = 3; + + // Event timestamp in nanosec since epoch. + uint64 TimestampNanosec = 4; +} + +//////////////////////////////////////////////////////////////////////////////// +// Shuttle trace . + +message TShuttleTrace +{ + // Request events. + repeated TTraceEvent Events = 1; +} + +//////////////////////////////////////////////////////////////////////////////// +// Trace request. + +message TTraceRequest +{ + // trace id of remote trace session + bool IsTraced = 1; +} + +//////////////////////////////////////////////////////////////////////////////// +// Trace response. + +message TTraceResponse +{ + // traced events + TShuttleTrace Trace = 1; +} diff --git a/library/cpp/lwtrace/protos/ya.make b/library/cpp/lwtrace/protos/ya.make index cefcadc853..503d5e515f 100644 --- a/library/cpp/lwtrace/protos/ya.make +++ b/library/cpp/lwtrace/protos/ya.make @@ -2,8 +2,8 @@ PROTO_LIBRARY() OWNER(serxa) -INCLUDE_TAGS(GO_PROTO) - +INCLUDE_TAGS(GO_PROTO) + SRCS( lwtrace.proto ) diff --git a/library/cpp/lwtrace/shuttle.h b/library/cpp/lwtrace/shuttle.h index 14bf9e59f4..85c6e4da61 100644 --- a/library/cpp/lwtrace/shuttle.h +++ b/library/cpp/lwtrace/shuttle.h @@ -65,9 +65,9 @@ namespace NLWTrace { AtomicSub(Status, 2); return result; } - } - } - + } + } + template <class F> void UnlessDead(F func) { while (true) { @@ -91,7 +91,7 @@ namespace NLWTrace { } // Returns false iff shuttle should be destroyed - bool AddProbe(TProbe* probe, const TParams& params, ui64 timestamp = 0) { + bool AddProbe(TProbe* probe, const TParams& params, ui64 timestamp = 0) { return UnlessDead([&] { return DoAddProbe(probe, params, timestamp); }, false); @@ -161,10 +161,10 @@ namespace NLWTrace { } protected: - virtual bool DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) = 0; + virtual bool DoAddProbe(TProbe* probe, const TParams& params, ui64 timestamp) = 0; virtual void DoEndOfTrack() = 0; virtual void DoDrop() = 0; - virtual void DoSerialize(TShuttleTrace& msg) = 0; + virtual void DoSerialize(TShuttleTrace& msg) = 0; virtual bool DoFork(TShuttlePtr& child) = 0; virtual bool DoJoin(const TShuttlePtr& child) = 0; }; @@ -227,7 +227,7 @@ namespace NLWTrace { }); } - void AddProbe(TProbe* probe, const TParams& params, ui64 timestamp = 0) { + void AddProbe(TProbe* probe, const TParams& params, ui64 timestamp = 0) { NotConcurrent([&] (TShuttlePtr& head) { TShuttlePtr* ref = &head; while (IShuttle* s = ref->Get()) { @@ -253,14 +253,14 @@ namespace NLWTrace { } }); } - + void Serialize(ui64 traceIdx, TShuttleTrace& msg) { ForEachShuttle(traceIdx, [&] (NLWTrace::IShuttle* shuttle) { - shuttle->Serialize(msg); - return false; - }); - } - + shuttle->Serialize(msg); + return false; + }); + } + bool HasShuttle(ui64 traceIdx) { return NotConcurrent([=] (TShuttlePtr& head) { TShuttlePtr ref = head; @@ -270,10 +270,10 @@ namespace NLWTrace { } else { ref = s->GetNext(); } - } + } return false; }); - } + } bool Fork(TOrbit& child) { return NotConcurrent([&] (TShuttlePtr& head) { diff --git a/library/cpp/lwtrace/signature.h b/library/cpp/lwtrace/signature.h index f5415998a9..868bd9bcf2 100644 --- a/library/cpp/lwtrace/signature.h +++ b/library/cpp/lwtrace/signature.h @@ -14,8 +14,8 @@ #include <google/protobuf/descriptor.h> #include <google/protobuf/generated_enum_reflection.h> -#include <library/cpp/lwtrace/protos/lwtrace.pb.h> - +#include <library/cpp/lwtrace/protos/lwtrace.pb.h> + #include <type_traits> namespace NLWTrace { @@ -390,8 +390,8 @@ namespace NLWTrace { TParam Param[LWTRACE_MAX_PARAMS]; }; - using TSerializedParams = google::protobuf::RepeatedPtrField<NLWTrace::TTraceParam>; - + using TSerializedParams = google::protobuf::RepeatedPtrField<NLWTrace::TTraceParam>; + // Represents a common class for all function "signatures" (parameter types and names). // Provides non-virtual interface to handle the signature and (emulated) virtual interface to handle TParams corresponding to the signature struct TSignature { @@ -403,8 +403,8 @@ namespace NLWTrace { void (*SerializeParamsFunc)(const TParams& params, TString* values); void (*CloneParamsFunc)(TParams& newParams, const TParams& oldParams); void (*DestroyParamsFunc)(TParams& params); - void (*SerializeToPbFunc)(const TParams& params, TSerializedParams& arr); - bool (*DeserializeFromPbFunc)(TParams& params, const TSerializedParams& arr); + void (*SerializeToPbFunc)(const TParams& params, TSerializedParams& arr); + bool (*DeserializeFromPbFunc)(TParams& params, const TSerializedParams& arr); // Virtual calls emulation void SerializeParams(const TParams& params, TString* values) const { @@ -419,16 +419,16 @@ namespace NLWTrace { (*DestroyParamsFunc)(params); } - void SerializeToPb(const TParams& params, TSerializedParams& arr) const - { - (*SerializeToPbFunc)(params, arr); - } - - bool DeserializeFromPb(TParams& params, const TSerializedParams& arr) const - { - return (*DeserializeFromPbFunc)(params, arr); - } - + void SerializeToPb(const TParams& params, TSerializedParams& arr) const + { + (*SerializeToPbFunc)(params, arr); + } + + bool DeserializeFromPb(TParams& params, const TSerializedParams& arr) const + { + return (*DeserializeFromPbFunc)(params, arr); + } + void ToProtobuf(TEventPb& pb) const; size_t FindParamIndex(const TString& param) const { @@ -564,118 +564,118 @@ namespace NLWTrace { } }; - inline EParamTypePb ParamTypeToProtobuf(const char* paramType) { -#define FOREACH_PARAMTYPE_MACRO(n, t, v) \ - if (strcmp(paramType, n) == 0) { \ - return PT_##v; \ - } \ - /**/ - FOREACH_PARAMTYPE(FOREACH_PARAMTYPE_MACRO) -#undef FOREACH_PARAMTYPE_MACRO - return PT_UNKNOWN; - } - - template <typename T> - inline void SaveParamToPb(TSerializedParams& msg, const TParam& param); - - template <> - inline void SaveParamToPb<TNil>(TSerializedParams& msg, const TParam& param) - { - Y_UNUSED(msg); - Y_UNUSED(param); - } - - template <> - inline void SaveParamToPb<i64>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetIntValue(param.Get<typename TParamTraits<i64>::TStoreType>()); - } - - template <> - inline void SaveParamToPb<ui64>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetUintValue(param.Get<typename TParamTraits<ui64>::TStoreType>()); - } - - template <> - inline void SaveParamToPb<double>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetDoubleValue(param.Get<typename TParamTraits<double>::TStoreType>()); - } - - template <> - inline void SaveParamToPb<TString>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetStrValue(param.Get<typename TParamTraits<TString>::TStoreType>()); - } - - template <> - inline void SaveParamToPb<TSymbol>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetStrValue(*param.Get<typename TParamTraits<TSymbol>::TStoreType>().Str); - } - - template <> - inline void SaveParamToPb<TCheck>(TSerializedParams& msg, const TParam& param) - { - msg.Add()->SetIntValue(param.Get<typename TParamTraits<TCheck>::TStoreType>().Value); - } - - template <typename T> - inline void LoadParamFromPb(const TTraceParam& msg, TParam& param); - - template <> - inline void LoadParamFromPb<i64>(const TTraceParam& msg, TParam& param) - { - param.DefaultConstruct<i64>(); - param.Get<i64>() = msg.GetIntValue(); - } - - template <> - inline void LoadParamFromPb<ui64>(const TTraceParam& msg, TParam& param) - { - param.DefaultConstruct<ui64>(); - param.Get<ui64>() = msg.GetUintValue(); - } - - template <> - inline void LoadParamFromPb<double>(const TTraceParam& msg, TParam& param) - { - param.DefaultConstruct<double>(); - param.Get<double>() = msg.GetDoubleValue(); - } - - template <> - inline void LoadParamFromPb<TCheck>(const TTraceParam& msg, TParam& param) - { - param.CopyConstruct<TCheck>(TCheck(msg.GetIntValue())); - } - - template <> - inline void LoadParamFromPb<TSymbol>(const TTraceParam& msg, TParam& param) - { - Y_UNUSED(msg); - Y_UNUSED(param); - static TString unsupported("unsupported"); - // so far TSymbol deserialization is not supported - // since it is not used for probes, it is ok - param.CopyConstruct<TSymbol>(TSymbol(&unsupported)); - } - - template <> - inline void LoadParamFromPb<TString>(const TTraceParam& msg, TParam& param) - { - param.DefaultConstruct<TString>(); - param.Get<TString>() = msg.GetStrValue(); - } - - template <> - inline void LoadParamFromPb<TNil>(const TTraceParam& msg, TParam& param) - { - Y_UNUSED(msg); - Y_UNUSED(param); - } - + inline EParamTypePb ParamTypeToProtobuf(const char* paramType) { +#define FOREACH_PARAMTYPE_MACRO(n, t, v) \ + if (strcmp(paramType, n) == 0) { \ + return PT_##v; \ + } \ + /**/ + FOREACH_PARAMTYPE(FOREACH_PARAMTYPE_MACRO) +#undef FOREACH_PARAMTYPE_MACRO + return PT_UNKNOWN; + } + + template <typename T> + inline void SaveParamToPb(TSerializedParams& msg, const TParam& param); + + template <> + inline void SaveParamToPb<TNil>(TSerializedParams& msg, const TParam& param) + { + Y_UNUSED(msg); + Y_UNUSED(param); + } + + template <> + inline void SaveParamToPb<i64>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetIntValue(param.Get<typename TParamTraits<i64>::TStoreType>()); + } + + template <> + inline void SaveParamToPb<ui64>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetUintValue(param.Get<typename TParamTraits<ui64>::TStoreType>()); + } + + template <> + inline void SaveParamToPb<double>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetDoubleValue(param.Get<typename TParamTraits<double>::TStoreType>()); + } + + template <> + inline void SaveParamToPb<TString>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetStrValue(param.Get<typename TParamTraits<TString>::TStoreType>()); + } + + template <> + inline void SaveParamToPb<TSymbol>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetStrValue(*param.Get<typename TParamTraits<TSymbol>::TStoreType>().Str); + } + + template <> + inline void SaveParamToPb<TCheck>(TSerializedParams& msg, const TParam& param) + { + msg.Add()->SetIntValue(param.Get<typename TParamTraits<TCheck>::TStoreType>().Value); + } + + template <typename T> + inline void LoadParamFromPb(const TTraceParam& msg, TParam& param); + + template <> + inline void LoadParamFromPb<i64>(const TTraceParam& msg, TParam& param) + { + param.DefaultConstruct<i64>(); + param.Get<i64>() = msg.GetIntValue(); + } + + template <> + inline void LoadParamFromPb<ui64>(const TTraceParam& msg, TParam& param) + { + param.DefaultConstruct<ui64>(); + param.Get<ui64>() = msg.GetUintValue(); + } + + template <> + inline void LoadParamFromPb<double>(const TTraceParam& msg, TParam& param) + { + param.DefaultConstruct<double>(); + param.Get<double>() = msg.GetDoubleValue(); + } + + template <> + inline void LoadParamFromPb<TCheck>(const TTraceParam& msg, TParam& param) + { + param.CopyConstruct<TCheck>(TCheck(msg.GetIntValue())); + } + + template <> + inline void LoadParamFromPb<TSymbol>(const TTraceParam& msg, TParam& param) + { + Y_UNUSED(msg); + Y_UNUSED(param); + static TString unsupported("unsupported"); + // so far TSymbol deserialization is not supported + // since it is not used for probes, it is ok + param.CopyConstruct<TSymbol>(TSymbol(&unsupported)); + } + + template <> + inline void LoadParamFromPb<TString>(const TTraceParam& msg, TParam& param) + { + param.DefaultConstruct<TString>(); + param.Get<TString>() = msg.GetStrValue(); + } + + template <> + inline void LoadParamFromPb<TNil>(const TTraceParam& msg, TParam& param) + { + Y_UNUSED(msg); + Y_UNUSED(param); + } + // Class representing a specific signature template <LWTRACE_TEMPLATE_PARAMS> struct TUserSignature { @@ -705,42 +705,42 @@ namespace NLWTrace { FOREACH_PARAMNUM(FOREACH_PARAMNUM_MACRO); #undef FOREACH_PARAMNUM_MACRO } - - // Implementation of virtual function (TSignature derived classes vtable emulation) - inline static void SerializeToPb(const TParams& params, TSerializedParams& arr) - { -#define FOREACH_PARAMNUM_MACRO(i) \ - SaveParamToPb<typename TParamTraits<TP##i>::TStoreType>( \ - arr, \ - params.Param[i]); \ -// FOREACH_PARAMNUM_MACRO - FOREACH_PARAMNUM(FOREACH_PARAMNUM_MACRO); -#undef FOREACH_PARAMNUM_MACRO - } - - // Implementation of virtual function (TSignature derived classes vtable emulation) - inline static bool DeserializeFromPb(TParams& params, const TSerializedParams& arr) { - if (arr.size() != ParamCount) { - return false; - } - if (!ParamCount) { - return true; - } - - int paramIdx = 0; -#define FOREACH_PARAMNUM_MACRO(i) \ - if (paramIdx >= arr.size()) { \ - return true; \ - }; \ - LoadParamFromPb<typename TParamTraits<TP##i>::TStoreType>( \ - arr.Get(paramIdx), \ - params.Param[paramIdx]); \ - ++paramIdx; \ -// FOREACH_PARAMNUM_MACRO - FOREACH_PARAMNUM(FOREACH_PARAMNUM_MACRO); -#undef FOREACH_PARAMNUM_MACRO - return true; - } + + // Implementation of virtual function (TSignature derived classes vtable emulation) + inline static void SerializeToPb(const TParams& params, TSerializedParams& arr) + { +#define FOREACH_PARAMNUM_MACRO(i) \ + SaveParamToPb<typename TParamTraits<TP##i>::TStoreType>( \ + arr, \ + params.Param[i]); \ +// FOREACH_PARAMNUM_MACRO + FOREACH_PARAMNUM(FOREACH_PARAMNUM_MACRO); +#undef FOREACH_PARAMNUM_MACRO + } + + // Implementation of virtual function (TSignature derived classes vtable emulation) + inline static bool DeserializeFromPb(TParams& params, const TSerializedParams& arr) { + if (arr.size() != ParamCount) { + return false; + } + if (!ParamCount) { + return true; + } + + int paramIdx = 0; +#define FOREACH_PARAMNUM_MACRO(i) \ + if (paramIdx >= arr.size()) { \ + return true; \ + }; \ + LoadParamFromPb<typename TParamTraits<TP##i>::TStoreType>( \ + arr.Get(paramIdx), \ + params.Param[paramIdx]); \ + ++paramIdx; \ +// FOREACH_PARAMNUM_MACRO + FOREACH_PARAMNUM(FOREACH_PARAMNUM_MACRO); +#undef FOREACH_PARAMNUM_MACRO + return true; + } }; // Array of static strings pointers for names of parameter types in a specific signature diff --git a/library/cpp/lwtrace/trace.cpp b/library/cpp/lwtrace/trace.cpp index 1aee64a16f..3c974c85a0 100644 --- a/library/cpp/lwtrace/trace.cpp +++ b/library/cpp/lwtrace/trace.cpp @@ -432,9 +432,9 @@ namespace NLWTrace { public: TLogActionExecutor(TProbe* probe, const TLogAction& action, TLog* log) - : LogParams(!action.GetDoNotLogParams()) + : LogParams(!action.GetDoNotLogParams()) , LogTimestamp(action.GetLogTimestamp()) - , MaxRecords(action.GetMaxRecords() ? new intptr_t(action.GetMaxRecords()) : nullptr) + , MaxRecords(action.GetMaxRecords() ? new intptr_t(action.GetMaxRecords()) : nullptr) , Records(0) , Probe(probe) , Log(log) @@ -475,11 +475,11 @@ namespace NLWTrace { const TArgument& arg = op.GetArgument(argumentIdx); TArgumentDescription operand; operand.ParamIdx = size_t(-1); - if (arg.GetVariable()) { + if (arg.GetVariable()) { operand.Type = OT_VARIABLE; - } else if (arg.GetValue()) { + } else if (arg.GetValue()) { operand.Type = OT_LITERAL; - } else if (arg.GetParam()) { + } else if (arg.GetParam()) { operand.Type = OT_PARAMETER; operand.ParamIdx = signature.FindParamIndex(arg.GetParam()); if (operand.ParamIdx == size_t(-1)) { @@ -672,7 +672,7 @@ namespace NLWTrace { } else if (action.HasSleepAction()) { if (destructiveActionsAllowed) { const TSleepAction& sleepAction = action.GetSleepAction(); - if (sleepAction.GetNanoSeconds()) { + if (sleepAction.GetNanoSeconds()) { ui64 nanoSeconds = sleepAction.GetNanoSeconds(); actExec.Reset(new NPrivate::TSleepActionExecutor(probe, nanoSeconds)); } else { @@ -858,9 +858,9 @@ namespace NLWTrace { , Registry(registry) , StoreDuration(TDuration::MicroSeconds(query.GetLogDurationUs() * 11 / 10)) // +10% to try avoid truncation while reading multiple threads/traces , ReadDuration(TDuration::MicroSeconds(query.GetLogDurationUs())) - , CyclicLog(query.GetPerThreadLogSize() ? query.GetPerThreadLogSize() : 1000) + , CyclicLog(query.GetPerThreadLogSize() ? query.GetPerThreadLogSize() : 1000) , DurationLog(StoreDuration) - , CyclicDepot(query.GetPerThreadLogSize() ? query.GetPerThreadLogSize() : 1000) + , CyclicDepot(query.GetPerThreadLogSize() ? query.GetPerThreadLogSize() : 1000) , DurationDepot(StoreDuration) , LastTrackId(0) , LastSpanId(0) @@ -879,7 +879,7 @@ namespace NLWTrace { ythrow yexception() << "block #" << bi + 1 << " has no action"; } const NProtoBuf::RepeatedPtrField<TAction>& actions = block.action(); - if (pdesc.GetName() && pdesc.GetProvider()) { + if (pdesc.GetName() && pdesc.GetProvider()) { TProbeRegistry::TProbesAccessor probes(Registry); bool found = false; for (auto& kv : probes) { @@ -894,7 +894,7 @@ namespace NLWTrace { ythrow yexception() << "block #" << bi + 1 << " has no matching probe with name '" << pdesc.GetName() << "' provider '" << pdesc.GetProvider() << "'"; } - } else if (pdesc.GetGroup()) { + } else if (pdesc.GetGroup()) { bool found = false; TProbeRegistry::TProbesAccessor probes(Registry); for (auto& kv : probes) { diff --git a/library/cpp/lwtrace/trace_ut.cpp b/library/cpp/lwtrace/trace_ut.cpp index 5e1256585e..cb03e4fbde 100644 --- a/library/cpp/lwtrace/trace_ut.cpp +++ b/library/cpp/lwtrace/trace_ut.cpp @@ -16,17 +16,17 @@ enum class EEnumClass { ValueD, }; -#define LWTRACE_UT_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \ - PROBE(NoParam, GROUPS("Group"), TYPES(), NAMES()) \ - PROBE(IntParam, GROUPS("Group"), TYPES(ui32), NAMES("value")) \ - PROBE(StringParam, GROUPS("Group"), TYPES(TString), NAMES("value")) \ - PROBE(SymbolParam, GROUPS("Group"), TYPES(NLWTrace::TSymbol), NAMES("symbol")) \ - PROBE(CheckParam, GROUPS("Group"), TYPES(NLWTrace::TCheck), NAMES("value")) \ +#define LWTRACE_UT_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \ + PROBE(NoParam, GROUPS("Group"), TYPES(), NAMES()) \ + PROBE(IntParam, GROUPS("Group"), TYPES(ui32), NAMES("value")) \ + PROBE(StringParam, GROUPS("Group"), TYPES(TString), NAMES("value")) \ + PROBE(SymbolParam, GROUPS("Group"), TYPES(NLWTrace::TSymbol), NAMES("symbol")) \ + PROBE(CheckParam, GROUPS("Group"), TYPES(NLWTrace::TCheck), NAMES("value")) \ PROBE(EnumParams, GROUPS("Group"), TYPES(ESimpleEnum, EEnumClass), NAMES("simpleEnum", "enumClass")) \ - PROBE(InstantParam, GROUPS("Group"), TYPES(TInstant), NAMES("value")) \ - PROBE(DurationParam, GROUPS("Group"), TYPES(TDuration), NAMES("value")) \ - PROBE(ProtoEnum, GROUPS("Group"), TYPES(NLWTrace::EOperatorType), NAMES("value")) \ - PROBE(IntIntParams, GROUPS("Group"), TYPES(ui32, ui64), NAMES("value1", "value2")) \ + PROBE(InstantParam, GROUPS("Group"), TYPES(TInstant), NAMES("value")) \ + PROBE(DurationParam, GROUPS("Group"), TYPES(TDuration), NAMES("value")) \ + PROBE(ProtoEnum, GROUPS("Group"), TYPES(NLWTrace::EOperatorType), NAMES("value")) \ + PROBE(IntIntParams, GROUPS("Group"), TYPES(ui32, ui64), NAMES("value1", "value2")) \ /**/ LWTRACE_DECLARE_PROVIDER(LWTRACE_UT_PROVIDER) @@ -546,7 +546,7 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { using TPbEnumTraits = TParamTraits<EOperatorType>; TString str; TPbEnumTraits::ToString(TPbEnumTraits::ToStoreType(OT_EQ), &str); - UNIT_ASSERT_STRINGS_EQUAL(str, "OT_EQ (0)"); + UNIT_ASSERT_STRINGS_EQUAL(str, "OT_EQ (0)"); } Y_UNIT_TEST(Track) { @@ -581,164 +581,164 @@ Y_UNIT_TEST_SUITE(LWTraceTrace) { } reader; mngr.ReadDepot("Query1", reader); } - - Y_UNIT_TEST(ShouldSerializeTracks) - { - TManager manager(*Singleton<TProbeRegistry>(), false); - - TOrbit orbit; - TTraceRequest req; - req.SetIsTraced(true); - manager.HandleTraceRequest(req, orbit); - - LWTRACK(NoParam, orbit); - LWTRACK(IntParam, orbit, 1); - LWTRACK(StringParam, orbit, "str"); - LWTRACK(EnumParams, orbit, ValueA, EEnumClass::ValueC); - LWTRACK(InstantParam, orbit, TInstant::Seconds(42)); - LWTRACK(DurationParam, orbit, TDuration::MilliSeconds(146)); + + Y_UNIT_TEST(ShouldSerializeTracks) + { + TManager manager(*Singleton<TProbeRegistry>(), false); + + TOrbit orbit; + TTraceRequest req; + req.SetIsTraced(true); + manager.HandleTraceRequest(req, orbit); + + LWTRACK(NoParam, orbit); + LWTRACK(IntParam, orbit, 1); + LWTRACK(StringParam, orbit, "str"); + LWTRACK(EnumParams, orbit, ValueA, EEnumClass::ValueC); + LWTRACK(InstantParam, orbit, TInstant::Seconds(42)); + LWTRACK(DurationParam, orbit, TDuration::MilliSeconds(146)); LWTRACK(ProtoEnum, orbit, OT_EQ); - LWTRACK(IntIntParams, orbit, 1, 2); - - TTraceResponse resp; - orbit.Serialize(0, *resp.MutableTrace()); - auto& r = resp.GetTrace(); - - UNIT_ASSERT_VALUES_EQUAL(8, r.EventsSize()); - - const auto& p0 = r.GetEvents(0); - UNIT_ASSERT_VALUES_EQUAL("NoParam", p0.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p0.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL(0 , p0.ParamsSize()); - - const auto& p1 = r.GetEvents(1); - UNIT_ASSERT_VALUES_EQUAL("IntParam", p1.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p1.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL(1, p1.GetParams(0).GetUintValue()); - - const auto& p2 = r.GetEvents(2); - UNIT_ASSERT_VALUES_EQUAL("StringParam", p2.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p2.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL("str", p2.GetParams(0).GetStrValue()); - - const auto& p3 = r.GetEvents(3); - UNIT_ASSERT_VALUES_EQUAL("EnumParams", p3.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p3.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL((ui32)ValueA, p3.GetParams(0).GetIntValue()); - UNIT_ASSERT_VALUES_EQUAL((ui32)EEnumClass::ValueC, p3.GetParams(1).GetIntValue()); - - const auto& p4 = r.GetEvents(4); - UNIT_ASSERT_VALUES_EQUAL("InstantParam", p4.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p4.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL(42, p4.GetParams(0).GetDoubleValue()); - - const auto& p5 = r.GetEvents(5); - UNIT_ASSERT_VALUES_EQUAL("DurationParam", p5.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p5.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL(146, p5.GetParams(0).GetDoubleValue()); - - const auto& p6 = r.GetEvents(6); - UNIT_ASSERT_VALUES_EQUAL("ProtoEnum", p6.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p6.GetProvider()); + LWTRACK(IntIntParams, orbit, 1, 2); + + TTraceResponse resp; + orbit.Serialize(0, *resp.MutableTrace()); + auto& r = resp.GetTrace(); + + UNIT_ASSERT_VALUES_EQUAL(8, r.EventsSize()); + + const auto& p0 = r.GetEvents(0); + UNIT_ASSERT_VALUES_EQUAL("NoParam", p0.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p0.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL(0 , p0.ParamsSize()); + + const auto& p1 = r.GetEvents(1); + UNIT_ASSERT_VALUES_EQUAL("IntParam", p1.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p1.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL(1, p1.GetParams(0).GetUintValue()); + + const auto& p2 = r.GetEvents(2); + UNIT_ASSERT_VALUES_EQUAL("StringParam", p2.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p2.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL("str", p2.GetParams(0).GetStrValue()); + + const auto& p3 = r.GetEvents(3); + UNIT_ASSERT_VALUES_EQUAL("EnumParams", p3.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p3.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL((ui32)ValueA, p3.GetParams(0).GetIntValue()); + UNIT_ASSERT_VALUES_EQUAL((ui32)EEnumClass::ValueC, p3.GetParams(1).GetIntValue()); + + const auto& p4 = r.GetEvents(4); + UNIT_ASSERT_VALUES_EQUAL("InstantParam", p4.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p4.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL(42, p4.GetParams(0).GetDoubleValue()); + + const auto& p5 = r.GetEvents(5); + UNIT_ASSERT_VALUES_EQUAL("DurationParam", p5.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p5.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL(146, p5.GetParams(0).GetDoubleValue()); + + const auto& p6 = r.GetEvents(6); + UNIT_ASSERT_VALUES_EQUAL("ProtoEnum", p6.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p6.GetProvider()); UNIT_ASSERT_VALUES_EQUAL((int)OT_EQ, p6.GetParams(0).GetIntValue()); - - const auto& p7 = r.GetEvents(7); - UNIT_ASSERT_VALUES_EQUAL("IntIntParams", p7.GetName()); - UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p7.GetProvider()); - UNIT_ASSERT_VALUES_EQUAL(1, p7.GetParams(0).GetUintValue()); - UNIT_ASSERT_VALUES_EQUAL(2, p7.GetParams(1).GetUintValue()); - } - - Y_UNIT_TEST(ShouldDeserializeTracks) - { - TManager manager(*Singleton<TProbeRegistry>(), false); - - TTraceResponse resp; - auto& r = *resp.MutableTrace()->MutableEvents(); - - auto& p0 = *r.Add(); - p0.SetName("NoParam"); - p0.SetProvider("LWTRACE_UT_PROVIDER"); - - auto& p1 = *r.Add(); - p1.SetName("IntParam"); - p1.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p1param = *p1.MutableParams()->Add(); - p1param.SetUintValue(1); - - auto& p2 = *r.Add(); - p2.SetName("StringParam"); - p2.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p2param = *p2.MutableParams()->Add(); - p2param.SetStrValue("str"); - - auto& p3 = *r.Add(); - p3.SetName("EnumParams"); - p3.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p3param1 = *p3.MutableParams()->Add(); - p3param1.SetUintValue((ui64)EEnumClass::ValueC); - auto& p3param2 = *p3.MutableParams()->Add(); - p3param2.SetIntValue((ui64)EEnumClass::ValueC); - - auto& p4 = *r.Add(); - p4.SetName("InstantParam"); - p4.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p4param = *p4.MutableParams()->Add(); - p4param.SetDoubleValue(42); - - auto& p5 = *r.Add(); - p5.SetName("DurationParam"); - p5.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p5param = *p5.MutableParams()->Add(); - p5param.SetDoubleValue(146); - - auto& p6 = *r.Add(); - p6.SetName("ProtoEnum"); - p6.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p6param = *p6.MutableParams()->Add(); + + const auto& p7 = r.GetEvents(7); + UNIT_ASSERT_VALUES_EQUAL("IntIntParams", p7.GetName()); + UNIT_ASSERT_VALUES_EQUAL("LWTRACE_UT_PROVIDER", p7.GetProvider()); + UNIT_ASSERT_VALUES_EQUAL(1, p7.GetParams(0).GetUintValue()); + UNIT_ASSERT_VALUES_EQUAL(2, p7.GetParams(1).GetUintValue()); + } + + Y_UNIT_TEST(ShouldDeserializeTracks) + { + TManager manager(*Singleton<TProbeRegistry>(), false); + + TTraceResponse resp; + auto& r = *resp.MutableTrace()->MutableEvents(); + + auto& p0 = *r.Add(); + p0.SetName("NoParam"); + p0.SetProvider("LWTRACE_UT_PROVIDER"); + + auto& p1 = *r.Add(); + p1.SetName("IntParam"); + p1.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p1param = *p1.MutableParams()->Add(); + p1param.SetUintValue(1); + + auto& p2 = *r.Add(); + p2.SetName("StringParam"); + p2.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p2param = *p2.MutableParams()->Add(); + p2param.SetStrValue("str"); + + auto& p3 = *r.Add(); + p3.SetName("EnumParams"); + p3.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p3param1 = *p3.MutableParams()->Add(); + p3param1.SetUintValue((ui64)EEnumClass::ValueC); + auto& p3param2 = *p3.MutableParams()->Add(); + p3param2.SetIntValue((ui64)EEnumClass::ValueC); + + auto& p4 = *r.Add(); + p4.SetName("InstantParam"); + p4.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p4param = *p4.MutableParams()->Add(); + p4param.SetDoubleValue(42); + + auto& p5 = *r.Add(); + p5.SetName("DurationParam"); + p5.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p5param = *p5.MutableParams()->Add(); + p5param.SetDoubleValue(146); + + auto& p6 = *r.Add(); + p6.SetName("ProtoEnum"); + p6.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p6param = *p6.MutableParams()->Add(); p6param.SetIntValue((i64)OT_EQ); - - auto& p7 = *r.Add(); - p7.SetName("IntIntParams"); - p7.SetProvider("LWTRACE_UT_PROVIDER"); - auto& p7param1 = *p7.MutableParams()->Add(); - p7param1.SetIntValue(1); - auto& p7param2 = *p7.MutableParams()->Add(); - p7param2.SetIntValue(2); - - TOrbit orbit; - UNIT_ASSERT_VALUES_EQUAL( - manager.HandleTraceResponse(resp, manager.GetProbesMap(), orbit).IsSuccess, - true); - } - - Y_UNIT_TEST(ShouldDeserializeWhatSerialized) - { - TManager manager(*Singleton<TProbeRegistry>(), false); - - TOrbit orbit; - TTraceRequest req; - req.SetIsTraced(true); - manager.HandleTraceRequest(req, orbit); - - LWTRACK(NoParam, orbit); - LWTRACK(IntParam, orbit, 1); - LWTRACK(StringParam, orbit, "str"); - LWTRACK(EnumParams, orbit, ValueA, EEnumClass::ValueC); - LWTRACK(InstantParam, orbit, TInstant::Seconds(42)); - LWTRACK(DurationParam, orbit, TDuration::MilliSeconds(146)); + + auto& p7 = *r.Add(); + p7.SetName("IntIntParams"); + p7.SetProvider("LWTRACE_UT_PROVIDER"); + auto& p7param1 = *p7.MutableParams()->Add(); + p7param1.SetIntValue(1); + auto& p7param2 = *p7.MutableParams()->Add(); + p7param2.SetIntValue(2); + + TOrbit orbit; + UNIT_ASSERT_VALUES_EQUAL( + manager.HandleTraceResponse(resp, manager.GetProbesMap(), orbit).IsSuccess, + true); + } + + Y_UNIT_TEST(ShouldDeserializeWhatSerialized) + { + TManager manager(*Singleton<TProbeRegistry>(), false); + + TOrbit orbit; + TTraceRequest req; + req.SetIsTraced(true); + manager.HandleTraceRequest(req, orbit); + + LWTRACK(NoParam, orbit); + LWTRACK(IntParam, orbit, 1); + LWTRACK(StringParam, orbit, "str"); + LWTRACK(EnumParams, orbit, ValueA, EEnumClass::ValueC); + LWTRACK(InstantParam, orbit, TInstant::Seconds(42)); + LWTRACK(DurationParam, orbit, TDuration::MilliSeconds(146)); LWTRACK(ProtoEnum, orbit, OT_EQ); - LWTRACK(IntIntParams, orbit, 1, 2); - - TTraceResponse resp; - auto& r = *resp.MutableTrace(); - orbit.Serialize(0, r); - - TOrbit orbit1; - UNIT_ASSERT_VALUES_EQUAL( - manager.HandleTraceResponse(resp, manager.GetProbesMap(), orbit1).IsSuccess, - true); - } + LWTRACK(IntIntParams, orbit, 1, 2); + + TTraceResponse resp; + auto& r = *resp.MutableTrace(); + orbit.Serialize(0, r); + + TOrbit orbit1; + UNIT_ASSERT_VALUES_EQUAL( + manager.HandleTraceResponse(resp, manager.GetProbesMap(), orbit1).IsSuccess, + true); + } Y_UNIT_TEST(TrackForkJoin) { TManager mngr(*Singleton<TProbeRegistry>(), true); diff --git a/library/cpp/lwtrace/ya.make b/library/cpp/lwtrace/ya.make index d863638b7d..d9accb3006 100644 --- a/library/cpp/lwtrace/ya.make +++ b/library/cpp/lwtrace/ya.make @@ -8,7 +8,7 @@ PEERDIR( SRCS( check.cpp - control.cpp + control.cpp custom_action.cpp kill_action.cpp log_shuttle.cpp @@ -23,7 +23,7 @@ SRCS( ) END() - + RECURSE(mon) -RECURSE_FOR_TESTS(ut) +RECURSE_FOR_TESTS(ut) diff --git a/ydb/core/base/tablet_types.h b/ydb/core/base/tablet_types.h index 958ce144c9..f585819299 100644 --- a/ydb/core/base/tablet_types.h +++ b/ydb/core/base/tablet_types.h @@ -31,7 +31,7 @@ public: static constexpr EType RTMR_PARTITION = RTMRPartition; static constexpr EType BLOCKSTORE_VOLUME = BlockStoreVolume; static constexpr EType BLOCKSTORE_PARTITION = BlockStorePartition; - static constexpr EType BLOCKSTORE_PARTITION2 = BlockStorePartition2; + static constexpr EType BLOCKSTORE_PARTITION2 = BlockStorePartition2; static constexpr EType BLOCKSTORE_DISK_REGISTRY = BlockStoreDiskRegistry; static constexpr EType TENANT_SLOT_BROKER = TenantSlotBroker; static constexpr EType CONSOLE = Console; diff --git a/ydb/core/driver_lib/run/run.cpp b/ydb/core/driver_lib/run/run.cpp index b03d28f002..a4f74aa4e0 100644 --- a/ydb/core/driver_lib/run/run.cpp +++ b/ydb/core/driver_lib/run/run.cpp @@ -955,8 +955,8 @@ void TKikimrRunner::InitializeLogSettings(const TKikimrRunConfig& runConfig) NKikimrServices::LOGGER, (NActors::NLog::EPriority)logConfig.GetDefaultLevel(), (NActors::NLog::EPriority)logConfig.GetDefaultSamplingLevel(), - logConfig.GetDefaultSamplingRate(), - logConfig.GetTimeThresholdMs())); + logConfig.GetDefaultSamplingRate(), + logConfig.GetTimeThresholdMs())); LogSettings->Append( NActorsServices::EServiceCommon_MIN, diff --git a/ydb/core/protos/blockstore_config.proto b/ydb/core/protos/blockstore_config.proto index e3298d1f14..5cba383bfd 100644 --- a/ydb/core/protos/blockstore_config.proto +++ b/ydb/core/protos/blockstore_config.proto @@ -35,17 +35,17 @@ message TVolumeConfig { optional uint32 Version = 6; // Volume private data - optional string DiskId = 7; - optional string ProjectId = 8; - optional string FolderId = 9; - optional string CloudId = 10; + optional string DiskId = 7; + optional string ProjectId = 8; + optional string FolderId = 9; + optional string CloudId = 10; optional uint32 TabletVersion = 11; // Binary data for private use by BlockStore implementation (legacy, unused) optional bytes Opaque = 12; - - // Volume disk type - optional uint32 StorageMediaKind = 13; + + // Volume disk type + optional uint32 StorageMediaKind = 13; // Performance profile fields, used for correct bs group allocation and iops/bandwidth throttling optional uint32 PerformanceProfileMaxReadBandwidth = 14; @@ -81,9 +81,9 @@ message TVolumeConfig { // Placement group id. optional string PlacementGroupId = 34; - // Tags. Use TagsStr, because we need capability to pass empty set of tags. - optional string TagsStr = 35; // ,-delimited string - repeated string Tags = 36; // array of strings, do not use + // Tags. Use TagsStr, because we need capability to pass empty set of tags. + optional string TagsStr = 35; // ,-delimited string + repeated string Tags = 36; // array of strings, do not use // Block count per stripe. Affects multipartition volumes. optional uint32 BlocksPerStripe = 37; @@ -96,9 +96,9 @@ message TVolumeConfig { // Indicates that volume does not belong to user directly, but used for system needs optional bool IsSystem = 40; - - // Channel descriptions for volume tablets - repeated TChannelProfile VolumeExplicitChannelProfiles = 41; + + // Channel descriptions for volume tablets + repeated TChannelProfile VolumeExplicitChannelProfiles = 41; } message TUpdateVolumeConfig { diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto index 8668fb6317..d64169d4fc 100644 --- a/ydb/core/protos/config.proto +++ b/ydb/core/protos/config.proto @@ -287,7 +287,7 @@ message TLogConfig { optional string SysLogService = 11; optional bool SysLogToStdErr = 12; // writes logs to stderr as well as in syslog optional TUAClientConfig UAClientConfig = 13; - optional uint64 TimeThresholdMs = 14 [default = 1000]; + optional uint64 TimeThresholdMs = 14 [default = 1000]; } message TCompileServiceConfig { diff --git a/ydb/core/protos/counters_schemeshard.proto b/ydb/core/protos/counters_schemeshard.proto index 45ff336aa8..a839915c98 100644 --- a/ydb/core/protos/counters_schemeshard.proto +++ b/ydb/core/protos/counters_schemeshard.proto @@ -63,7 +63,7 @@ enum ESimpleCounters { COUNTER_USER_ATTRIBUTES_COUNT = 50 [(CounterOpts) = {Name: "UserAttributes"}]; COUNTER_IN_FLIGHT_OPS_TxCreateTableIndex = 51 [(CounterOpts) = {Name: "InFlightOps/CreateTableIndex"}]; COUNTER_TABLE_INDEXES_COUNT = 52 [(CounterOpts) = {Name: "TableIndexes"}]; - COUNTER_BLOCKSTORE_PARTITION2_SHARD_COUNT = 53 [(CounterOpts) = {Name: "BlockStorePartition2Shards"}]; + COUNTER_BLOCKSTORE_PARTITION2_SHARD_COUNT = 53 [(CounterOpts) = {Name: "BlockStorePartition2Shards"}]; COUNTER_IN_FLIGHT_OPS_TxDropTableIndex = 54 [(CounterOpts) = {Name: "InFlightOps/DropTableIndex"}]; COUNTER_EXTSUB_DOMAIN_COUNT = 55 [(CounterOpts) = {Name: "ExernalSubDomains"}]; diff --git a/ydb/core/protos/flat_scheme_op.proto b/ydb/core/protos/flat_scheme_op.proto index a2627f2b1a..33e598c1c2 100644 --- a/ydb/core/protos/flat_scheme_op.proto +++ b/ydb/core/protos/flat_scheme_op.proto @@ -945,7 +945,7 @@ message TBlockStoreVolumeDescription { optional uint64 VolumeTabletId = 5; // do not set optional uint64 AlterVersion = 6; // do not set optional string MountToken = 7; // do not set - optional uint64 TokenVersion = 8; // do not set + optional uint64 TokenVersion = 8; // do not set } message TFileStoreDescription { @@ -1005,7 +1005,7 @@ message TAlterSolomonVolume { message TBlockStoreAssignOp { optional string Name = 1; // mandatory optional string NewMountToken = 2; // unset to unassign - optional uint64 TokenVersion = 3; + optional uint64 TokenVersion = 3; } message TModifyACL { diff --git a/ydb/core/protos/services.proto b/ydb/core/protos/services.proto index 470062dacf..c17c8a7dc3 100644 --- a/ydb/core/protos/services.proto +++ b/ydb/core/protos/services.proto @@ -866,6 +866,6 @@ message TActivity { REPLICATION_CONTROLLER_STREAM_CREATOR = 561; YQ_TEST_CONNECTION_ACTOR = 560; REPLICATION_CONTROLLER_DST_CREATOR = 562; - BLOCKSTORE_STATS_SERVICE = 563; + BLOCKSTORE_STATS_SERVICE = 563; }; }; diff --git a/ydb/core/protos/tablet.proto b/ydb/core/protos/tablet.proto index 05dfb77324..f0bec238e7 100644 --- a/ydb/core/protos/tablet.proto +++ b/ydb/core/protos/tablet.proto @@ -37,7 +37,7 @@ message TTabletTypes { TenantSlotBroker = 27; Console = 28; Kesus = 29; - BlockStorePartition2 = 30; + BlockStorePartition2 = 30; BlockStoreDiskRegistry = 31; SysViewProcessor = 32; FileStore = 33; diff --git a/ydb/core/tablet/node_whiteboard.cpp b/ydb/core/tablet/node_whiteboard.cpp index a9e3191c4c..783758e99d 100644 --- a/ydb/core/tablet/node_whiteboard.cpp +++ b/ydb/core/tablet/node_whiteboard.cpp @@ -56,8 +56,8 @@ public: } version = branch + '.' + version; SystemStateInfo.SetVersion(version); - auto versionCounter = GetServiceCounters(AppData(ctx)->Counters, "utils")->GetSubgroup("revision", version); - *versionCounter->GetCounter("version", false) = 1; + auto versionCounter = GetServiceCounters(AppData(ctx)->Counters, "utils")->GetSubgroup("revision", version); + *versionCounter->GetCounter("version", false) = 1; } SystemStateInfo.SetStartTime(ctx.Now().MilliSeconds()); ProcessStats.Fill(getpid()); diff --git a/ydb/core/tablet/tablet_counters.h b/ydb/core/tablet/tablet_counters.h index e0cd1c474e..a8cc27e9ed 100644 --- a/ydb/core/tablet/tablet_counters.h +++ b/ydb/core/tablet/tablet_counters.h @@ -161,11 +161,11 @@ public: return *this; } - TTabletPercentileCounter& IncrementForRange(ui64 idx) { - Values[idx] += 1; - return *this; - } - + TTabletPercentileCounter& IncrementForRange(ui64 idx) { + Values[idx] += 1; + return *this; + } + TTabletPercentileCounter& DecrementFor(ui64 what) { Y_VERIFY(Integral); ui32 index = FindSlot(what); @@ -186,10 +186,10 @@ public: return Values[index]; } - ui64 GetRangeBound(ui32 index) const { - return Ranges[index].RangeVal; - } - + ui64 GetRangeBound(ui32 index) const { + return Ranges[index].RangeVal; + } + TVector<TRangeDef> GetRanges() const { return TVector<TRangeDef>(Ranges, Ranges + RangeCount); } @@ -198,10 +198,10 @@ public: return Integral; } - void PopulateFrom(const TTabletPercentileCounter& rp) { - Populate(rp); - } - + void PopulateFrom(const TTabletPercentileCounter& rp) { + Populate(rp); + } + void OutputHtml(IOutputStream &os, const char* name) const; private: diff --git a/ydb/core/tablet/tablet_monitoring_proxy.cpp b/ydb/core/tablet/tablet_monitoring_proxy.cpp index 5064b661a0..a61a43b7e5 100644 --- a/ydb/core/tablet/tablet_monitoring_proxy.cpp +++ b/ydb/core/tablet/tablet_monitoring_proxy.cpp @@ -24,19 +24,19 @@ public: return NKikimrServices::TActivity::TABLET_FORWARDING_ACTOR; } - TForwardingActor(const TTabletMonitoringProxyConfig& config, ui64 targetTablet, bool forceFollower, const TActorId& sender, const TString& query, HTTP_METHOD method) + TForwardingActor(const TTabletMonitoringProxyConfig& config, ui64 targetTablet, bool forceFollower, const TActorId& sender, const TString& query, HTTP_METHOD method) : Config(config) , TargetTablet(targetTablet) , ForceFollower(forceFollower) , Sender(sender) , Query(query) - , Method(method) + , Method(method) + {} + + TForwardingActor(const TTabletMonitoringProxyConfig& config, ui64 targetTablet, bool forceFollower, const TActorId& sender, const TString& query) + : TForwardingActor(config, targetTablet, forceFollower, sender, query, HTTP_METHOD::HTTP_METHOD_GET) {} - TForwardingActor(const TTabletMonitoringProxyConfig& config, ui64 targetTablet, bool forceFollower, const TActorId& sender, const TString& query) - : TForwardingActor(config, targetTablet, forceFollower, sender, query, HTTP_METHOD::HTTP_METHOD_GET) - {} - void Bootstrap(const TActorContext& ctx) { NTabletPipe::TClientConfig config; config.AllowFollower = ForceFollower; @@ -45,7 +45,7 @@ public: config.RetryPolicy = Config.RetryPolicy; PipeClient = ctx.ExecutorThread.RegisterActor(NTabletPipe::CreateClient(ctx.SelfID, TargetTablet, config)); - NTabletPipe::SendData(ctx, PipeClient, new NMon::TEvRemoteHttpInfo(Query, Method)); + NTabletPipe::SendData(ctx, PipeClient, new NMon::TEvRemoteHttpInfo(Query, Method)); ctx.Schedule(TDuration::Seconds(60), new TEvents::TEvWakeup()); Become(&TThis::StateWork); @@ -116,7 +116,7 @@ private: const TActorId Sender; const TString Query; TActorId PipeClient; - const HTTP_METHOD Method; + const HTTP_METHOD Method; }; } @@ -184,16 +184,16 @@ void TTabletMonitoringProxyActor::Handle(NMon::TEvHttpInfo::TPtr &ev, const TActorContext &ctx) { // NMon::TEvHttpInfo* msg = ev->Get(); - const TCgiParameters* cgi; - - if (msg->Request.GetMethod() == HTTP_METHOD_POST) { - cgi = &msg->Request.GetPostParams(); - } else { - cgi = &msg->Request.GetParams(); - } - - if (cgi->Has("KillTabletID")) { - const ui64 tabletId = TryParseTabletId(cgi->Get("KillTabletID")); + const TCgiParameters* cgi; + + if (msg->Request.GetMethod() == HTTP_METHOD_POST) { + cgi = &msg->Request.GetPostParams(); + } else { + cgi = &msg->Request.GetParams(); + } + + if (cgi->Has("KillTabletID")) { + const ui64 tabletId = TryParseTabletId(cgi->Get("KillTabletID")); if (tabletId) { ctx.Register(CreateTabletKiller(tabletId)); ctx.Send(ev->Sender, new NMon::TEvHttpInfoRes("<meta http-equiv=\"refresh\" content=\"0; tablets\" />")); @@ -206,28 +206,28 @@ TTabletMonitoringProxyActor::Handle(NMon::TEvHttpInfo::TPtr &ev, const TActorCon const TString &tabletIdParam = cgi->Get("FollowerID"); const ui64 tabletId = TryParseTabletId(tabletIdParam); if (tabletId) { - TString url = TStringBuilder() << msg->Request.GetPathInfo() << "?" << cgi->Print(); + TString url = TStringBuilder() << msg->Request.GetPathInfo() << "?" << cgi->Print(); ctx.ExecutorThread.RegisterActor(new TForwardingActor(Config, tabletId, true, ev->Sender, std::move(url))); return; } } - bool hasIdParam = cgi->Has("TabletID"); + bool hasIdParam = cgi->Has("TabletID"); if (hasIdParam) { - const TString &tabletIdParam = cgi->Get("TabletID"); + const TString &tabletIdParam = cgi->Get("TabletID"); const ui64 tabletId = TryParseTabletId(tabletIdParam); if (tabletId) { - TString url = TStringBuilder() << msg->Request.GetPathInfo() << "?" << cgi->Print(); - ctx.ExecutorThread.RegisterActor(new TForwardingActor(Config, tabletId, false, ev->Sender, std::move(url), msg->Request.GetMethod())); + TString url = TStringBuilder() << msg->Request.GetPathInfo() << "?" << cgi->Print(); + ctx.ExecutorThread.RegisterActor(new TForwardingActor(Config, tabletId, false, ev->Sender, std::move(url), msg->Request.GetMethod())); return; } } - if (cgi->Has("SsId")) { - const TString &ssIdParam = cgi->Get("SsId"); + if (cgi->Has("SsId")) { + const TString &ssIdParam = cgi->Get("SsId"); const ui64 tabletId = TryParseTabletId(ssIdParam); if (tabletId) { - TString url = TStringBuilder() << msg->Request.GetPathInfo() << "?" << cgi->Print(); + TString url = TStringBuilder() << msg->Request.GetPathInfo() << "?" << cgi->Print(); ctx.ExecutorThread.RegisterActor(CreateStateStorageMonitoringActor(tabletId, ev->Sender, std::move(url))); return; } diff --git a/ydb/core/tx/schemeshard/schemeshard__init.cpp b/ydb/core/tx/schemeshard/schemeshard__init.cpp index 9394648bee..650506549e 100644 --- a/ydb/core/tx/schemeshard/schemeshard__init.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__init.cpp @@ -3683,9 +3683,9 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> { case ETabletType::BlockStorePartition: Self->TabletCounters->Simple()[COUNTER_BLOCKSTORE_PARTITION_SHARD_COUNT].Add(1); break; - case ETabletType::BlockStorePartition2: - Self->TabletCounters->Simple()[COUNTER_BLOCKSTORE_PARTITION2_SHARD_COUNT].Add(1); - break; + case ETabletType::BlockStorePartition2: + Self->TabletCounters->Simple()[COUNTER_BLOCKSTORE_PARTITION2_SHARD_COUNT].Add(1); + break; case ETabletType::FileStore: Self->TabletCounters->Simple()[COUNTER_FILESTORE_COUNT].Add(1); break; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_bsv.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_bsv.cpp index 2debfbe10b..27455e4627 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_bsv.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_bsv.cpp @@ -78,7 +78,7 @@ public: TOperationId operationId, TPathElement::TPtr item, TBlockStoreVolumeInfo::TPtr volume, const TChannelsBindings& partitionChannels, - const TChannelsBindings& volumeChannels, + const TChannelsBindings& volumeChannels, ui64 shardsToCreate, TOperationContext& context) { @@ -98,15 +98,15 @@ public: << " ExplicitChannelProfiles#" << volume->ExplicitChannelProfileCount << "->" << volume->AlterData->ExplicitChannelProfileCount); - bool needMoreShards = ApplySharding( - operationId.GetTxId(), - item->PathId, - volume, - txState, - partitionChannels, - volumeChannels, - context); - + bool needMoreShards = ApplySharding( + operationId.GetTxId(), + item->PathId, + volume, + txState, + partitionChannels, + volumeChannels, + context); + if (needMoreShards) { context.SS->PersistUpdateNextShardIdx(db); } @@ -153,7 +153,7 @@ public: TBlockStoreVolumeInfo::TPtr volume, TTxState& txState, const TChannelsBindings& partitionChannels, - const TChannelsBindings& volumeChannels, + const TChannelsBindings& volumeChannels, TOperationContext& context) { Y_VERIFY(volume->AlterData->DefaultPartitionCount @@ -181,11 +181,11 @@ public: } } - if (volume->VolumeConfig.GetTabletVersion() == 2) { + if (volume->VolumeConfig.GetTabletVersion() == 2) { txState.Shards.emplace_back(shardIdx, ETabletType::BlockStorePartition2, partitionOp); - } else { + } else { txState.Shards.emplace_back(shardIdx, ETabletType::BlockStorePartition, partitionOp); - } + } } // create new shards @@ -193,11 +193,11 @@ public: TShardIdx shardIdx; if (volume->VolumeConfig.GetTabletVersion() == 2) { shardIdx = context.SS->RegisterShardInfo(TShardInfo::BlockStorePartition2Info(txId, pathId)); - context.SS->TabletCounters->Simple()[COUNTER_BLOCKSTORE_PARTITION2_SHARD_COUNT].Add(1); - } else { + context.SS->TabletCounters->Simple()[COUNTER_BLOCKSTORE_PARTITION2_SHARD_COUNT].Add(1); + } else { shardIdx = context.SS->RegisterShardInfo(TShardInfo::BlockStorePartitionInfo(txId, pathId)); - context.SS->TabletCounters->Simple()[COUNTER_BLOCKSTORE_PARTITION_SHARD_COUNT].Add(1); - } + context.SS->TabletCounters->Simple()[COUNTER_BLOCKSTORE_PARTITION_SHARD_COUNT].Add(1); + } auto& shardInfo = context.SS->ShardInfos.at(shardIdx); shardInfo.BindedChannels = partitionChannels; txState.Shards.emplace_back(shardIdx, shardInfo.TabletType, TTxState::CreateParts); @@ -208,20 +208,20 @@ public: volume->Shards[shardIdx] = std::move(part); } - // update the volume shard if needed - auto volumeOp = TTxState::ConfigureParts; - auto shardIdx = volume->VolumeShardIdx; - auto& shardInfo = context.SS->ShardInfos[shardIdx]; - for (ui32 i = 0; i < volumeChannels.size(); ++i) { - if (i >= shardInfo.BindedChannels.size()) { - shardInfo.BindedChannels.push_back(volumeChannels[i]); - volumeOp = TTxState::CreateParts; - } else if (!Compare(volumeChannels[i], shardInfo.BindedChannels[i])) { - shardInfo.BindedChannels[i] = volumeChannels[i]; - volumeOp = TTxState::CreateParts; - } + // update the volume shard if needed + auto volumeOp = TTxState::ConfigureParts; + auto shardIdx = volume->VolumeShardIdx; + auto& shardInfo = context.SS->ShardInfos[shardIdx]; + for (ui32 i = 0; i < volumeChannels.size(); ++i) { + if (i >= shardInfo.BindedChannels.size()) { + shardInfo.BindedChannels.push_back(volumeChannels[i]); + volumeOp = TTxState::CreateParts; + } else if (!Compare(volumeChannels[i], shardInfo.BindedChannels[i])) { + shardInfo.BindedChannels[i] = volumeChannels[i]; + volumeOp = TTxState::CreateParts; + } } - txState.Shards.emplace_back(shardIdx, ETabletType::BlockStoreVolume, volumeOp); + txState.Shards.emplace_back(shardIdx, ETabletType::BlockStoreVolume, volumeOp); return shardsToCreate > 0; } @@ -272,60 +272,60 @@ public: return &volumeConfig; } - bool ProcessVolumeChannelProfiles( - const TPath& path, - const NKikimrBlockStore::TVolumeConfig& volumeConfig, - const NKikimrBlockStore::TVolumeConfig& alterVolumeConfig, - TOperationContext& context, - TProposeResponse& result, - TChannelsBindings* volumeChannelsBinding) - { - const auto& alterVolumeEcps = alterVolumeConfig.GetVolumeExplicitChannelProfiles(); - - if (alterVolumeEcps.size() && - (ui32)alterVolumeEcps.size() != TBlockStoreVolumeInfo::NumVolumeTabletChannels) - { - auto errStr = Sprintf("Wrong number of channels %u , should be %lu", - alterVolumeEcps.size(), - TBlockStoreVolumeInfo::NumVolumeTabletChannels); + bool ProcessVolumeChannelProfiles( + const TPath& path, + const NKikimrBlockStore::TVolumeConfig& volumeConfig, + const NKikimrBlockStore::TVolumeConfig& alterVolumeConfig, + TOperationContext& context, + TProposeResponse& result, + TChannelsBindings* volumeChannelsBinding) + { + const auto& alterVolumeEcps = alterVolumeConfig.GetVolumeExplicitChannelProfiles(); + + if (alterVolumeEcps.size() && + (ui32)alterVolumeEcps.size() != TBlockStoreVolumeInfo::NumVolumeTabletChannels) + { + auto errStr = Sprintf("Wrong number of channels %u , should be %lu", + alterVolumeEcps.size(), + TBlockStoreVolumeInfo::NumVolumeTabletChannels); result.SetError(NKikimrScheme::StatusInvalidParameter, errStr); - return false; - } - - if (alterVolumeEcps.size() || volumeConfig.VolumeExplicitChannelProfilesSize()) { - const auto& ecps = alterVolumeEcps.empty() - ? volumeConfig.GetVolumeExplicitChannelProfiles() - : alterVolumeEcps; - - TVector<TStringBuf> poolKinds; - poolKinds.reserve(ecps.size()); - for (const auto& ecp : ecps) { - poolKinds.push_back(ecp.GetPoolKind()); - } - - const auto volumeChannelsResolved = context.SS->ResolveChannelsByPoolKinds( - poolKinds, - path.DomainId(), - *volumeChannelsBinding); - - if (!volumeChannelsResolved) { + return false; + } + + if (alterVolumeEcps.size() || volumeConfig.VolumeExplicitChannelProfilesSize()) { + const auto& ecps = alterVolumeEcps.empty() + ? volumeConfig.GetVolumeExplicitChannelProfiles() + : alterVolumeEcps; + + TVector<TStringBuf> poolKinds; + poolKinds.reserve(ecps.size()); + for (const auto& ecp : ecps) { + poolKinds.push_back(ecp.GetPoolKind()); + } + + const auto volumeChannelsResolved = context.SS->ResolveChannelsByPoolKinds( + poolKinds, + path.DomainId(), + *volumeChannelsBinding); + + if (!volumeChannelsResolved) { result.SetError(NKikimrScheme::StatusInvalidParameter, - "Unable to construct channel binding for volume with the storage pool"); - return false; - } - context.SS->SetNbsChannelsParams(ecps, *volumeChannelsBinding); - } else { - const ui32 volumeProfileId = 0; - if (!context.SS->ResolveTabletChannels(volumeProfileId, path.DomainId(), *volumeChannelsBinding)) { + "Unable to construct channel binding for volume with the storage pool"); + return false; + } + context.SS->SetNbsChannelsParams(ecps, *volumeChannelsBinding); + } else { + const ui32 volumeProfileId = 0; + if (!context.SS->ResolveTabletChannels(volumeProfileId, path.DomainId(), *volumeChannelsBinding)) { result.SetError(NKikimrScheme::StatusInvalidParameter, - "Unable to construct channel binding for volume with the profile"); - return false; - } - } - - return true; - } - + "Unable to construct channel binding for volume with the profile"); + return false; + } + } + + return true; + } + bool ProcessChannelProfiles( const TPath& path, const NKikimrBlockStore::TVolumeConfig& volumeConfig, @@ -500,19 +500,19 @@ public: } } - TChannelsBindings volumeChannelsBinding; - const auto channelProfilesProcessed = ProcessVolumeChannelProfiles( - path, - volume->VolumeConfig, - *alterVolumeConfig, - context, - *result, - &volumeChannelsBinding); - - if (!channelProfilesProcessed) { - return result; - } - + TChannelsBindings volumeChannelsBinding; + const auto channelProfilesProcessed = ProcessVolumeChannelProfiles( + path, + volume->VolumeConfig, + *alterVolumeConfig, + context, + *result, + &volumeChannelsBinding); + + if (!channelProfilesProcessed) { + return result; + } + if (alterVolumeConfig->PartitionsSize()) { // Cannot delete individual partitions // Do we need to verify whether geometry changes make sense? @@ -550,15 +550,15 @@ public: } } - if (alterVolumeConfig->HasVersion() && - alterVolumeConfig->GetVersion() != volume->AlterVersion) - { - result->SetError( + if (alterVolumeConfig->HasVersion() && + alterVolumeConfig->GetVersion() != volume->AlterVersion) + { + result->SetError( NKikimrScheme::StatusPreconditionFailed, - "Wrong version in VolumeConfig"); - return result; - } - + "Wrong version in VolumeConfig"); + return result; + } + if (!context.SS->CheckApplyIf(Transaction, errStr)) { result->SetError(NKikimrScheme::StatusPreconditionFailed, errStr); return result; @@ -595,10 +595,10 @@ public: // MergeFrom will append explicit channel profiles, we want a replace operation instead alterData->VolumeConfig.ClearExplicitChannelProfiles(); } - if (alterVolumeConfig->VolumeExplicitChannelProfilesSize() > 0) { - // MergeFrom will append explicit channel profiles, we want a replace operation instead - alterData->VolumeConfig.ClearVolumeExplicitChannelProfiles(); - } + if (alterVolumeConfig->VolumeExplicitChannelProfilesSize() > 0) { + // MergeFrom will append explicit channel profiles, we want a replace operation instead + alterData->VolumeConfig.ClearVolumeExplicitChannelProfiles(); + } if (alterVolumeConfig->TagsSize() > 0) { // MergeFrom will append tags, we want a replace operation instead alterData->VolumeConfig.ClearTags(); @@ -626,14 +626,14 @@ public: // Increase in occupied space is applied immediately domainDir->ChangeVolumeSpaceBegin(newVolumeSpace, oldVolumeSpace); - const TTxState& txState = PrepareChanges( - OperationId, - path.Base(), - volume, - partitionChannelsBinding, - volumeChannelsBinding, - shardsToCreate, - context); + const TTxState& txState = PrepareChanges( + OperationId, + path.Base(), + volume, + partitionChannelsBinding, + volumeChannelsBinding, + shardsToCreate, + context); context.SS->ClearDescribePathCaches(path.Base()); context.OnComplete.PublishToSchemeBoard(OperationId, path.Base()->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_assign_bsv.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_assign_bsv.cpp index 61106c1182..de1576f2b1 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_assign_bsv.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_assign_bsv.cpp @@ -71,16 +71,16 @@ public: return result; } - - if (version && - version != volume->TokenVersion) - { - result->SetError( + + if (version && + version != volume->TokenVersion) + { + result->SetError( NKikimrScheme::StatusPreconditionFailed, - "Wrong version in Assign Volume"); - return result; + "Wrong version in Assign Volume"); + return result; } - + TString errStr; if (!context.SS->CheckApplyIf(Transaction, errStr)) { result->SetError(NKikimrScheme::StatusPreconditionFailed, errStr); @@ -90,7 +90,7 @@ public: NIceDb::TNiceDb db(context.Txc.DB); volume->MountToken = mountToken; - ++volume->TokenVersion; + ++volume->TokenVersion; context.SS->PersistBlockStoreVolumeMountToken(db, path.Base()->PathId, volume); context.OnComplete.PublishToSchemeBoard(OperationId, path.Base()->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_common.h b/ydb/core/tx/schemeshard/schemeshard__operation_common.h index 8507bfdb5e..5a3da32cad 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_common.h +++ b/ydb/core/tx/schemeshard/schemeshard__operation_common.h @@ -655,7 +655,7 @@ public: auto tablePartitionConfig = context.SS->GetTablePartitionConfigWithAlterData(targetPath->PathId); const auto& shard = context.SS->ShardInfos[shardIdx]; - if (shard.TabletType == ETabletType::BlockStorePartition || + if (shard.TabletType == ETabletType::BlockStorePartition || shard.TabletType == ETabletType::BlockStorePartition2) { auto it = context.SS->BlockStoreVolumes.FindPtr(targetPath->PathId); @@ -713,8 +713,8 @@ public: } } - if (shard.TabletType == ETabletType::BlockStorePartition || - shard.TabletType == ETabletType::BlockStorePartition2 || + if (shard.TabletType == ETabletType::BlockStorePartition || + shard.TabletType == ETabletType::BlockStorePartition2 || shard.TabletType == ETabletType::RTMRPartition) { // Partitions should never be booted by local ev->Record.SetTabletBootMode(NKikimrHive::TABLET_BOOT_MODE_EXTERNAL); @@ -1272,8 +1272,8 @@ public: } for (auto shard : txState->Shards) { - if (shard.TabletType == ETabletType::BlockStorePartition || - shard.TabletType == ETabletType::BlockStorePartition2) { + if (shard.TabletType == ETabletType::BlockStorePartition || + shard.TabletType == ETabletType::BlockStorePartition2) { continue; } diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp index cca688f9d6..b32fb7d969 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp @@ -38,7 +38,7 @@ TBlockStoreVolumeInfo::TPtr CreateBlockStoreVolumeInfo(const NKikimrSchemeOp::TB } volume->AlterVersion = 1; - volume->TokenVersion = 0; + volume->TokenVersion = 0; volume->DefaultPartitionCount = TBlockStoreVolumeInfo::CalculateDefaultPartitionCount(op.GetVolumeConfig()); volume->VolumeConfig.CopyFrom(op.GetVolumeConfig()); @@ -49,25 +49,25 @@ TBlockStoreVolumeInfo::TPtr CreateBlockStoreVolumeInfo(const NKikimrSchemeOp::TB void ApplySharding(TTxId txId, TPathId pathId, TBlockStoreVolumeInfo::TPtr volume, TTxState& txState, const TChannelsBindings& partitionChannels, const TChannelsBindings& volumeChannels, TOperationContext& context) { - Y_VERIFY(volume->VolumeConfig.GetTabletVersion() <= 2); + Y_VERIFY(volume->VolumeConfig.GetTabletVersion() <= 2); ui64 count = volume->DefaultPartitionCount; txState.Shards.reserve(count + 1); for (ui64 i = 0; i < count; ++i) { TShardIdx shardIdx; - if (volume->VolumeConfig.GetTabletVersion() == 2) { + if (volume->VolumeConfig.GetTabletVersion() == 2) { shardIdx = context.SS->RegisterShardInfo( TShardInfo::BlockStorePartition2Info(txId, pathId) .WithBindedChannels(partitionChannels)); context.SS->TabletCounters->Simple()[COUNTER_BLOCKSTORE_PARTITION2_SHARD_COUNT].Add(1); - txState.Shards.emplace_back(shardIdx, ETabletType::BlockStorePartition2, TTxState::CreateParts); - } else { + txState.Shards.emplace_back(shardIdx, ETabletType::BlockStorePartition2, TTxState::CreateParts); + } else { shardIdx = context.SS->RegisterShardInfo( TShardInfo::BlockStorePartitionInfo(txId, pathId) .WithBindedChannels(partitionChannels)); context.SS->TabletCounters->Simple()[COUNTER_BLOCKSTORE_PARTITION_SHARD_COUNT].Add(1); - txState.Shards.emplace_back(shardIdx, ETabletType::BlockStorePartition, TTxState::CreateParts); - } + txState.Shards.emplace_back(shardIdx, ETabletType::BlockStorePartition, TTxState::CreateParts); + } TBlockStorePartitionInfo::TPtr part = new TBlockStorePartitionInfo(); part->PartitionId = i; @@ -305,19 +305,19 @@ public: return result; } - auto resolveChannels = [&] (const auto& ecps, TChannelsBindings& binding) - { - TVector<TStringBuf> poolKinds; - poolKinds.reserve(ecps.size()); - for (const auto& ecp : ecps) { - poolKinds.push_back(ecp.GetPoolKind()); - } - return context.SS->ResolveChannelsByPoolKinds( - poolKinds, - dstPath.DomainId(), - binding); - }; - + auto resolveChannels = [&] (const auto& ecps, TChannelsBindings& binding) + { + TVector<TStringBuf> poolKinds; + poolKinds.reserve(ecps.size()); + for (const auto& ecp : ecps) { + poolKinds.push_back(ecp.GetPoolKind()); + } + return context.SS->ResolveChannelsByPoolKinds( + poolKinds, + dstPath.DomainId(), + binding); + }; + TChannelsBindings partitionChannelsBinding; if (defaultPartitionCount) { const auto& ecps = operation.GetVolumeConfig().GetExplicitChannelProfiles(); @@ -330,7 +330,7 @@ public: return result; } - if (!resolveChannels(ecps, partitionChannelsBinding)) { + if (!resolveChannels(ecps, partitionChannelsBinding)) { result->SetError(NKikimrScheme::StatusInvalidParameter, "Unable to construct channel binding for partition with the storage pool"); return result; @@ -340,29 +340,29 @@ public: } TChannelsBindings volumeChannelsBinding; - const auto& ecps = operation.GetVolumeConfig().GetVolumeExplicitChannelProfiles(); - if (ecps.size()) { - if ((ui32)ecps.size() != TBlockStoreVolumeInfo::NumVolumeTabletChannels) { - auto errStr = Sprintf("Wrong number of channels %u , should be %lu", - ecps.size(), - TBlockStoreVolumeInfo::NumVolumeTabletChannels); + const auto& ecps = operation.GetVolumeConfig().GetVolumeExplicitChannelProfiles(); + if (ecps.size()) { + if ((ui32)ecps.size() != TBlockStoreVolumeInfo::NumVolumeTabletChannels) { + auto errStr = Sprintf("Wrong number of channels %u , should be %lu", + ecps.size(), + TBlockStoreVolumeInfo::NumVolumeTabletChannels); result->SetError(NKikimrScheme::StatusInvalidParameter, errStr); - return result; - } - - if (!resolveChannels(ecps, volumeChannelsBinding)) { + return result; + } + + if (!resolveChannels(ecps, volumeChannelsBinding)) { result->SetError(NKikimrScheme::StatusInvalidParameter, - "Unable to construct channel binding for volume with the storage pool"); - return result; - } - context.SS->SetNbsChannelsParams(ecps, volumeChannelsBinding); - } else { - const ui32 volumeProfileId = 0; - if (!context.SS->ResolveTabletChannels(volumeProfileId, dstPath.DomainId(), volumeChannelsBinding)) { + "Unable to construct channel binding for volume with the storage pool"); + return result; + } + context.SS->SetNbsChannelsParams(ecps, volumeChannelsBinding); + } else { + const ui32 volumeProfileId = 0; + if (!context.SS->ResolveTabletChannels(volumeProfileId, dstPath.DomainId(), volumeChannelsBinding)) { result->SetError(NKikimrScheme::StatusInvalidParameter, - "Unable to construct channel binding for volume with the profile"); - return result; - } + "Unable to construct channel binding for volume with the profile"); + return result; + } } auto domainDir = context.SS->PathsById.at(dstPath.DomainId()); diff --git a/ydb/core/tx/schemeshard/schemeshard_impl.cpp b/ydb/core/tx/schemeshard/schemeshard_impl.cpp index 6df2896f23..0715543a22 100644 --- a/ydb/core/tx/schemeshard/schemeshard_impl.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_impl.cpp @@ -2710,7 +2710,7 @@ void TSchemeShard::PersistBlockStoreVolumeMountToken(NIceDb::TNiceDb& db, TPathI { Y_VERIFY(IsLocalId(pathId)); db.Table<Schema::BlockStoreVolumes>().Key(pathId.LocalPathId).Update( - NIceDb::TUpdate<Schema::BlockStoreVolumes::MountToken>(volume->MountToken), + NIceDb::TUpdate<Schema::BlockStoreVolumes::MountToken>(volume->MountToken), NIceDb::TUpdate<Schema::BlockStoreVolumes::TokenVersion>(volume->TokenVersion)); } diff --git a/ydb/core/tx/schemeshard/schemeshard_info_types.h b/ydb/core/tx/schemeshard/schemeshard_info_types.h index 95e3178f1e..2e5710c3d3 100644 --- a/ydb/core/tx/schemeshard/schemeshard_info_types.h +++ b/ydb/core/tx/schemeshard/schemeshard_info_types.h @@ -917,10 +917,10 @@ struct TShardInfo { return TShardInfo(txId, pathId, ETabletType::BlockStorePartition); } - static TShardInfo BlockStorePartition2Info(TTxId txId, TPathId pathId) { - return TShardInfo(txId, pathId, ETabletType::BlockStorePartition2); - } - + static TShardInfo BlockStorePartition2Info(TTxId txId, TPathId pathId) { + return TShardInfo(txId, pathId, ETabletType::BlockStorePartition2); + } + static TShardInfo FileStoreInfo(TTxId txId, TPathId pathId) { return TShardInfo(txId, pathId, ETabletType::FileStore); } @@ -1843,7 +1843,7 @@ struct TBlockStoreVolumeInfo : public TSimpleRefCount<TBlockStoreVolumeInfo> { }; static constexpr size_t NumVolumeTabletChannels = 3; - + ui32 DefaultPartitionCount = 0; NKikimrBlockStore::TVolumeConfig VolumeConfig; ui64 AlterVersion = 0; diff --git a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp index 0764f7e873..3789d3af1b 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp @@ -674,7 +674,7 @@ void TPathDescriber::DescribeBlockStoreVolume(TPathId pathId, TPathElement::TPtr entry->SetVolumeTabletId(ui64(volume->VolumeTabletId)); entry->SetAlterVersion(volume->AlterVersion); entry->SetMountToken(volume->MountToken); - entry->SetTokenVersion(volume->TokenVersion); + entry->SetTokenVersion(volume->TokenVersion); const auto& tablets = volume->GetTablets(Self->ShardInfos); for (ui32 idx = 0; idx < tablets.size(); ++idx) { diff --git a/ydb/core/tx/schemeshard/schemeshard_schema.h b/ydb/core/tx/schemeshard/schemeshard_schema.h index 34884742bc..f293136fe8 100644 --- a/ydb/core/tx/schemeshard/schemeshard_schema.h +++ b/ydb/core/tx/schemeshard/schemeshard_schema.h @@ -840,7 +840,7 @@ struct Schema : NIceDb::Schema { struct TokenVersion: Column<5, NScheme::NTypeIds::Uint64> {}; using TKey = TableKey<PathId>; - using TColumns = TableColumns<PathId, VolumeConfig, AlterVersion, MountToken, TokenVersion>; + using TColumns = TableColumns<PathId, VolumeConfig, AlterVersion, MountToken, TokenVersion>; }; struct BlockStoreVolumeAlters : Table<24> { diff --git a/ydb/core/tx/schemeshard/ut_base.cpp b/ydb/core/tx/schemeshard/ut_base.cpp index 5027b569fd..a76dcf9d5b 100644 --- a/ydb/core/tx/schemeshard/ut_base.cpp +++ b/ydb/core/tx/schemeshard/ut_base.cpp @@ -7200,36 +7200,36 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { {NKikimrScheme::StatusAlreadyExists}); } - Y_UNIT_TEST(CreateBlockStoreVolumeWithVolumeChannelsProfiles) { //+ - TTestBasicRuntime runtime; - TTestEnv env(runtime); - ui64 txId = 100; - + Y_UNIT_TEST(CreateBlockStoreVolumeWithVolumeChannelsProfiles) { //+ + TTestBasicRuntime runtime; + TTestEnv env(runtime); + ui64 txId = 100; + NKikimrSchemeOp::TBlockStoreVolumeDescription vdescr; - vdescr.SetName("BSVolume"); - auto& vc = *vdescr.MutableVolumeConfig(); - - vc.SetBlockSize(4096); - vc.AddPartitions()->SetBlockCount(16); - vc.AddExplicitChannelProfiles()->SetPoolKind("pool-kind-1"); - - // Too few volume channel profiles - vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-2"); - vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-2"); - - TestCreateBlockStoreVolume(runtime, ++txId, "/MyRoot", - vdescr.DebugString(), + vdescr.SetName("BSVolume"); + auto& vc = *vdescr.MutableVolumeConfig(); + + vc.SetBlockSize(4096); + vc.AddPartitions()->SetBlockCount(16); + vc.AddExplicitChannelProfiles()->SetPoolKind("pool-kind-1"); + + // Too few volume channel profiles + vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-2"); + vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-2"); + + TestCreateBlockStoreVolume(runtime, ++txId, "/MyRoot", + vdescr.DebugString(), {NKikimrScheme::StatusInvalidParameter}); - - vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-2"); - - TestCreateBlockStoreVolume(runtime, ++txId, "/MyRoot", vdescr.DebugString()); - env.TestWaitNotification(runtime, txId); - - TestDescribeResult(DescribePath(runtime, "/MyRoot/BSVolume"), - {NLs::Finished, NLs::PathsInsideDomain(1), NLs::ShardsInsideDomain(2)}); - } - + + vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-2"); + + TestCreateBlockStoreVolume(runtime, ++txId, "/MyRoot", vdescr.DebugString()); + env.TestWaitNotification(runtime, txId); + + TestDescribeResult(DescribePath(runtime, "/MyRoot/BSVolume"), + {NLs::Finished, NLs::PathsInsideDomain(1), NLs::ShardsInsideDomain(2)}); + } + Y_UNIT_TEST(CreateBlockStoreVolumeWithNonReplicatedPartitions) { //+ TTestBasicRuntime runtime; TTestEnv env(runtime); @@ -7402,14 +7402,14 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { {NKikimrScheme::StatusInvalidParameter}); vc.ClearExplicitChannelProfiles(); - // Number of volume channel explicit profiles must be equal to 3 - vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-1"); - vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-2"); - TestAlterBlockStoreVolume(runtime, ++txId, "/MyRoot", - vdescr.DebugString(), + // Number of volume channel explicit profiles must be equal to 3 + vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-1"); + vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-2"); + TestAlterBlockStoreVolume(runtime, ++txId, "/MyRoot", + vdescr.DebugString(), {NKikimrScheme::StatusInvalidParameter}); - vc.ClearVolumeExplicitChannelProfiles(); - + vc.ClearVolumeExplicitChannelProfiles(); + // Changing PoolKind is not allowed vc.AddExplicitChannelProfiles()->SetPoolKind("pool-kind-1"); vc.MutableExplicitChannelProfiles(0)->SetSize(128); @@ -7503,7 +7503,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { { NKikimrBlockStore::TVolumeConfig config; TestLs(runtime, "/MyRoot/BSVolume", false, NLs::ExtractVolumeConfig(&config)); - UNIT_ASSERT_VALUES_EQUAL(config.GetDiskId(), "foo"); + UNIT_ASSERT_VALUES_EQUAL(config.GetDiskId(), "foo"); UNIT_ASSERT_VALUES_EQUAL(config.GetOpaque(), "binary data"); } @@ -7526,27 +7526,27 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { *vc.AddTags() = "tag4"; TestAlterBlockStoreVolume(runtime, ++txId, "/MyRoot", vdescr.DebugString()); env.TestWaitNotification(runtime, txId); - - vc.SetVersion(9); - // Set volume tablet channels - - vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-1"); - vc.MutableVolumeExplicitChannelProfiles(0)->SetSize(128); - vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-1"); - vc.MutableVolumeExplicitChannelProfiles(1)->SetSize(128); - vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-1"); - vc.MutableVolumeExplicitChannelProfiles(2)->SetSize(128); - TestAlterBlockStoreVolume(runtime, ++txId, "/MyRoot", vdescr.DebugString()); - env.TestWaitNotification(runtime, txId); - - vc.SetVersion(10); - // Changing volume tablet channels - - vc.MutableVolumeExplicitChannelProfiles(0)->SetPoolKind("pool-kind-2"); - vc.MutableVolumeExplicitChannelProfiles(1)->SetPoolKind("pool-kind-2"); - vc.MutableVolumeExplicitChannelProfiles(2)->SetPoolKind("pool-kind-2"); - TestAlterBlockStoreVolume(runtime, ++txId, "/MyRoot", vdescr.DebugString()); - env.TestWaitNotification(runtime, txId); + + vc.SetVersion(9); + // Set volume tablet channels + + vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-1"); + vc.MutableVolumeExplicitChannelProfiles(0)->SetSize(128); + vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-1"); + vc.MutableVolumeExplicitChannelProfiles(1)->SetSize(128); + vc.AddVolumeExplicitChannelProfiles()->SetPoolKind("pool-kind-1"); + vc.MutableVolumeExplicitChannelProfiles(2)->SetSize(128); + TestAlterBlockStoreVolume(runtime, ++txId, "/MyRoot", vdescr.DebugString()); + env.TestWaitNotification(runtime, txId); + + vc.SetVersion(10); + // Changing volume tablet channels + + vc.MutableVolumeExplicitChannelProfiles(0)->SetPoolKind("pool-kind-2"); + vc.MutableVolumeExplicitChannelProfiles(1)->SetPoolKind("pool-kind-2"); + vc.MutableVolumeExplicitChannelProfiles(2)->SetPoolKind("pool-kind-2"); + TestAlterBlockStoreVolume(runtime, ++txId, "/MyRoot", vdescr.DebugString()); + env.TestWaitNotification(runtime, txId); vc.Clear(); { @@ -7554,7 +7554,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { NLs::ExtractVolumeConfig(&config)(DescribePath(runtime, "/MyRoot/BSVolume")); UNIT_ASSERT_VALUES_EQUAL(config.GetBlockSize(), 4096u); UNIT_ASSERT_VALUES_EQUAL(config.PartitionsSize(), 2); - UNIT_ASSERT_VALUES_EQUAL(config.GetDiskId(), "foobaz"); + UNIT_ASSERT_VALUES_EQUAL(config.GetDiskId(), "foobaz"); UNIT_ASSERT_VALUES_EQUAL(config.GetFolderId(), "baz"); UNIT_ASSERT_VALUES_EQUAL(config.GetOpaque(), "binary data"); @@ -7612,15 +7612,15 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { UNIT_ASSERT_VALUES_EQUAL(config.GetExplicitChannelProfiles(5).GetWriteIops(), 601); UNIT_ASSERT_VALUES_EQUAL(config.GetExplicitChannelProfiles(5).GetWriteBandwidth(), 600501); UNIT_ASSERT_VALUES_EQUAL(config.GetExplicitChannelProfiles(5).GetDataKind(), 1); - - UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(0).GetPoolKind(), "pool-kind-2"); - UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(0).GetSize(), 128); - - UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(1).GetPoolKind(), "pool-kind-2"); - UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(1).GetSize(), 128); - - UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(2).GetPoolKind(), "pool-kind-2"); - UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(2).GetSize(), 128); + + UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(0).GetPoolKind(), "pool-kind-2"); + UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(0).GetSize(), 128); + + UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(1).GetPoolKind(), "pool-kind-2"); + UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(1).GetSize(), 128); + + UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(2).GetPoolKind(), "pool-kind-2"); + UNIT_ASSERT_VALUES_EQUAL(config.GetVolumeExplicitChannelProfiles(2).GetSize(), 128); } } @@ -7793,7 +7793,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { ui64 txId = 100; // Cannot assign non-existant volume - TestAssignBlockStoreVolume(runtime, ++txId, "/MyRoot", "BSVolume", "Owner123", 0, + TestAssignBlockStoreVolume(runtime, ++txId, "/MyRoot", "BSVolume", "Owner123", 0, {NKikimrScheme::StatusPathDoesNotExist}); // Create volume with 1 partition @@ -7820,22 +7820,22 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { TestDescribeResult(DescribePath(runtime, "/MyRoot/BSVolume"), {NLs::CheckMountToken("BSVolume", "Owner123")}); - // AssignVolume to Owner124 - TestAssignBlockStoreVolume(runtime, ++txId, "/MyRoot", "BSVolume", "Owner124"); - - TestDescribeResult(DescribePath(runtime, "/MyRoot/BSVolume"), - {NLs::CheckMountToken("BSVolume", "Owner124")}); + // AssignVolume to Owner124 + TestAssignBlockStoreVolume(runtime, ++txId, "/MyRoot", "BSVolume", "Owner124"); + + TestDescribeResult(DescribePath(runtime, "/MyRoot/BSVolume"), + {NLs::CheckMountToken("BSVolume", "Owner124")}); // AssignVolume using TokenVersion - TestAssignBlockStoreVolume(runtime, ++txId, "/MyRoot", "BSVolume", "Owner125", 2); - - TestDescribeResult(DescribePath(runtime, "/MyRoot/BSVolume"), - {NLs::CheckMountToken("BSVolume", "Owner125")}); - - // AssignVolume using wrong TokenVersion - TestAssignBlockStoreVolume(runtime, ++txId, "/MyRoot", "BSVolume", "Owner126", 2, + TestAssignBlockStoreVolume(runtime, ++txId, "/MyRoot", "BSVolume", "Owner125", 2); + + TestDescribeResult(DescribePath(runtime, "/MyRoot/BSVolume"), + {NLs::CheckMountToken("BSVolume", "Owner125")}); + + // AssignVolume using wrong TokenVersion + TestAssignBlockStoreVolume(runtime, ++txId, "/MyRoot", "BSVolume", "Owner126", 2, {NKikimrScheme::StatusPreconditionFailed}); - + // Alter is allowed vc.SetVersion(1); vc.AddPartitions()->SetBlockCount(32); @@ -7886,10 +7886,10 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { } Y_UNIT_TEST(AssignBlockStoreCheckVersionInAlter) { //+ - TTestBasicRuntime runtime; - TTestEnv env(runtime); - ui64 txId = 100; - + TTestBasicRuntime runtime; + TTestEnv env(runtime); + ui64 txId = 100; + NKikimrSchemeOp::TBlockStoreVolumeDescription vdescr; vdescr.SetName("BSVolume"); auto& vc = *vdescr.MutableVolumeConfig(); @@ -7903,7 +7903,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { TestCreateBlockStoreVolume(runtime, ++txId, "/MyRoot", vdescr.DebugString()); env.TestWaitNotification(runtime, txId); vc.Clear(); - + vc.SetVersion(1); vc.AddPartitions()->SetBlockCount(24); vc.AddPartitions()->SetBlockCount(24); @@ -7911,7 +7911,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { TestAlterBlockStoreVolume(runtime, ++txId, "/MyRoot", vdescr.DebugString()); env.TestWaitNotification(runtime, txId); vc.Clear(); - + vc.SetVersion(0); vc.AddPartitions()->SetBlockCount(25); vc.AddPartitions()->SetBlockCount(25); @@ -7921,7 +7921,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { {NKikimrScheme::StatusPreconditionFailed}); env.TestWaitNotification(runtime, txId); vc.Clear(); - + vc.SetVersion(1); vc.AddPartitions()->SetBlockCount(32); vc.AddPartitions()->SetBlockCount(32); @@ -7931,15 +7931,15 @@ Y_UNIT_TEST_SUITE(TSchemeShardTest) { {NKikimrScheme::StatusPreconditionFailed}); env.TestWaitNotification(runtime, txId); vc.Clear(); - + vc.SetVersion(2); vc.AddPartitions()->SetBlockCount(48); vc.AddPartitions()->SetBlockCount(48); TestAlterBlockStoreVolume(runtime, ++txId, "/MyRoot", vdescr.DebugString()); env.TestWaitNotification(runtime, txId); - } - + } + Y_UNIT_TEST(BlockStoreVolumeLimits) { //+ TTestBasicRuntime runtime; TTestEnv env(runtime); diff --git a/ydb/core/tx/schemeshard/ut_bsvolume_reboots.cpp b/ydb/core/tx/schemeshard/ut_bsvolume_reboots.cpp index c4e74a41b6..5dbdecf8e6 100644 --- a/ydb/core/tx/schemeshard/ut_bsvolume_reboots.cpp +++ b/ydb/core/tx/schemeshard/ut_bsvolume_reboots.cpp @@ -322,31 +322,31 @@ Y_UNIT_TEST_SUITE(TBSVWithReboots) { AsyncCreateBlockStoreVolume(runtime, txId, root, vdescr.DebugString()); }); } - - - Y_UNIT_TEST(CreateAssignWithVersion) { - TTestWithReboots t; - t.Run([&](TTestActorRuntime& runtime, bool& activeZone) { - Y_UNUSED(activeZone); - - t.RestoreLogging(); - + + + Y_UNIT_TEST(CreateAssignWithVersion) { + TTestWithReboots t; + t.Run([&](TTestActorRuntime& runtime, bool& activeZone) { + Y_UNUSED(activeZone); + + t.RestoreLogging(); + NKikimrSchemeOp::TBlockStoreVolumeDescription vdescr; - InitCreateVolumeConfig("BSVolume_4", vdescr); - TestCreateBlockStoreVolume(runtime, t.TxId++, "/MyRoot/DirA", vdescr.DebugString()); - - t.TestEnv->TestWaitNotification(runtime, t.TxId-1); - TestLs(runtime, "/MyRoot/DirA/BSVolume_4", false, NLs::Finished); - - TestAssignBlockStoreVolume(runtime, t.TxId++, "/MyRoot/DirA", "BSVolume_4", "Owner123", 0); - t.TestEnv->TestWaitNotification(runtime, t.TxId-1); - TestLs(runtime, "/MyRoot/DirA/BSVolume_4", false, NLs::CheckMountToken("BSVolume_4", "Owner123")); - - - TestAssignBlockStoreVolume(runtime, t.TxId++, "/MyRoot/DirA", "BSVolume_4", "Owner124", 1); - t.TestEnv->TestWaitNotification(runtime, t.TxId-1); - TestLs(runtime, "/MyRoot/DirA/BSVolume_4", false, NLs::CheckMountToken("BSVolume_4", "Owner124")); - - }); + InitCreateVolumeConfig("BSVolume_4", vdescr); + TestCreateBlockStoreVolume(runtime, t.TxId++, "/MyRoot/DirA", vdescr.DebugString()); + + t.TestEnv->TestWaitNotification(runtime, t.TxId-1); + TestLs(runtime, "/MyRoot/DirA/BSVolume_4", false, NLs::Finished); + + TestAssignBlockStoreVolume(runtime, t.TxId++, "/MyRoot/DirA", "BSVolume_4", "Owner123", 0); + t.TestEnv->TestWaitNotification(runtime, t.TxId-1); + TestLs(runtime, "/MyRoot/DirA/BSVolume_4", false, NLs::CheckMountToken("BSVolume_4", "Owner123")); + + + TestAssignBlockStoreVolume(runtime, t.TxId++, "/MyRoot/DirA", "BSVolume_4", "Owner124", 1); + t.TestEnv->TestWaitNotification(runtime, t.TxId-1); + TestLs(runtime, "/MyRoot/DirA/BSVolume_4", false, NLs::CheckMountToken("BSVolume_4", "Owner124")); + + }); } } diff --git a/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp b/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp index fb16c58793..6f999b268b 100644 --- a/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp +++ b/ydb/core/tx/schemeshard/ut_helpers/helpers.cpp @@ -808,7 +808,7 @@ namespace NSchemeShardUT_Private { } void AsyncAssignBlockStoreVolume(TTestActorRuntime& runtime, ui64 txId, const TString& parentPath, const TString& name, - const TString& mountToken, ui64 tokenVersion) + const TString& mountToken, ui64 tokenVersion) { TActorId sender = runtime.AllocateEdgeActor(); auto evTx = new TEvSchemeShard::TEvModifySchemeTransaction(txId, TTestTxConfig::SchemeShard); @@ -826,7 +826,7 @@ namespace NSchemeShardUT_Private { void TestAssignBlockStoreVolume(TTestActorRuntime& runtime, ui64 txId, const TString& parentPath, const TString& name, const TString& mountToken, ui64 tokenVersion, const TVector<TEvSchemeShard::EStatus>& expectedResults) { - AsyncAssignBlockStoreVolume(runtime, txId, parentPath, name, mountToken, tokenVersion); + AsyncAssignBlockStoreVolume(runtime, txId, parentPath, name, mountToken, tokenVersion); TestModificationResults(runtime, txId, expectedResults); } |