Add BinlogKeyValue logging.

This commit is contained in:
levlam 2021-06-16 05:23:22 +03:00
parent d069de6a8b
commit a36266a764
6 changed files with 13 additions and 8 deletions

View File

@ -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"

View File

@ -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<string, string> prefix_get(Slice prefix) override {
// TODO: optimize with std::map?
auto lock = rw_mutex_.lock_write().move_as_ok();
std::unordered_map<string, string> res;
for (const auto &kv : map_) {

View File

@ -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());

View File

@ -27,6 +27,8 @@
namespace td {
extern int32 VERBOSITY_NAME(binlog);
struct BinlogInfo {
bool was_created{false};
uint64 last_id{0};

View File

@ -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();

View File

@ -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) {