2018-12-31 20:04:05 +01:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
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
|
2018-07-03 21:29:04 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/db/binlog/BinlogEvent.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2018-07-03 21:29:04 +02:00
|
|
|
#include "td/utils/logging.h"
|
2018-07-17 15:49:57 +02:00
|
|
|
#include "td/utils/Status.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
namespace detail {
|
2019-10-22 01:12:58 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class BinlogEventsProcessor {
|
|
|
|
public:
|
2018-07-16 12:07:00 +02:00
|
|
|
Status add_event(BinlogEvent &&event) TD_WARN_UNUSED_RESULT {
|
|
|
|
return do_event(std::move(event));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class CallbackT>
|
|
|
|
void for_each(CallbackT &&callback) {
|
2023-01-16 10:47:37 +01:00
|
|
|
for (size_t i = 0; i < event_ids_.size(); i++) {
|
|
|
|
LOG_CHECK(i == 0 || event_ids_[i - 1] < event_ids_[i])
|
|
|
|
<< event_ids_[i - 1] << " " << events_[i - 1].public_to_string() << " " << event_ids_[i] << " "
|
|
|
|
<< events_[i].public_to_string();
|
|
|
|
if ((event_ids_[i] & 1) == 0) {
|
2018-12-31 20:04:05 +01:00
|
|
|
callback(events_[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-16 10:47:37 +01:00
|
|
|
uint64 last_event_id() const {
|
|
|
|
return last_event_id_;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
int64 offset() const {
|
|
|
|
return offset_;
|
|
|
|
}
|
|
|
|
int64 total_raw_events_size() const {
|
|
|
|
return total_raw_events_size_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-01-16 10:47:37 +01:00
|
|
|
// holds (event_id * 2 + was_deleted)
|
|
|
|
std::vector<uint64> event_ids_;
|
2018-12-31 20:04:05 +01:00
|
|
|
std::vector<BinlogEvent> events_;
|
|
|
|
size_t total_events_{0};
|
|
|
|
size_t empty_events_{0};
|
2023-01-16 10:47:37 +01:00
|
|
|
uint64 last_event_id_{0};
|
2018-12-31 20:04:05 +01:00
|
|
|
int64 offset_{0};
|
|
|
|
int64 total_raw_events_size_{0};
|
|
|
|
|
2018-07-16 12:07:00 +02:00
|
|
|
Status do_event(BinlogEvent &&event);
|
2018-12-31 20:04:05 +01:00
|
|
|
void compactify();
|
|
|
|
};
|
2019-10-22 01:12:58 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace detail
|
|
|
|
} // namespace td
|