Add BinlogInterface::add/rewrite/erase.

GitOrigin-RevId: fdb0f4f2d2af0f8ab540c0249ddfff9b9c4af8fb
This commit is contained in:
levlam 2020-06-11 02:25:50 +03:00
parent 8e7c6fcda2
commit b21fc85219
2 changed files with 30 additions and 19 deletions

View File

@ -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 <class BinlogT>
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 <class BinlogT>
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 <class BinlogT>
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

View File

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