aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2025-05-21 19:33:22 +0000
committerAlexander Smirnov <alex@ydb.tech>2025-05-21 19:33:22 +0000
commit2747776ba820b0878ed3d1b47f36e14d3af8d5f0 (patch)
tree6b0f49dad7ebf7b32ca775e357719d534ed01721 /library/cpp
parentc63302006bb8e860e3c8446a59a5fe80e3e5ac3c (diff)
parentf111cf8a3210e5d31ec55a0e035c0b2849ee518d (diff)
downloadydb-2747776ba820b0878ed3d1b47f36e14d3af8d5f0.tar.gz
Merge pull request #18635 from ydb-platform/merge-libs-250521-1607
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/logging/logger-inl.h25
-rw-r--r--library/cpp/yt/logging/logger.cpp15
-rw-r--r--library/cpp/yt/logging/logger.h4
-rw-r--r--library/cpp/yt/memory/non_null_ptr.h2
-rw-r--r--library/cpp/yt/string/string_builder-inl.h8
-rw-r--r--library/cpp/yt/string/string_builder.h4
6 files changed, 27 insertions, 31 deletions
diff --git a/library/cpp/yt/logging/logger-inl.h b/library/cpp/yt/logging/logger-inl.h
index c9a98cb3b44..f63f259d5f0 100644
--- a/library/cpp/yt/logging/logger-inl.h
+++ b/library/cpp/yt/logging/logger-inl.h
@@ -77,17 +77,26 @@ Y_FORCE_INLINE ELogLevel TLogger::GetEffectiveLoggingLevel(ELogLevel level, cons
Y_FORCE_INLINE bool TLogger::IsLevelEnabled(ELogLevel level) const
{
- // This is the first check which is intended to be inlined next to
- // logging invocation point. Check below is almost zero-cost due
- // to branch prediction (which requires inlining for proper work).
- if (level < MinLevel_) {
+ if (!Category_) {
return false;
}
- // Next check is heavier and requires full log manager definition which
- // is undesirable in -inl.h header file. This is why we extract it
- // to a separate method which is implemented in cpp file.
- return IsLevelEnabledHeavy(level);
+ [[unlikely]] if (
+ Category_->CurrentVersion.load(std::memory_order::relaxed) !=
+ Category_->ActualVersion->load(std::memory_order::relaxed))
+ {
+ UpdateCategory();
+ }
+
+ if (level < Category_->MinPlainTextLevel) {
+ return false;
+ }
+
+ if (level < GetThreadMinLogLevel()) {
+ return false;
+ }
+
+ return true;
}
Y_FORCE_INLINE const TLogger& TLogger::operator()() const
diff --git a/library/cpp/yt/logging/logger.cpp b/library/cpp/yt/logging/logger.cpp
index 38fd5b6e134..7e59a3eb2b2 100644
--- a/library/cpp/yt/logging/logger.cpp
+++ b/library/cpp/yt/logging/logger.cpp
@@ -169,20 +169,9 @@ const TLoggingCategory* TLogger::GetCategory() const
return Category_;
}
-bool TLogger::IsLevelEnabledHeavy(ELogLevel level) const
+void TLogger::UpdateCategory() const
{
- // Note that we managed to reach this point, i.e. level >= MinLevel_,
- // which implies that MinLevel_ != ELogLevel::Maximum, so this logger was not
- // default constructed, thus it has non-trivial category.
- YT_ASSERT(Category_);
-
- if (Category_->CurrentVersion != Category_->ActualVersion->load(std::memory_order::relaxed)) {
- LogManager_->UpdateCategory(const_cast<TLoggingCategory*>(Category_));
- }
-
- return
- level >= Category_->MinPlainTextLevel &&
- level >= ThreadMinLogLevel();
+ LogManager_->UpdateCategory(const_cast<TLoggingCategory*>(Category_));
}
bool TLogger::GetAbortOnAlert() const
diff --git a/library/cpp/yt/logging/logger.h b/library/cpp/yt/logging/logger.h
index 1dc241ed81a..a0f2591c030 100644
--- a/library/cpp/yt/logging/logger.h
+++ b/library/cpp/yt/logging/logger.h
@@ -274,9 +274,7 @@ protected:
void ResetCoWState();
private:
- //! This method checks level against category's min level.
- //! Refer to comment in TLogger::IsLevelEnabled for more details.
- bool IsLevelEnabledHeavy(ELogLevel level) const;
+ void UpdateCategory() const;
};
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/memory/non_null_ptr.h b/library/cpp/yt/memory/non_null_ptr.h
index f5992216c6a..7e5589ec28a 100644
--- a/library/cpp/yt/memory/non_null_ptr.h
+++ b/library/cpp/yt/memory/non_null_ptr.h
@@ -20,7 +20,7 @@ public:
TNonNullPtrBase(const TNonNullPtrBase& other) = default;
TNonNullPtrBase(std::nullptr_t) = delete;
- TNonNullPtrBase operator=(const TNonNullPtrBase&) = delete;
+ TNonNullPtrBase& operator=(const TNonNullPtrBase&) = default;
T* operator->() const noexcept;
T& operator*() const noexcept;
diff --git a/library/cpp/yt/string/string_builder-inl.h b/library/cpp/yt/string/string_builder-inl.h
index 7027f9acc12..5d66e1b0ded 100644
--- a/library/cpp/yt/string/string_builder-inl.h
+++ b/library/cpp/yt/string/string_builder-inl.h
@@ -94,7 +94,7 @@ void TStringBuilderBase::AppendFormat(const char (&format)[Length], TArgs&& ...
////////////////////////////////////////////////////////////////////////////////
-inline TString TStringBuilder::Flush()
+inline std::string TStringBuilder::Flush()
{
Buffer_.resize(GetLength());
auto result = std::move(Buffer_);
@@ -104,14 +104,14 @@ inline TString TStringBuilder::Flush()
inline void TStringBuilder::DoReset()
{
- Buffer_ = {};
+ Buffer_.clear();
}
inline void TStringBuilder::DoReserve(size_t newLength)
{
- Buffer_.ReserveAndResize(newLength);
+ Buffer_.resize(newLength);
auto capacity = Buffer_.capacity();
- Buffer_.ReserveAndResize(capacity);
+ Buffer_.resize(capacity);
Begin_ = &*Buffer_.begin();
End_ = Begin_ + capacity;
}
diff --git a/library/cpp/yt/string/string_builder.h b/library/cpp/yt/string/string_builder.h
index ac3aa26a7c1..82caed29943 100644
--- a/library/cpp/yt/string/string_builder.h
+++ b/library/cpp/yt/string/string_builder.h
@@ -52,10 +52,10 @@ class TStringBuilder
: public TStringBuilderBase
{
public:
- TString Flush();
+ std::string Flush();
protected:
- TString Buffer_;
+ std::string Buffer_;
void DoReset() override;
void DoReserve(size_t size) override;