summaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorAlexander Smirnov <[email protected]>2025-01-20 00:22:00 +0000
committerAlexander Smirnov <[email protected]>2025-01-20 00:22:00 +0000
commitcfd87133325bcd8572eabbb04f0480b08a969fca (patch)
tree91d2a6dd92ab736133636f8cc692d6d67805245e /library/cpp
parent0723ece8129bacd44fb630ee30726d4cc9def311 (diff)
parenta68a2f035954b6e087c94367dfb1dc506d1d88c0 (diff)
Merge branch 'rightlib' into merge-libs-250120-0020
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/tld/tlds-alpha-by-domain.txt2
-rw-r--r--library/cpp/yt/logging/logger-inl.h11
-rw-r--r--library/cpp/yt/logging/logger.cpp47
-rw-r--r--library/cpp/yt/logging/logger.h26
4 files changed, 63 insertions, 23 deletions
diff --git a/library/cpp/tld/tlds-alpha-by-domain.txt b/library/cpp/tld/tlds-alpha-by-domain.txt
index c150e0c2ec6..7616e359ea4 100644
--- a/library/cpp/tld/tlds-alpha-by-domain.txt
+++ b/library/cpp/tld/tlds-alpha-by-domain.txt
@@ -1,4 +1,4 @@
-# Version 2025011300, Last Updated Mon Jan 13 07:07:01 2025 UTC
+# Version 2025011900, Last Updated Sun Jan 19 07:07:01 2025 UTC
AAA
AARP
ABB
diff --git a/library/cpp/yt/logging/logger-inl.h b/library/cpp/yt/logging/logger-inl.h
index 0637292037e..958ede8cda0 100644
--- a/library/cpp/yt/logging/logger-inl.h
+++ b/library/cpp/yt/logging/logger-inl.h
@@ -30,7 +30,8 @@ void TLogger::AddTag(const char* format, TArgs&&... args)
template <class TType>
void TLogger::AddStructuredTag(TStringBuf key, TType value)
{
- StructuredTags_.emplace_back(key, NYson::ConvertToYsonString(value));
+ auto* state = GetMutableCoWState();
+ state->StructuredTags.emplace_back(key, NYson::ConvertToYsonString(value));
}
template <class... TArgs>
@@ -115,10 +116,10 @@ inline bool HasMessageTags(
const TLoggingContext& loggingContext,
const TLogger& logger)
{
- if (logger.GetTag()) {
+ if (!logger.GetTag().empty()) {
return true;
}
- if (loggingContext.TraceLoggingTag) {
+ if (!loggingContext.TraceLoggingTag.empty()) {
return true;
}
return false;
@@ -130,11 +131,11 @@ inline void AppendMessageTags(
const TLogger& logger)
{
bool printComma = false;
- if (const auto& loggerTag = logger.GetTag()) {
+ if (const auto& loggerTag = logger.GetTag(); !loggerTag.empty()) {
builder->AppendString(loggerTag);
printComma = true;
}
- if (auto traceLoggingTag = loggingContext.TraceLoggingTag) {
+ if (const auto& traceLoggingTag = loggingContext.TraceLoggingTag; !traceLoggingTag.empty()) {
if (printComma) {
builder->AppendString(TStringBuf(", "));
}
diff --git a/library/cpp/yt/logging/logger.cpp b/library/cpp/yt/logging/logger.cpp
index a6a0010b3bf..682231d4895 100644
--- a/library/cpp/yt/logging/logger.cpp
+++ b/library/cpp/yt/logging/logger.cpp
@@ -217,15 +217,16 @@ void TLogger::Write(TLogEvent&& event) const
LogManager_->Enqueue(std::move(event));
}
-void TLogger::AddRawTag(const TString& tag)
+void TLogger::AddRawTag(const std::string& tag)
{
- if (!Tag_.empty()) {
- Tag_ += ", ";
+ auto* state = GetMutableCoWState();
+ if (!state->Tag.empty()) {
+ state->Tag += ", ";
}
- Tag_ += tag;
+ state->Tag += tag;
}
-TLogger TLogger::WithRawTag(const TString& tag) const
+TLogger TLogger::WithRawTag(const std::string& tag) const
{
auto result = *this;
result.AddRawTag(tag);
@@ -239,10 +240,16 @@ TLogger TLogger::WithEssential(bool essential) const
return result;
}
+void TLogger::AddStructuredValidator(TStructuredValidator validator)
+{
+ auto* state = GetMutableCoWState();
+ state->StructuredValidators.push_back(std::move(validator));
+}
+
TLogger TLogger::WithStructuredValidator(TStructuredValidator validator) const
{
auto result = *this;
- result.StructuredValidators_.push_back(std::move(validator));
+ result.AddStructuredValidator(std::move(validator));
return result;
}
@@ -255,19 +262,39 @@ TLogger TLogger::WithMinLevel(ELogLevel minLevel) const
return result;
}
-const TString& TLogger::GetTag() const
+const std::string& TLogger::GetTag() const
{
- return Tag_;
+ static const std::string emptyResult;
+ return CoWState_ ? CoWState_->Tag : emptyResult;
}
const TLogger::TStructuredTags& TLogger::GetStructuredTags() const
{
- return StructuredTags_;
+ static const TStructuredTags emptyResult;
+ return CoWState_ ? CoWState_->StructuredTags : emptyResult;
}
const TLogger::TStructuredValidators& TLogger::GetStructuredValidators() const
{
- return StructuredValidators_;
+ static const TStructuredValidators emptyResult;
+ return CoWState_ ? CoWState_->StructuredValidators : emptyResult;
+}
+
+TLogger::TCoWState* TLogger::GetMutableCoWState()
+{
+ if (!CoWState_ || GetRefCounter(CoWState_.get())->GetRefCount() > 1) {
+ auto uniquelyOwnedState = New<TCoWState>();
+ if (CoWState_) {
+ *uniquelyOwnedState = *CoWState_;
+ }
+ CoWState_ = StaticPointerCast<const TCoWState>(std::move(uniquelyOwnedState));
+ }
+ return const_cast<TCoWState*>(CoWState_.get());
+}
+
+void TLogger::ResetCoWState()
+{
+ CoWState_.Reset();
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/logging/logger.h b/library/cpp/yt/logging/logger.h
index eff5da078ea..510acf13101 100644
--- a/library/cpp/yt/logging/logger.h
+++ b/library/cpp/yt/logging/logger.h
@@ -175,7 +175,7 @@ public:
using TStructuredValidator = std::function<void(const NYson::TYsonString&)>;
using TStructuredValidators = std::vector<TStructuredValidator>;
- using TStructuredTag = std::pair<TString, NYson::TYsonString>;
+ using TStructuredTag = std::pair<std::string, NYson::TYsonString>;
// TODO(max42): switch to TCompactVector after YT-15430.
using TStructuredTags = std::vector<TStructuredTag>;
@@ -215,14 +215,16 @@ public:
void Write(TLogEvent&& event) const;
- void AddRawTag(const TString& tag);
+ void AddRawTag(const std::string& tag);
template <class... TArgs>
void AddTag(const char* format, TArgs&&... args);
template <class TType>
void AddStructuredTag(TStringBuf key, TType value);
- TLogger WithRawTag(const TString& tag) const;
+ void AddStructuredValidator(TStructuredValidator validator);
+
+ TLogger WithRawTag(const std::string& tag) const;
template <class... TArgs>
TLogger WithTag(const char* format, TArgs&&... args) const;
@@ -235,21 +237,31 @@ public:
TLogger WithEssential(bool essential = true) const;
- const TString& GetTag() const;
+ const std::string& GetTag() const;
const TStructuredTags& GetStructuredTags() const;
const TStructuredValidators& GetStructuredValidators() const;
protected:
+ // NB: Mind TSerializableLogger when changing the state.
// These fields are set only during logger creation, so they are effectively const
// and accessing them is thread-safe.
ILogManager* LogManager_ = nullptr;
const TLoggingCategory* Category_ = nullptr;
bool Essential_ = false;
ELogLevel MinLevel_ = NullLoggerMinLevel;
- TString Tag_;
- TStructuredTags StructuredTags_;
- TStructuredValidators StructuredValidators_;
+
+ struct TCoWState final
+ {
+ std::string Tag;
+ TStructuredTags StructuredTags;
+ TStructuredValidators StructuredValidators;
+ };
+
+ TIntrusivePtr<const TCoWState> CoWState_;
+
+ TCoWState* GetMutableCoWState();
+ void ResetCoWState();
private:
//! This method checks level against category's min level.