From b21fc85219838370e58756da41e9d45668f2c198 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 11 Jun 2020 02:25:50 +0300 Subject: [PATCH] Add BinlogInterface::add/rewrite/erase. GitOrigin-RevId: fdb0f4f2d2af0f8ab540c0249ddfff9b9c4af8fb --- tddb/td/db/binlog/BinlogHelper.h | 26 +++++++------------------- tddb/td/db/binlog/BinlogInterface.h | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/tddb/td/db/binlog/BinlogHelper.h b/tddb/td/db/binlog/BinlogHelper.h index e06498e71..763ff54ff 100644 --- a/tddb/td/db/binlog/BinlogHelper.h +++ b/tddb/td/db/binlog/BinlogHelper.h @@ -9,36 +9,24 @@ #include "td/actor/PromiseFuture.h" #include "td/db/binlog/BinlogEvent.h" +#include "td/db/binlog/BinlogInterface.h" #include "td/utils/common.h" #include "td/utils/StorerBase.h" namespace td { -template -uint64 binlog_add(const BinlogT &binlog_ptr, int32 type, const Storer &storer, Promise<> promise = Promise<>()) { - auto logevent_id = binlog_ptr->next_id(); - binlog_ptr->add_raw_event(logevent_id, BinlogEvent::create_raw(logevent_id, type, 0, storer), std::move(promise)); - return logevent_id; +inline uint64 binlog_add(BinlogInterface *binlog_ptr, int32 type, const Storer &storer, Promise<> promise = Promise<>()) { + return binlog_ptr->add(type, storer, std::move(promise)); } -template -uint64 binlog_rewrite(const BinlogT &binlog_ptr, uint64 logevent_id, int32 type, const Storer &storer, +inline uint64 binlog_rewrite(BinlogInterface *binlog_ptr, uint64 logevent_id, int32 type, const Storer &storer, Promise<> promise = Promise<>()) { - auto seq_no = binlog_ptr->next_id(); - binlog_ptr->add_raw_event(seq_no, BinlogEvent::create_raw(logevent_id, type, BinlogEvent::Flags::Rewrite, storer), - std::move(promise)); - return seq_no; + return binlog_ptr->rewrite(logevent_id, type, storer, std::move(promise)); } -template -uint64 binlog_erase(const BinlogT &binlog_ptr, uint64 logevent_id, Promise<> promise = Promise<>()) { - auto seq_no = binlog_ptr->next_id(); - binlog_ptr->add_raw_event(seq_no, - BinlogEvent::create_raw(logevent_id, BinlogEvent::ServiceTypes::Empty, - BinlogEvent::Flags::Rewrite, EmptyStorer()), - std::move(promise)); - return seq_no; +inline uint64 binlog_erase(BinlogInterface *binlog_ptr, uint64 logevent_id, Promise<> promise = Promise<>()) { + return binlog_ptr->erase(logevent_id, std::move(promise)); } } // namespace td diff --git a/tddb/td/db/binlog/BinlogInterface.h b/tddb/td/db/binlog/BinlogInterface.h index 7c81eb688..76281c1c6 100644 --- a/tddb/td/db/binlog/BinlogInterface.h +++ b/tddb/td/db/binlog/BinlogInterface.h @@ -40,6 +40,29 @@ class BinlogInterface { void lazy_sync(Promise<> promise = Promise<>()) { add_raw_event_impl(next_id(), BufferSlice(), std::move(promise), {}); } + + uint64 add(int32 type, const Storer &storer, Promise<> promise = Promise<>()) { + auto logevent_id = next_id(); + add_raw_event_impl(logevent_id, BinlogEvent::create_raw(logevent_id, type, 0, storer), std::move(promise), {}); + return logevent_id; + } + + uint64 rewrite(uint64 logevent_id, int32 type, const Storer &storer, Promise<> promise = Promise<>()) { + auto seq_no = next_id(); + add_raw_event_impl(seq_no, BinlogEvent::create_raw(logevent_id, type, BinlogEvent::Flags::Rewrite, storer), + std::move(promise), {}); + return seq_no; + } + + uint64 erase(uint64 logevent_id, Promise<> promise = Promise<>()) { + auto seq_no = next_id(); + add_raw_event_impl(seq_no, + BinlogEvent::create_raw(logevent_id, BinlogEvent::ServiceTypes::Empty, + BinlogEvent::Flags::Rewrite, EmptyStorer()), + std::move(promise), {}); + return seq_no; + } + virtual void force_sync(Promise<> promise) = 0; virtual void force_flush() = 0; virtual void change_key(DbKey db_key, Promise<> promise = Promise<>()) = 0;