diff options
author | babenko <babenko@yandex-team.com> | 2024-10-30 14:45:00 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2024-10-30 15:52:26 +0300 |
commit | 7891efa0c4d0a1bbf82be8885a53017e06f2adf5 (patch) | |
tree | 935a947693b5d35b823e192c4b8e62f9caaa25a3 | |
parent | e589edb669af5acb0efabcfa77cebb60a9b97407 (diff) | |
download | ydb-7891efa0c4d0a1bbf82be8885a53017e06f2adf5.tar.gz |
Fix regression: static anchors are not updated properly
commit_hash:ab0bd9b2d0569820e495c714baecb05145ed35bf
-rw-r--r-- | library/cpp/yt/logging/backends/stream/stream_log_manager.cpp | 6 | ||||
-rw-r--r-- | library/cpp/yt/logging/logger.cpp | 13 | ||||
-rw-r--r-- | library/cpp/yt/logging/logger.h | 51 | ||||
-rw-r--r-- | yt/cpp/mapreduce/interface/logging/yt_log.cpp | 4 | ||||
-rw-r--r-- | yt/yt/core/logging/log_manager.cpp | 7 | ||||
-rw-r--r-- | yt/yt/core/rpc/service_detail.cpp | 4 |
6 files changed, 55 insertions, 30 deletions
diff --git a/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp b/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp index 62fa3e91d0..8b46d5679f 100644 --- a/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp +++ b/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp @@ -21,12 +21,10 @@ public: { } void RegisterStaticAnchor( - TLoggingAnchor* anchor, + TLoggingAnchor* /*anchor*/, ::TSourceLocation /*sourceLocation*/, TStringBuf /*anchorMessage*/) override - { - anchor->Registered = true; - } + { } virtual void UpdateAnchor(TLoggingAnchor* /*anchor*/) override { } diff --git a/library/cpp/yt/logging/logger.cpp b/library/cpp/yt/logging/logger.cpp index 58add38429..a6a0010b3b 100644 --- a/library/cpp/yt/logging/logger.cpp +++ b/library/cpp/yt/logging/logger.cpp @@ -195,14 +195,21 @@ bool TLogger::IsEssential() const return Essential_; } -void TLogger::UpdateAnchor(TLoggingAnchor* anchor) const +void TLogger::UpdateStaticAnchor( + TLoggingAnchor* anchor, + std::atomic<bool>* anchorRegistered, + ::TSourceLocation sourceLocation, + TStringBuf message) const { + if (!anchorRegistered->exchange(true)) { + LogManager_->RegisterStaticAnchor(anchor, sourceLocation, message); + } LogManager_->UpdateAnchor(anchor); } -void TLogger::RegisterStaticAnchor(TLoggingAnchor* anchor, ::TSourceLocation sourceLocation, TStringBuf message) const +void TLogger::UpdateDynamicAnchor(TLoggingAnchor* anchor) const { - LogManager_->RegisterStaticAnchor(anchor, sourceLocation, message); + LogManager_->UpdateAnchor(anchor); } void TLogger::Write(TLogEvent&& event) const diff --git a/library/cpp/yt/logging/logger.h b/library/cpp/yt/logging/logger.h index 35aba4eb4c..eff5da078e 100644 --- a/library/cpp/yt/logging/logger.h +++ b/library/cpp/yt/logging/logger.h @@ -206,8 +206,12 @@ public: bool IsEssential() const; bool IsAnchorUpToDate(const TLoggingAnchor& anchor) const; - void UpdateAnchor(TLoggingAnchor* anchor) const; - void RegisterStaticAnchor(TLoggingAnchor* anchor, ::TSourceLocation sourceLocation, TStringBuf message) const; + void UpdateStaticAnchor( + TLoggingAnchor* anchor, + std::atomic<bool>* anchorRegistered, + ::TSourceLocation sourceLocation, + TStringBuf message) const; + void UpdateDynamicAnchor(TLoggingAnchor* anchor) const; void Write(TLogEvent&& event) const; @@ -302,19 +306,12 @@ void LogStructuredEvent( #define YT_LOG_FATAL_UNLESS(condition, ...) if (!Y_LIKELY(condition)) YT_LOG_FATAL(__VA_ARGS__) #define YT_LOG_EVENT(logger, level, ...) \ - YT_LOG_EVENT_WITH_ANCHOR(logger, level, nullptr, __VA_ARGS__) - -#define YT_LOG_EVENT_WITH_ANCHOR(logger, level, anchor, ...) \ do { \ const auto& logger__ = (logger)(); \ auto level__ = (level); \ auto location__ = __LOCATION__; \ - \ - ::NYT::NLogging::TLoggingAnchor* anchor__ = (anchor); \ - [[unlikely]] if (!anchor__) { \ - static ::NYT::TLeakyStorage<::NYT::NLogging::TLoggingAnchor> staticAnchor__; \ - anchor__ = staticAnchor__.Get(); \ - } \ + static ::NYT::TLeakyStorage<::NYT::NLogging::TLoggingAnchor> anchorStorage__; \ + auto* anchor__ = anchorStorage__.Get(); \ \ bool anchorUpToDate__ = logger__.IsAnchorUpToDate(*anchor__); \ [[likely]] if (anchorUpToDate__) { \ @@ -328,7 +325,8 @@ void LogStructuredEvent( auto message__ = ::NYT::NLogging::NDetail::BuildLogMessage(loggingContext__, logger__, __VA_ARGS__); \ \ [[unlikely]] if (!anchorUpToDate__) { \ - logger__.RegisterStaticAnchor(anchor__, location__, message__.Anchor); \ + static std::atomic<bool> anchorRegistered__; \ + logger__.UpdateStaticAnchor(anchor__, &anchorRegistered__, location__, message__.Anchor); \ } \ \ auto effectiveLevel__ = ::NYT::NLogging::TLogger::GetEffectiveLoggingLevel(level__, *anchor__); \ @@ -345,6 +343,35 @@ void LogStructuredEvent( std::move(message__.MessageRef)); \ } while (false) +#define YT_LOG_EVENT_WITH_DYNAMIC_ANCHOR(logger, level, anchor, ...) \ + do { \ + const auto& logger__ = (logger)(); \ + auto level__ = (level); \ + auto location__ = __LOCATION__; \ + auto* anchor__ = (anchor); \ + \ + bool anchorUpToDate__ = logger__.IsAnchorUpToDate(*anchor__); \ + [[unlikely]] if (!anchorUpToDate__) { \ + logger__.UpdateDynamicAnchor(anchor__); \ + } \ + \ + auto effectiveLevel__ = ::NYT::NLogging::TLogger::GetEffectiveLoggingLevel(level__, *anchor__); \ + if (!logger__.IsLevelEnabled(effectiveLevel__)) { \ + break; \ + } \ + \ + auto loggingContext__ = ::NYT::NLogging::GetLoggingContext(); \ + auto message__ = ::NYT::NLogging::NDetail::BuildLogMessage(loggingContext__, logger__, __VA_ARGS__); \ + \ + ::NYT::NLogging::NDetail::LogEventImpl( \ + loggingContext__, \ + logger__, \ + effectiveLevel__, \ + location__, \ + anchor__, \ + std::move(message__.MessageRef)); \ + } while (false) + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NLogging diff --git a/yt/cpp/mapreduce/interface/logging/yt_log.cpp b/yt/cpp/mapreduce/interface/logging/yt_log.cpp index 4ff38d4c58..d41bfa559f 100644 --- a/yt/cpp/mapreduce/interface/logging/yt_log.cpp +++ b/yt/cpp/mapreduce/interface/logging/yt_log.cpp @@ -26,10 +26,6 @@ public: ::TSourceLocation sourceLocation, TStringBuf anchorMessage) override { - if (anchor->Registered.exchange(true)) { - return; - } - auto guard = Guard(Mutex_); anchor->SourceLocation = sourceLocation; anchor->AnchorMessage = anchorMessage; diff --git a/yt/yt/core/logging/log_manager.cpp b/yt/yt/core/logging/log_manager.cpp index d7e15992be..5694698800 100644 --- a/yt/yt/core/logging/log_manager.cpp +++ b/yt/yt/core/logging/log_manager.cpp @@ -519,10 +519,6 @@ public: ::TSourceLocation sourceLocation, TStringBuf message) { - if (anchor->Registered.exchange(true)) { - return; - } - auto guard = Guard(SpinLock_); auto config = Config_.Acquire(); anchor->SourceLocation = sourceLocation; @@ -537,12 +533,13 @@ public: if (auto it = AnchorMap_.find(anchorMessage)) { return it->second; } + auto config = Config_.Acquire(); auto anchor = std::make_unique<TLoggingAnchor>(); - anchor->Registered = true; anchor->AnchorMessage = std::move(anchorMessage); auto* rawAnchor = anchor.get(); DynamicAnchors_.push_back(std::move(anchor)); DoRegisterAnchor(rawAnchor); + DoUpdateAnchor(config, rawAnchor); return rawAnchor; } diff --git a/yt/yt/core/rpc/service_detail.cpp b/yt/yt/core/rpc/service_detail.cpp index 970552940b..d300c6b05e 100644 --- a/yt/yt/core/rpc/service_detail.cpp +++ b/yt/yt/core/rpc/service_detail.cpp @@ -1117,7 +1117,7 @@ private: TraceContext_->AddTag(RequestUser, builder.Flush()); } } - YT_LOG_EVENT_WITH_ANCHOR(Logger, LogLevel_, RuntimeInfo_->RequestLoggingAnchor, logMessage); + YT_LOG_EVENT_WITH_DYNAMIC_ANCHOR(Logger, LogLevel_, RuntimeInfo_->RequestLoggingAnchor, logMessage); } void LogResponse() override @@ -1164,7 +1164,7 @@ private: if (TraceContext_ && TraceContext_->IsRecorded()) { TraceContext_->AddTag(ResponseInfoAnnotation, logMessage); } - YT_LOG_EVENT_WITH_ANCHOR(Logger, LogLevel_, RuntimeInfo_->ResponseLoggingAnchor, logMessage); + YT_LOG_EVENT_WITH_DYNAMIC_ANCHOR(Logger, LogLevel_, RuntimeInfo_->ResponseLoggingAnchor, logMessage); } |