cb3f390a92
GitOrigin-RevId: a1a491981596c56dbf7541d80ead1ea9f5d5bd04
56 lines
2.0 KiB
C++
56 lines
2.0 KiB
C++
//
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020
|
|
//
|
|
// 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)
|
|
//
|
|
#include "td/telegram/logevent/LogEventHelper.h"
|
|
|
|
#include "td/telegram/Global.h"
|
|
#include "td/telegram/TdDb.h"
|
|
|
|
#include "tddb/td/db/binlog/BinlogHelper.h"
|
|
|
|
#include "td/utils/logging.h"
|
|
|
|
namespace td {
|
|
|
|
void add_log_event(LogeventIdWithGeneration &log_event_id, const Storer &storer, uint32 type, Slice name) {
|
|
LOG(INFO) << "Save " << name << " to binlog";
|
|
if (log_event_id.log_event_id == 0) {
|
|
log_event_id.log_event_id = binlog_add(G()->td_db()->get_binlog(), type, storer);
|
|
LOG(INFO) << "Add " << name << " log event " << log_event_id.log_event_id;
|
|
} else {
|
|
auto new_log_event_id = binlog_rewrite(G()->td_db()->get_binlog(), log_event_id.log_event_id, type, storer);
|
|
LOG(INFO) << "Rewrite " << name << " log event " << log_event_id.log_event_id << " with " << new_log_event_id;
|
|
}
|
|
log_event_id.generation++;
|
|
}
|
|
|
|
void delete_log_event(LogeventIdWithGeneration &log_event_id, uint64 generation, Slice name) {
|
|
LOG(INFO) << "Finish to process " << name << " log event " << log_event_id.log_event_id << " with generation "
|
|
<< generation;
|
|
if (log_event_id.generation == generation) {
|
|
CHECK(log_event_id.log_event_id != 0);
|
|
LOG(INFO) << "Delete " << name << " log event " << log_event_id.log_event_id;
|
|
binlog_erase(G()->td_db()->get_binlog(), log_event_id.log_event_id);
|
|
log_event_id.log_event_id = 0;
|
|
}
|
|
}
|
|
|
|
Promise<Unit> get_erase_log_event_promise(uint64 log_event_id, Promise<Unit> promise) {
|
|
if (log_event_id == 0) {
|
|
return promise;
|
|
}
|
|
|
|
return PromiseCreator::lambda([log_event_id, promise = std::move(promise)](Result<Unit> result) mutable {
|
|
if (!G()->close_flag()) {
|
|
binlog_erase(G()->td_db()->get_binlog(), log_event_id);
|
|
}
|
|
|
|
promise.set_result(std::move(result));
|
|
});
|
|
}
|
|
|
|
} // namespace td
|