2018-12-31 20:04:05 +01:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// 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/db/binlog/BinlogEvent.h"
|
|
|
|
#include "td/db/DbKey.h"
|
|
|
|
|
2021-09-18 23:47:05 +02:00
|
|
|
#include "td/actor/PromiseFuture.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/buffer.h"
|
|
|
|
#include "td/utils/common.h"
|
2020-06-11 15:43:26 +02:00
|
|
|
#include "td/utils/StorerBase.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
namespace td {
|
2019-01-06 20:59:17 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class BinlogInterface {
|
|
|
|
public:
|
|
|
|
BinlogInterface() = default;
|
|
|
|
BinlogInterface(const BinlogInterface &) = delete;
|
|
|
|
BinlogInterface &operator=(const BinlogInterface &) = delete;
|
|
|
|
BinlogInterface(BinlogInterface &&) = delete;
|
|
|
|
BinlogInterface &operator=(BinlogInterface &&) = delete;
|
|
|
|
virtual ~BinlogInterface() = default;
|
|
|
|
|
|
|
|
void close(Promise<> promise = {}) {
|
|
|
|
close_impl(std::move(promise));
|
|
|
|
}
|
|
|
|
void close_and_destroy(Promise<> promise = {}) {
|
|
|
|
close_and_destroy_impl(std::move(promise));
|
|
|
|
}
|
2018-06-28 17:12:20 +02:00
|
|
|
void add_raw_event(BinlogDebugInfo info, uint64 id, BufferSlice &&raw_event, Promise<> promise = Promise<>()) {
|
|
|
|
add_raw_event_impl(id, std::move(raw_event), std::move(promise), info);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
void add_raw_event(uint64 id, BufferSlice &&raw_event, Promise<> promise = Promise<>()) {
|
2018-06-28 17:12:20 +02:00
|
|
|
add_raw_event_impl(id, std::move(raw_event), std::move(promise), {});
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
void lazy_sync(Promise<> promise = Promise<>()) {
|
2018-06-28 17:12:20 +02:00
|
|
|
add_raw_event_impl(next_id(), BufferSlice(), std::move(promise), {});
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2020-06-11 01:25:50 +02:00
|
|
|
|
|
|
|
uint64 add(int32 type, const Storer &storer, Promise<> promise = Promise<>()) {
|
2020-09-22 01:15:09 +02:00
|
|
|
auto log_event_id = next_id();
|
|
|
|
add_raw_event_impl(log_event_id, BinlogEvent::create_raw(log_event_id, type, 0, storer), std::move(promise), {});
|
|
|
|
return log_event_id;
|
2020-06-11 01:25:50 +02:00
|
|
|
}
|
|
|
|
|
2020-09-22 01:15:09 +02:00
|
|
|
uint64 rewrite(uint64 log_event_id, int32 type, const Storer &storer, Promise<> promise = Promise<>()) {
|
2020-06-11 01:25:50 +02:00
|
|
|
auto seq_no = next_id();
|
2020-09-22 01:15:09 +02:00
|
|
|
add_raw_event_impl(seq_no, BinlogEvent::create_raw(log_event_id, type, BinlogEvent::Flags::Rewrite, storer),
|
2020-06-11 01:25:50 +02:00
|
|
|
std::move(promise), {});
|
|
|
|
return seq_no;
|
|
|
|
}
|
|
|
|
|
2020-09-22 01:15:09 +02:00
|
|
|
uint64 erase(uint64 log_event_id, Promise<> promise = Promise<>()) {
|
2020-06-11 01:25:50 +02:00
|
|
|
auto seq_no = next_id();
|
|
|
|
add_raw_event_impl(seq_no,
|
2020-09-22 01:15:09 +02:00
|
|
|
BinlogEvent::create_raw(log_event_id, BinlogEvent::ServiceTypes::Empty,
|
2020-06-11 01:25:50 +02:00
|
|
|
BinlogEvent::Flags::Rewrite, EmptyStorer()),
|
|
|
|
std::move(promise), {});
|
|
|
|
return seq_no;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
virtual void force_sync(Promise<> promise) = 0;
|
|
|
|
virtual void force_flush() = 0;
|
|
|
|
virtual void change_key(DbKey db_key, Promise<> promise = Promise<>()) = 0;
|
|
|
|
|
|
|
|
virtual uint64 next_id() = 0;
|
|
|
|
virtual uint64 next_id(int32 shift) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void close_impl(Promise<> promise) = 0;
|
|
|
|
virtual void close_and_destroy_impl(Promise<> promise) = 0;
|
2018-06-28 17:12:20 +02:00
|
|
|
virtual void add_raw_event_impl(uint64 id, BufferSlice &&raw_event, Promise<> promise, BinlogDebugInfo info) = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2019-01-06 20:59:17 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|