diff options
author | George Hazan <george.hazan@gmail.com> | 2024-09-29 19:03:55 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-09-29 19:04:03 +0300 |
commit | cebfc5c8facbf6ae335499f7f4b3dc57a60af999 (patch) | |
tree | 4c39e613c87f6164df1fe80601e611987aaaec84 /protocols/Telegram/tdlib/td/tddb | |
parent | 189164bebda4bca9bb3d672500d844bfe7f26517 (diff) |
TDLIB update up to the current state
Diffstat (limited to 'protocols/Telegram/tdlib/td/tddb')
15 files changed, 108 insertions, 62 deletions
diff --git a/protocols/Telegram/tdlib/td/tddb/CMakeLists.txt b/protocols/Telegram/tdlib/td/tddb/CMakeLists.txt index 036f0ca61c..85573170dc 100644 --- a/protocols/Telegram/tdlib/td/tddb/CMakeLists.txt +++ b/protocols/Telegram/tdlib/td/tddb/CMakeLists.txt @@ -6,7 +6,6 @@ if (NOT DEFINED CMAKE_INSTALL_LIBDIR) set(CMAKE_INSTALL_LIBDIR "lib") endif() -#SOURCE SETS set(TDDB_SOURCE td/db/binlog/Binlog.cpp td/db/binlog/BinlogEvent.cpp @@ -14,6 +13,8 @@ set(TDDB_SOURCE td/db/binlog/detail/BinlogEventsBuffer.cpp td/db/binlog/detail/BinlogEventsProcessor.cpp + td/db/detail/RawSqliteDb.cpp + td/db/SqliteConnectionSafe.cpp td/db/SqliteDb.cpp td/db/SqliteKeyValue.cpp @@ -21,8 +22,6 @@ set(TDDB_SOURCE td/db/SqliteStatement.cpp td/db/TQueue.cpp - td/db/detail/RawSqliteDb.cpp - td/db/binlog/Binlog.h td/db/binlog/BinlogEvent.h td/db/binlog/BinlogHelper.h @@ -56,7 +55,7 @@ if (NOT CMAKE_CROSSCOMPILING) target_link_libraries(binlog_dump PRIVATE tddb) endif() -install(TARGETS tddb EXPORT TdTargets +install(TARGETS tddb EXPORT TdStaticTargets LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/BinlogKeyValue.h b/protocols/Telegram/tdlib/td/tddb/td/db/BinlogKeyValue.h index 6b6e68422d..a43c1ba8fc 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/BinlogKeyValue.h +++ b/protocols/Telegram/tdlib/td/tddb/td/db/BinlogKeyValue.h @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -14,6 +14,7 @@ #include "td/utils/algorithm.h" #include "td/utils/buffer.h" #include "td/utils/common.h" +#include "td/utils/FlatHashMap.h" #include "td/utils/HashTableUtils.h" #include "td/utils/logging.h" #include "td/utils/misc.h" @@ -25,6 +26,7 @@ #include "td/utils/tl_parsers.h" #include "td/utils/tl_storers.h" +#include <functional> #include <memory> #include <unordered_map> #include <utility> @@ -83,6 +85,10 @@ class BinlogKeyValue final : public KeyValueSyncInterface { [&](const BinlogEvent &binlog_event) { Event event; event.parse(TlParser(binlog_event.get_data())); + if (event.key.empty()) { + LOG(ERROR) << "Have event with empty key"; + return; + } map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_)); }, std::move(db_key), DbKey::empty(), scheduler_id)); @@ -104,6 +110,10 @@ class BinlogKeyValue final : public KeyValueSyncInterface { void external_init_handle(const BinlogEvent &binlog_event) { Event event; event.parse(TlParser(binlog_event.get_data())); + if (event.key.empty()) { + LOG(ERROR) << "Have external event with empty key"; + return; + } map_.emplace(event.key.str(), std::make_pair(event.value.str(), binlog_event.id_)); } @@ -121,6 +131,7 @@ class BinlogKeyValue final : public KeyValueSyncInterface { SeqNo set(string key, string value) final { auto lock = rw_mutex_.lock_write().move_as_ok(); uint64 old_event_id = 0; + CHECK(!key.empty()); auto it_ok = map_.emplace(key, std::make_pair(value, 0)); if (!it_ok.second) { if (it_ok.first->second.first == value) { @@ -202,14 +213,21 @@ class BinlogKeyValue final : public KeyValueSyncInterface { return it->second.first; } - void force_sync(Promise<> &&promise) final { - binlog_->force_sync(std::move(promise)); + void force_sync(Promise<> &&promise, const char *source) final { + binlog_->force_sync(std::move(promise), source); } void lazy_sync(Promise<> &&promise) { binlog_->lazy_sync(std::move(promise)); } + void for_each(std::function<void(Slice, Slice)> func) final { + auto lock = rw_mutex_.lock_write().move_as_ok(); + for (const auto &kv : map_) { + func(kv.first, kv.second.first); + } + } + std::unordered_map<string, string, Hash<string>> prefix_get(Slice prefix) final { auto lock = rw_mutex_.lock_write().move_as_ok(); std::unordered_map<string, string, Hash<string>> res; @@ -221,9 +239,10 @@ class BinlogKeyValue final : public KeyValueSyncInterface { return res; } - std::unordered_map<string, string, Hash<string>> get_all() final { + FlatHashMap<string, string> get_all() final { auto lock = rw_mutex_.lock_write().move_as_ok(); - std::unordered_map<string, string, Hash<string>> res; + FlatHashMap<string, string> res; + res.reserve(map_.size()); for (const auto &kv : map_) { res.emplace(kv.first, kv.second.first); } @@ -248,6 +267,7 @@ class BinlogKeyValue final : public KeyValueSyncInterface { seq_no++; } } + template <class T> friend class BinlogKeyValue; @@ -256,7 +276,7 @@ class BinlogKeyValue final : public KeyValueSyncInterface { } private: - std::unordered_map<string, std::pair<string, uint64>, Hash<string>> map_; + FlatHashMap<string, std::pair<string, uint64>> map_; std::shared_ptr<BinlogT> binlog_; RwMutex rw_mutex_; int32 magic_ = MAGIC; @@ -268,14 +288,14 @@ inline void BinlogKeyValue<Binlog>::add_event(uint64 seq_no, BufferSlice &&event } template <> -inline void BinlogKeyValue<Binlog>::force_sync(Promise<> &&promise) { - binlog_->sync(); +inline void BinlogKeyValue<Binlog>::force_sync(Promise<> &&promise, const char *source) { + binlog_->sync(source); promise.set_value(Unit()); } template <> inline void BinlogKeyValue<Binlog>::lazy_sync(Promise<> &&promise) { - force_sync(std::move(promise)); + force_sync(std::move(promise), "lazy_sync"); } } // namespace td diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/KeyValueSyncInterface.h b/protocols/Telegram/tdlib/td/tddb/td/db/KeyValueSyncInterface.h index 111882fb29..2e68e3f7f9 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/KeyValueSyncInterface.h +++ b/protocols/Telegram/tdlib/td/tddb/td/db/KeyValueSyncInterface.h @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -7,10 +7,12 @@ #pragma once #include "td/utils/common.h" +#include "td/utils/FlatHashMap.h" #include "td/utils/HashTableUtils.h" #include "td/utils/Promise.h" #include "td/utils/Slice.h" +#include <functional> #include <unordered_map> namespace td { @@ -34,9 +36,11 @@ class KeyValueSyncInterface { virtual string get(const string &key) = 0; + virtual void for_each(std::function<void(Slice, Slice)> func) = 0; + virtual std::unordered_map<string, string, Hash<string>> prefix_get(Slice prefix) = 0; - virtual std::unordered_map<string, string, Hash<string>> get_all() = 0; + virtual FlatHashMap<string, string> get_all() = 0; virtual SeqNo erase(const string &key) = 0; @@ -44,7 +48,7 @@ class KeyValueSyncInterface { virtual void erase_by_prefix(Slice prefix) = 0; - virtual void force_sync(Promise<> &&promise) = 0; + virtual void force_sync(Promise<> &&promise, const char *source) = 0; virtual void close(Promise<> promise) = 0; }; diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/SeqKeyValue.h b/protocols/Telegram/tdlib/td/tddb/td/db/SeqKeyValue.h index 9870ac9391..125f036019 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/SeqKeyValue.h +++ b/protocols/Telegram/tdlib/td/tddb/td/db/SeqKeyValue.h @@ -1,16 +1,15 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #pragma once -#include "td/utils/HashTableUtils.h" +#include "td/utils/common.h" +#include "td/utils/FlatHashMap.h" #include "td/utils/Slice.h" -#include <unordered_map> - namespace td { class SeqKeyValue { @@ -24,6 +23,7 @@ class SeqKeyValue { ~SeqKeyValue() = default; SeqNo set(Slice key, Slice value) { + CHECK(!key.empty()); auto it_ok = map_.emplace(key.str(), value.str()); if (!it_ok.second) { if (it_ok.first->second == value) { @@ -84,13 +84,19 @@ class SeqKeyValue { return map_.size(); } - std::unordered_map<string, string, Hash<string>> get_all() const { - return map_; + FlatHashMap<string, string> get_all() const { + FlatHashMap<string, string> result; + result.reserve(map_.size()); + for (auto &it : map_) { + result.emplace(it.first, it.second); + } + return result; } private: - std::unordered_map<string, string, Hash<string>> map_; + FlatHashMap<string, string> map_; SeqNo current_id_ = 0; + SeqNo next_seq_no() { return ++current_id_; } diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/SqliteDb.h b/protocols/Telegram/tdlib/td/tddb/td/db/SqliteDb.h index 6e242e9ebd..2d78be3602 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/SqliteDb.h +++ b/protocols/Telegram/tdlib/td/tddb/td/db/SqliteDb.h @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -11,6 +11,7 @@ #include "td/db/detail/RawSqliteDb.h" +#include "td/utils/common.h" #include "td/utils/optional.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/SqliteKeyValue.h b/protocols/Telegram/tdlib/td/tddb/td/db/SqliteKeyValue.h index 914825da8a..222cbeb120 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/SqliteKeyValue.h +++ b/protocols/Telegram/tdlib/td/tddb/td/db/SqliteKeyValue.h @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -79,11 +79,17 @@ class SqliteKeyValue { if (!prefix.empty()) { next = next_prefix(prefix); } - get_by_range(prefix, next, callback); + get_by_range_impl(prefix, next, true, callback); } template <class CallbackT> void get_by_range(Slice from, Slice till, CallbackT &&callback) { + get_by_range_impl(from, till, false, std::move(callback)); + } + + private: + template <class CallbackT> + void get_by_range_impl(Slice from, Slice till, bool strip_key_prefix, CallbackT &&callback) { SqliteStatement *stmt = nullptr; if (from.empty()) { stmt = &get_all_stmt_; @@ -100,14 +106,17 @@ class SqliteKeyValue { auto guard = stmt->guard(); stmt->step().ensure(); while (stmt->has_row()) { - if (!callback(stmt->view_blob(0), stmt->view_blob(1))) { + auto key = stmt->view_blob(0); + if (strip_key_prefix) { + key.remove_prefix(from.size()); + } + if (!callback(key, stmt->view_blob(1))) { return; } stmt->step().ensure(); } } - private: string table_name_; SqliteDb db_; SqliteStatement get_stmt_; diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/SqliteKeyValueSafe.h b/protocols/Telegram/tdlib/td/tddb/td/db/SqliteKeyValueSafe.h index 9608514671..adde5697c7 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/SqliteKeyValueSafe.h +++ b/protocols/Telegram/tdlib/td/tddb/td/db/SqliteKeyValueSafe.h @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -11,6 +11,8 @@ #include "td/actor/SchedulerLocalStorage.h" +#include "td/utils/common.h" + #include <memory> namespace td { diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/TsSeqKeyValue.h b/protocols/Telegram/tdlib/td/tddb/td/db/TsSeqKeyValue.h index ebb4132892..48dd368d22 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/TsSeqKeyValue.h +++ b/protocols/Telegram/tdlib/td/tddb/td/db/TsSeqKeyValue.h @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -8,11 +8,11 @@ #include "td/db/SeqKeyValue.h" -#include "td/utils/HashTableUtils.h" +#include "td/utils/common.h" +#include "td/utils/FlatHashMap.h" #include "td/utils/port/RwMutex.h" #include "td/utils/Slice.h" -#include <unordered_map> #include <utility> namespace td { @@ -69,7 +69,7 @@ class TsSeqKeyValue { return kv_.size(); } - std::unordered_map<string, string, Hash<string>> get_all() const { + FlatHashMap<string, string> get_all() const { auto lock = rw_mutex_.lock_write().move_as_ok(); return kv_.get_all(); } diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/Binlog.cpp b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/Binlog.cpp index adbe97684c..76ca502a97 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/Binlog.cpp +++ b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/Binlog.cpp @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -286,9 +286,9 @@ Status Binlog::close(bool need_sync) { return Status::OK(); } if (need_sync) { - sync(); + sync("close"); } else { - flush(); + flush("close"); } fd_.lock(FileFd::LockFlags::Unlock, path_, 1).ensure(); @@ -373,7 +373,7 @@ void Binlog::do_event(BinlogEvent &&event) { LOG(INFO) << "Load: init encryption"; } else { CHECK(state_ == State::Reindex); - flush(); + flush("do_event"); update_write_encryption(); //LOG(INFO) << format::cond(state_ == State::Run, "Run", "Reindex") << ": init encryption"; } @@ -404,19 +404,21 @@ void Binlog::do_event(BinlogEvent &&event) { fd_size_ += event_size; } -void Binlog::sync() { - flush(); +void Binlog::sync(const char *source) { + flush(source); if (need_sync_) { + LOG(INFO) << "Sync binlog from " << source; auto status = fd_.sync(); LOG_IF(FATAL, status.is_error()) << "Failed to sync binlog: " << status; need_sync_ = false; } } -void Binlog::flush() { +void Binlog::flush(const char *source) { if (state_ == State::Load) { return; } + LOG(DEBUG) << "Flush binlog from " << source; flush_events_buffer(true); // NB: encryption happens during flush if (byte_flow_flag_) { @@ -448,7 +450,7 @@ void Binlog::lazy_flush() { buffer_reader_.sync_with_writer(); auto size = buffer_reader_.size() + events_buffer_size; if (size > (1 << 14)) { - flush(); + flush("lazy_flush"); } else if (size > 0 && need_flush_since_ == 0) { need_flush_since_ = Time::now_cached(); } @@ -660,7 +662,7 @@ void Binlog::do_reindex() { do_event(std::move(event)); // NB: no move is actually happens }); { - flush(); + flush("do_reindex"); if (start_size != 0) { // must sync creation of the file if it is non-empty auto status = fd_.sync_barrier(); LOG_IF(FATAL, status.is_error()) << "Failed to sync binlog: " << status; diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/Binlog.h b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/Binlog.h index 4b13b8a94f..82b8276a22 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/Binlog.h +++ b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/Binlog.h @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -109,8 +109,8 @@ class Binlog { } void add_event(BinlogEvent &&event); - void sync(); - void flush(); + void sync(const char *source); + void flush(const char *source); void lazy_flush(); double need_flush_since() const { return need_flush_since_; diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/BinlogEvent.cpp b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/BinlogEvent.cpp index c74f7378bd..9ad4c5d650 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/BinlogEvent.cpp +++ b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/BinlogEvent.cpp @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -23,7 +23,7 @@ void BinlogEvent::init(string raw_event) { flags_ = parser.fetch_int(); extra_ = static_cast<uint64>(parser.fetch_long()); CHECK(size_ >= MIN_SIZE); - parser.fetch_string_raw<Slice>(size_ - MIN_SIZE); // skip data + parser.template fetch_string_raw<Slice>(size_ - MIN_SIZE); // skip data crc32_ = static_cast<uint32>(parser.fetch_int()); raw_event_ = std::move(raw_event); } @@ -43,7 +43,7 @@ Status BinlogEvent::validate() const { return Status::Error(PSLICE() << "Size of event changed: " << tag("was", size_) << tag("now", size) << tag("real size", raw_event_.size())); } - parser.fetch_string_raw<Slice>(size_ - TAIL_SIZE - sizeof(int)); // skip + parser.template fetch_string_raw<Slice>(size_ - TAIL_SIZE - sizeof(int)); // skip auto stored_crc32 = static_cast<uint32>(parser.fetch_int()); auto calculated_crc = crc32(Slice(as_slice(raw_event_).data(), size_ - TAIL_SIZE)); if (calculated_crc != crc32_ || calculated_crc != stored_crc32) { diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/BinlogInterface.h b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/BinlogInterface.h index d46297f944..c6d6b96644 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/BinlogInterface.h +++ b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/BinlogInterface.h @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -74,7 +74,7 @@ class BinlogInterface { return seq_no; } - virtual void force_sync(Promise<> promise) = 0; + virtual void force_sync(Promise<> promise, const char *source) = 0; virtual void force_flush() = 0; virtual void change_key(DbKey db_key, Promise<> promise) = 0; diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/ConcurrentBinlog.cpp b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/ConcurrentBinlog.cpp index 437a4bbbfa..329e08d300 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/ConcurrentBinlog.cpp +++ b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/ConcurrentBinlog.cpp @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -61,7 +61,8 @@ class BinlogActor final : public Actor { try_flush(); } - void force_sync(Promise<> &&promise) { + void force_sync(Promise<> &&promise, const char *source) { + LOG(INFO) << "Force binlog sync from " << source; auto seq_no = processor_.max_unfinished_seq_no(); if (processor_.max_finished_seq_no() == seq_no) { do_immediate_sync(std::move(promise)); @@ -72,7 +73,7 @@ class BinlogActor final : public Actor { void force_flush() { // TODO: use same logic as in force_sync - binlog_->flush(); + binlog_->flush("force_flush"); flush_flag_ = false; } @@ -115,7 +116,7 @@ class BinlogActor final : public Actor { auto need_flush_since = binlog_->need_flush_since(); auto now = Time::now_cached(); if (now > need_flush_since + FLUSH_TIMEOUT - 1e-9) { - binlog_->flush(); + binlog_->flush("try_flush"); } else { if (!force_sync_flag_) { flush_flag_ = true; @@ -161,7 +162,7 @@ class BinlogActor final : public Actor { flush_flag_ = false; wakeup_at_ = 0; if (need_sync) { - binlog_->sync(); + binlog_->sync("timeout_expired"); // LOG(ERROR) << "BINLOG SYNC"; set_promises(sync_promises_); } else if (need_flush) { @@ -205,12 +206,14 @@ void ConcurrentBinlog::add_raw_event_impl(uint64 event_id, BufferSlice &&raw_eve send_closure(binlog_actor_, &detail::BinlogActor::add_raw_event, event_id, std::move(raw_event), std::move(promise), info); } -void ConcurrentBinlog::force_sync(Promise<> promise) { - send_closure(binlog_actor_, &detail::BinlogActor::force_sync, std::move(promise)); +void ConcurrentBinlog::force_sync(Promise<> promise, const char *source) { + send_closure(binlog_actor_, &detail::BinlogActor::force_sync, std::move(promise), source); } + void ConcurrentBinlog::force_flush() { send_closure(binlog_actor_, &detail::BinlogActor::force_flush); } + void ConcurrentBinlog::change_key(DbKey db_key, Promise<> promise) { send_closure(binlog_actor_, &detail::BinlogActor::change_key, std::move(db_key), std::move(promise)); } diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/ConcurrentBinlog.h b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/ConcurrentBinlog.h index f850e2ad46..321e2ebd50 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/ConcurrentBinlog.h +++ b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/ConcurrentBinlog.h @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -41,7 +41,7 @@ class ConcurrentBinlog final : public BinlogInterface { ConcurrentBinlog &operator=(ConcurrentBinlog &&) = delete; ~ConcurrentBinlog() final; - void force_sync(Promise<> promise) final; + void force_sync(Promise<> promise, const char *source) final; void force_flush() final; void change_key(DbKey db_key, Promise<> promise) final; diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/binlog_dump.cpp b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/binlog_dump.cpp index fd2498f256..050b7b99bd 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/binlog/binlog_dump.cpp +++ b/protocols/Telegram/tdlib/td/tddb/td/db/binlog/binlog_dump.cpp @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) { info[0].compressed_size += event.raw_event_.size(); info[event.type_].compressed_size += event.raw_event_.size(); if (event.type_ == ConfigPmcMagic || event.type_ == BinlogPmcMagic) { - auto key = td::TlParser(event.get_data()).fetch_string<td::Slice>(); + auto key = td::TlParser(event.get_data()).template fetch_string<td::Slice>(); info[event.type_].compressed_trie.add(key); } }, @@ -134,7 +134,7 @@ int main(int argc, char *argv[]) { info[0].full_size += event.raw_event_.size(); info[event.type_].full_size += event.raw_event_.size(); if (event.type_ == ConfigPmcMagic || event.type_ == BinlogPmcMagic) { - auto key = td::TlParser(event.get_data()).fetch_string<td::Slice>(); + auto key = td::TlParser(event.get_data()).template fetch_string<td::Slice>(); info[event.type_].trie.add(key); } LOG(PLAIN) << "LogEvent[" << td::tag("event_id", td::format::as_hex(event.id_)) |