2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-12-31 23:02:34 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
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/actor/PromiseFuture.h"
|
|
|
|
|
|
|
|
#include "td/db/binlog/BinlogEvent.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
|
|
|
|
namespace td {
|
2019-01-06 20:11:02 +01:00
|
|
|
|
2018-06-28 15:52:40 +02:00
|
|
|
template <class BinlogT, class StorerT>
|
2018-10-14 03:01:02 +02:00
|
|
|
uint64 binlog_add(const BinlogT &binlog_ptr, int32 type, const StorerT &storer, Promise<> promise = Promise<>()) {
|
2018-06-28 15:52:40 +02:00
|
|
|
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;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-06-28 15:52:40 +02:00
|
|
|
template <class BinlogT, class StorerT>
|
2018-09-19 00:35:45 +02:00
|
|
|
uint64 binlog_rewrite(const BinlogT &binlog_ptr, uint64 logevent_id, int32 type, const StorerT &storer,
|
2018-10-14 03:01:02 +02:00
|
|
|
Promise<> promise = Promise<>()) {
|
2018-06-28 15:52:40 +02:00
|
|
|
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;
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-06-28 17:12:20 +02:00
|
|
|
#define binlog_erase(...) binlog_erase_impl({__FILE__, __LINE__}, __VA_ARGS__)
|
|
|
|
|
2018-06-28 15:52:40 +02:00
|
|
|
template <class BinlogT>
|
2018-09-19 00:35:45 +02:00
|
|
|
uint64 binlog_erase_impl(BinlogDebugInfo info, const BinlogT &binlog_ptr, uint64 logevent_id,
|
2018-10-14 03:01:02 +02:00
|
|
|
Promise<> promise = Promise<>()) {
|
2018-06-28 15:52:40 +02:00
|
|
|
auto seq_no = binlog_ptr->next_id();
|
2018-06-28 17:12:20 +02:00
|
|
|
binlog_ptr->add_raw_event(info, seq_no,
|
2018-06-28 15:52:40 +02:00
|
|
|
BinlogEvent::create_raw(logevent_id, BinlogEvent::ServiceTypes::Empty,
|
|
|
|
BinlogEvent::Flags::Rewrite, EmptyStorer()),
|
|
|
|
std::move(promise));
|
|
|
|
return seq_no;
|
|
|
|
}
|
2019-01-06 20:11:02 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|