From a36266a764a802a3df14e5f0f80c2cb1640e03f8 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 16 Jun 2021 05:23:22 +0300 Subject: [PATCH] Add BinlogKeyValue logging. --- td/telegram/Logging.cpp | 2 +- tddb/td/db/BinlogKeyValue.h | 8 ++++++-- tddb/td/db/binlog/Binlog.cpp | 5 ++++- tddb/td/db/binlog/Binlog.h | 2 ++ tddb/td/db/binlog/BinlogEvent.cpp | 2 -- tddb/td/db/binlog/BinlogEvent.h | 2 -- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/td/telegram/Logging.cpp b/td/telegram/Logging.cpp index d80606ca4..4759ff6d5 100644 --- a/td/telegram/Logging.cpp +++ b/td/telegram/Logging.cpp @@ -21,7 +21,7 @@ #include "td/telegram/Td.h" #include "td/telegram/UpdatesManager.h" -#include "td/db/binlog/BinlogEvent.h" +#include "td/db/binlog/Binlog.h" #include "td/db/SqliteStatement.h" #include "td/net/GetHostByNameActor.h" diff --git a/tddb/td/db/BinlogKeyValue.h b/tddb/td/db/BinlogKeyValue.h index 0f5dde73d..67f9527e8 100644 --- a/tddb/td/db/BinlogKeyValue.h +++ b/tddb/td/db/BinlogKeyValue.h @@ -126,8 +126,12 @@ class BinlogKeyValue : public KeyValueSyncInterface { if (it_ok.first->second.first == value) { return 0; } + VLOG(binlog) << "Change value of key " << key << " from " << hex_encode(it_ok.first->second.first) << " to " + << hex_encode(value); old_id = it_ok.first->second.second; it_ok.first->second.first = value; + } else { + VLOG(binlog) << "Set value of key " << key << " to " << hex_encode(value); } bool rewrite = false; uint64 id; @@ -152,9 +156,9 @@ class BinlogKeyValue : public KeyValueSyncInterface { if (it == map_.end()) { return 0; } + VLOG(binlog) << "Remove value of key " << key << ", which is " << hex_encode(it->second.first); uint64 id = it->second.second; map_.erase(it); - // LOG(ERROR) << "ADD EVENT"; auto seq_no = binlog_->next_id(); lock.reset(); add_event(seq_no, BinlogEvent::create_raw(id, BinlogEvent::ServiceTypes::Empty, BinlogEvent::Flags::Rewrite, @@ -177,6 +181,7 @@ class BinlogKeyValue : public KeyValueSyncInterface { if (it == map_.end()) { return string(); } + VLOG(binlog) << "Get value of key " << key << ", which is " << hex_encode(it->second.first); return it->second.first; } @@ -189,7 +194,6 @@ class BinlogKeyValue : public KeyValueSyncInterface { } std::unordered_map prefix_get(Slice prefix) override { - // TODO: optimize with std::map? auto lock = rw_mutex_.lock_write().move_as_ok(); std::unordered_map res; for (const auto &kv : map_) { diff --git a/tddb/td/db/binlog/Binlog.cpp b/tddb/td/db/binlog/Binlog.cpp index aea3e444c..c5ea7fb30 100644 --- a/tddb/td/db/binlog/Binlog.cpp +++ b/tddb/td/db/binlog/Binlog.cpp @@ -164,6 +164,8 @@ static int64 file_size(CSlice path) { } } // namespace detail +int32 VERBOSITY_NAME(binlog) = VERBOSITY_NAME(DEBUG) + 8; + Binlog::Binlog() = default; Binlog::~Binlog() { @@ -322,12 +324,13 @@ void Binlog::do_event(BinlogEvent &&event) { auto event_size = event.raw_event_.size(); if (state_ == State::Run || state_ == State::Reindex) { - VLOG(binlog) << "Write binlog event: " << format::cond(state_ == State::Reindex, "[reindex] "); auto validate_status = event.validate(); if (validate_status.is_error()) { LOG(FATAL) << "Failed to validate binlog event " << validate_status << " " << format::as_hex_dump<4>(Slice(event.raw_event_.as_slice().truncate(28))); } + VLOG(binlog) << "Write binlog event: " << format::cond(state_ == State::Reindex, "[reindex] ") + << event.public_to_string(); switch (encryption_type_) { case EncryptionType::None: { buffer_writer_.append(event.raw_event_.clone()); diff --git a/tddb/td/db/binlog/Binlog.h b/tddb/td/db/binlog/Binlog.h index c46d1b5bb..6d0c5dc2c 100644 --- a/tddb/td/db/binlog/Binlog.h +++ b/tddb/td/db/binlog/Binlog.h @@ -27,6 +27,8 @@ namespace td { +extern int32 VERBOSITY_NAME(binlog); + struct BinlogInfo { bool was_created{false}; uint64 last_id{0}; diff --git a/tddb/td/db/binlog/BinlogEvent.cpp b/tddb/td/db/binlog/BinlogEvent.cpp index 8c7f8a1e5..145c7867a 100644 --- a/tddb/td/db/binlog/BinlogEvent.cpp +++ b/tddb/td/db/binlog/BinlogEvent.cpp @@ -13,8 +13,6 @@ namespace td { -int32 VERBOSITY_NAME(binlog) = VERBOSITY_NAME(DEBUG) + 8; - Status BinlogEvent::init(BufferSlice &&raw_event, bool check_crc) { TlParser parser(raw_event.as_slice()); size_ = parser.fetch_int(); diff --git a/tddb/td/db/binlog/BinlogEvent.h b/tddb/td/db/binlog/BinlogEvent.h index 96b1c9d46..e786e2388 100644 --- a/tddb/td/db/binlog/BinlogEvent.h +++ b/tddb/td/db/binlog/BinlogEvent.h @@ -33,8 +33,6 @@ inline auto EmptyStorer() { return create_default_storer(impl); } -extern int32 VERBOSITY_NAME(binlog); - struct BinlogDebugInfo { BinlogDebugInfo() = default; BinlogDebugInfo(const char *file, int line) : file(file), line(line) {