MCPcopy Create free account
hub / github.com/catboost/catboost / TReopenLogBackend

Class TReopenLogBackend

library/cpp/logger/reopen.h:12–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include <atomic>
11
12class TReopenLogBackend: public TLogBackend {
13public:
14 explicit TReopenLogBackend(THolder<TLogBackend>&& backend, ui64 bytesWrittenLimit = 1_GB)
15 : Backend_(std::move(backend)), BytesWrittenLimit_(bytesWrittenLimit), BytesWritten_(0) {
16 Y_ENSURE(BytesWrittenLimit_ > 0);
17 }
18
19 void WriteData(const TLogRecord& rec) override {
20 const ui64 prevWritten = BytesWritten_.fetch_add(rec.Len);
21 if (prevWritten < BytesWrittenLimit_ && prevWritten + rec.Len >= BytesWrittenLimit_) {
22 try {
23 ReopenLog();
24 } catch (...) {
25 }
26 }
27 Backend_->WriteData(rec);
28 }
29
30 void ReopenLog() override {
31 BytesWritten_.store(0);
32 Backend_->ReopenLog();
33 }
34
35private:
36 const THolder<TLogBackend> Backend_;
37
38 const ui64 BytesWrittenLimit_;
39 std::atomic<ui64> BytesWritten_;
40};

Callers 1

Y_UNIT_TESTFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected