BinlogHelper:: -> binlog_

GitOrigin-RevId: 94cf4585c4f61be2929c5a7cd1a3628b911bc4c5
This commit is contained in:
Arseny Smirnov 2018-06-28 16:52:40 +03:00
parent 05bb41b250
commit 80d4292493
6 changed files with 151 additions and 153 deletions

View File

@ -5154,9 +5154,9 @@ void ContactsManager::save_user(User *u, UserId user_id, bool from_binlog) {
auto logevent = UserLogEvent(user_id, *u); auto logevent = UserLogEvent(user_id, *u);
auto storer = LogEventStorerImpl<UserLogEvent>(logevent); auto storer = LogEventStorerImpl<UserLogEvent>(logevent);
if (u->logevent_id == 0) { if (u->logevent_id == 0) {
u->logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Users, storer); u->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Users, storer);
} else { } else {
BinlogHelper::rewrite(G()->td_db()->get_binlog(), u->logevent_id, LogEvent::HandlerType::Users, storer); binlog_rewrite(G()->td_db()->get_binlog(), u->logevent_id, LogEvent::HandlerType::Users, storer);
} }
} }
@ -5166,7 +5166,7 @@ void ContactsManager::save_user(User *u, UserId user_id, bool from_binlog) {
void ContactsManager::on_binlog_user_event(BinlogEvent &&event) { void ContactsManager::on_binlog_user_event(BinlogEvent &&event) {
if (!G()->parameters().use_chat_info_db) { if (!G()->parameters().use_chat_info_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
return; return;
} }
@ -5242,7 +5242,7 @@ void ContactsManager::on_save_user_to_database(UserId user_id, bool success) {
} }
if (u->is_saved && u->is_status_saved) { if (u->is_saved && u->is_status_saved) {
if (u->logevent_id != 0) { if (u->logevent_id != 0) {
BinlogHelper::erase(G()->td_db()->get_binlog(), u->logevent_id); binlog_erase(G()->td_db()->get_binlog(), u->logevent_id);
u->logevent_id = 0; u->logevent_id = 0;
} }
} else { } else {
@ -5308,7 +5308,7 @@ void ContactsManager::on_load_user_from_database(UserId user_id, string value) {
if (value != new_value) { if (value != new_value) {
save_user_to_database_impl(u, user_id, std::move(new_value)); save_user_to_database_impl(u, user_id, std::move(new_value));
} else if (u->logevent_id != 0) { } else if (u->logevent_id != 0) {
BinlogHelper::erase(G()->td_db()->get_binlog(), u->logevent_id); binlog_erase(G()->td_db()->get_binlog(), u->logevent_id);
u->logevent_id = 0; u->logevent_id = 0;
} }
} }
@ -5402,9 +5402,9 @@ void ContactsManager::save_chat(Chat *c, ChatId chat_id, bool from_binlog) {
auto logevent = ChatLogEvent(chat_id, *c); auto logevent = ChatLogEvent(chat_id, *c);
auto storer = LogEventStorerImpl<ChatLogEvent>(logevent); auto storer = LogEventStorerImpl<ChatLogEvent>(logevent);
if (c->logevent_id == 0) { if (c->logevent_id == 0) {
c->logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Chats, storer); c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Chats, storer);
} else { } else {
BinlogHelper::rewrite(G()->td_db()->get_binlog(), c->logevent_id, LogEvent::HandlerType::Chats, storer); binlog_rewrite(G()->td_db()->get_binlog(), c->logevent_id, LogEvent::HandlerType::Chats, storer);
} }
} }
@ -5415,7 +5415,7 @@ void ContactsManager::save_chat(Chat *c, ChatId chat_id, bool from_binlog) {
void ContactsManager::on_binlog_chat_event(BinlogEvent &&event) { void ContactsManager::on_binlog_chat_event(BinlogEvent &&event) {
if (!G()->parameters().use_chat_info_db) { if (!G()->parameters().use_chat_info_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
return; return;
} }
@ -5484,7 +5484,7 @@ void ContactsManager::on_save_chat_to_database(ChatId chat_id, bool success) {
} }
if (c->is_saved) { if (c->is_saved) {
if (c->logevent_id != 0) { if (c->logevent_id != 0) {
BinlogHelper::erase(G()->td_db()->get_binlog(), c->logevent_id); binlog_erase(G()->td_db()->get_binlog(), c->logevent_id);
c->logevent_id = 0; c->logevent_id = 0;
} }
} else { } else {
@ -5549,7 +5549,7 @@ void ContactsManager::on_load_chat_from_database(ChatId chat_id, string value) {
if (value != new_value) { if (value != new_value) {
save_chat_to_database_impl(c, chat_id, std::move(new_value)); save_chat_to_database_impl(c, chat_id, std::move(new_value));
} else if (c->logevent_id != 0) { } else if (c->logevent_id != 0) {
BinlogHelper::erase(G()->td_db()->get_binlog(), c->logevent_id); binlog_erase(G()->td_db()->get_binlog(), c->logevent_id);
c->logevent_id = 0; c->logevent_id = 0;
} }
} }
@ -5625,9 +5625,9 @@ void ContactsManager::save_channel(Channel *c, ChannelId channel_id, bool from_b
auto logevent = ChannelLogEvent(channel_id, *c); auto logevent = ChannelLogEvent(channel_id, *c);
auto storer = LogEventStorerImpl<ChannelLogEvent>(logevent); auto storer = LogEventStorerImpl<ChannelLogEvent>(logevent);
if (c->logevent_id == 0) { if (c->logevent_id == 0) {
c->logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Channels, storer); c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Channels, storer);
} else { } else {
BinlogHelper::rewrite(G()->td_db()->get_binlog(), c->logevent_id, LogEvent::HandlerType::Channels, storer); binlog_rewrite(G()->td_db()->get_binlog(), c->logevent_id, LogEvent::HandlerType::Channels, storer);
} }
} }
@ -5638,7 +5638,7 @@ void ContactsManager::save_channel(Channel *c, ChannelId channel_id, bool from_b
void ContactsManager::on_binlog_channel_event(BinlogEvent &&event) { void ContactsManager::on_binlog_channel_event(BinlogEvent &&event) {
if (!G()->parameters().use_chat_info_db) { if (!G()->parameters().use_chat_info_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
return; return;
} }
@ -5708,7 +5708,7 @@ void ContactsManager::on_save_channel_to_database(ChannelId channel_id, bool suc
} }
if (c->is_saved) { if (c->is_saved) {
if (c->logevent_id != 0) { if (c->logevent_id != 0) {
BinlogHelper::erase(G()->td_db()->get_binlog(), c->logevent_id); binlog_erase(G()->td_db()->get_binlog(), c->logevent_id);
c->logevent_id = 0; c->logevent_id = 0;
} }
} else { } else {
@ -5773,7 +5773,7 @@ void ContactsManager::on_load_channel_from_database(ChannelId channel_id, string
if (value != new_value) { if (value != new_value) {
save_channel_to_database_impl(c, channel_id, std::move(new_value)); save_channel_to_database_impl(c, channel_id, std::move(new_value));
} else if (c->logevent_id != 0) { } else if (c->logevent_id != 0) {
BinlogHelper::erase(G()->td_db()->get_binlog(), c->logevent_id); binlog_erase(G()->td_db()->get_binlog(), c->logevent_id);
c->logevent_id = 0; c->logevent_id = 0;
} }
} }
@ -5842,9 +5842,9 @@ void ContactsManager::save_secret_chat(SecretChat *c, SecretChatId secret_chat_i
auto logevent = SecretChatLogEvent(secret_chat_id, *c); auto logevent = SecretChatLogEvent(secret_chat_id, *c);
auto storer = LogEventStorerImpl<SecretChatLogEvent>(logevent); auto storer = LogEventStorerImpl<SecretChatLogEvent>(logevent);
if (c->logevent_id == 0) { if (c->logevent_id == 0) {
c->logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SecretChatInfos, storer); c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SecretChatInfos, storer);
} else { } else {
BinlogHelper::rewrite(G()->td_db()->get_binlog(), c->logevent_id, LogEvent::HandlerType::SecretChatInfos, binlog_rewrite(G()->td_db()->get_binlog(), c->logevent_id, LogEvent::HandlerType::SecretChatInfos,
storer); storer);
} }
} }
@ -5856,7 +5856,7 @@ void ContactsManager::save_secret_chat(SecretChat *c, SecretChatId secret_chat_i
void ContactsManager::on_binlog_secret_chat_event(BinlogEvent &&event) { void ContactsManager::on_binlog_secret_chat_event(BinlogEvent &&event) {
if (!G()->parameters().use_chat_info_db) { if (!G()->parameters().use_chat_info_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
return; return;
} }
@ -5927,7 +5927,7 @@ void ContactsManager::on_save_secret_chat_to_database(SecretChatId secret_chat_i
} }
if (c->is_saved) { if (c->is_saved) {
if (c->logevent_id != 0) { if (c->logevent_id != 0) {
BinlogHelper::erase(G()->td_db()->get_binlog(), c->logevent_id); binlog_erase(G()->td_db()->get_binlog(), c->logevent_id);
c->logevent_id = 0; c->logevent_id = 0;
} }
} else { } else {
@ -5993,7 +5993,7 @@ void ContactsManager::on_load_secret_chat_from_database(SecretChatId secret_chat
if (value != new_value) { if (value != new_value) {
save_secret_chat_to_database_impl(c, secret_chat_id, std::move(new_value)); save_secret_chat_to_database_impl(c, secret_chat_id, std::move(new_value));
} else if (c->logevent_id != 0) { } else if (c->logevent_id != 0) {
BinlogHelper::erase(G()->td_db()->get_binlog(), c->logevent_id); binlog_erase(G()->td_db()->get_binlog(), c->logevent_id);
c->logevent_id = 0; c->logevent_id = 0;
} }
} }

View File

@ -6696,7 +6696,7 @@ void MessagesManager::change_dialog_report_spam_state_on_server(DialogId dialog_
logevent.is_spam_dialog_ = is_spam_dialog; logevent.is_spam_dialog_ = is_spam_dialog;
auto storer = LogEventStorerImpl<ChangeDialogReportSpamStateOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<ChangeDialogReportSpamStateOnServerLogEvent>(logevent);
logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), logevent_id = binlog_add(G()->td_db()->get_binlog(),
LogEvent::HandlerType::ChangeDialogReportSpamStateOnServer, storer); LogEvent::HandlerType::ChangeDialogReportSpamStateOnServer, storer);
} }
@ -8284,7 +8284,7 @@ void MessagesManager::delete_messages_from_server(DialogId dialog_id, vector<Mes
auto storer = LogEventStorerImpl<DeleteMessagesFromServerLogEvent>(logevent); auto storer = LogEventStorerImpl<DeleteMessagesFromServerLogEvent>(logevent);
logevent_id = logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessagesFromServer, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessagesFromServer, storer);
} }
auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise)); auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise));
@ -8422,7 +8422,7 @@ void MessagesManager::delete_dialog_history_from_server(DialogId dialog_id, Mess
auto storer = LogEventStorerImpl<DeleteDialogHistoryFromServerLogEvent>(logevent); auto storer = LogEventStorerImpl<DeleteDialogHistoryFromServerLogEvent>(logevent);
logevent_id = logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteDialogHistoryFromServer, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteDialogHistoryFromServer, storer);
} }
auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise)); auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise));
@ -8620,7 +8620,7 @@ void MessagesManager::delete_all_channel_messages_from_user_on_server(ChannelId
logevent.user_id_ = user_id; logevent.user_id_ = user_id;
auto storer = LogEventStorerImpl<DeleteAllChannelMessagesFromUserOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<DeleteAllChannelMessagesFromUserOnServerLogEvent>(logevent);
logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), logevent_id = binlog_add(G()->td_db()->get_binlog(),
LogEvent::HandlerType::DeleteAllChannelMessagesFromUserOnServer, storer); LogEvent::HandlerType::DeleteAllChannelMessagesFromUserOnServer, storer);
} }
@ -8823,7 +8823,7 @@ void MessagesManager::read_all_dialog_mentions_on_server(DialogId dialog_id, uin
auto storer = LogEventStorerImpl<ReadAllDialogMentionsOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<ReadAllDialogMentionsOnServerLogEvent>(logevent);
logevent_id = logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadAllDialogMentionsOnServer, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadAllDialogMentionsOnServer, storer);
} }
LOG(INFO) << "Read all mentions on server in " << dialog_id; LOG(INFO) << "Read all mentions on server in " << dialog_id;
@ -12577,11 +12577,11 @@ Status MessagesManager::set_dialog_draft_message(DialogId dialog_id,
logevent.dialog_id_ = dialog_id; logevent.dialog_id_ = dialog_id;
auto storer = LogEventStorerImpl<SaveDialogDraftMessageOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<SaveDialogDraftMessageOnServerLogEvent>(logevent);
if (d->save_draft_message_logevent_id == 0) { if (d->save_draft_message_logevent_id == 0) {
d->save_draft_message_logevent_id = BinlogHelper::add( d->save_draft_message_logevent_id = binlog_add(
G()->td_db()->get_binlog(), LogEvent::HandlerType::SaveDialogDraftMessageOnServer, storer); G()->td_db()->get_binlog(), LogEvent::HandlerType::SaveDialogDraftMessageOnServer, storer);
LOG(INFO) << "Add draft logevent " << d->save_draft_message_logevent_id; LOG(INFO) << "Add draft logevent " << d->save_draft_message_logevent_id;
} else { } else {
auto new_logevent_id = BinlogHelper::rewrite(G()->td_db()->get_binlog(), d->save_draft_message_logevent_id, auto new_logevent_id = binlog_rewrite(G()->td_db()->get_binlog(), d->save_draft_message_logevent_id,
LogEvent::HandlerType::SaveDialogDraftMessageOnServer, storer); LogEvent::HandlerType::SaveDialogDraftMessageOnServer, storer);
LOG(INFO) << "Rewrite draft logevent " << d->save_draft_message_logevent_id << " with " << new_logevent_id; LOG(INFO) << "Rewrite draft logevent " << d->save_draft_message_logevent_id << " with " << new_logevent_id;
} }
@ -12620,7 +12620,7 @@ void MessagesManager::on_saved_dialog_draft_message(DialogId dialog_id, uint64 g
if (d->save_draft_message_logevent_id_generation == generation) { if (d->save_draft_message_logevent_id_generation == generation) {
CHECK(d->save_draft_message_logevent_id != 0); CHECK(d->save_draft_message_logevent_id != 0);
LOG(INFO) << "Delete draft logevent " << d->save_draft_message_logevent_id; LOG(INFO) << "Delete draft logevent " << d->save_draft_message_logevent_id;
BinlogHelper::erase(G()->td_db()->get_binlog(), d->save_draft_message_logevent_id); binlog_erase(G()->td_db()->get_binlog(), d->save_draft_message_logevent_id);
d->save_draft_message_logevent_id = 0; d->save_draft_message_logevent_id = 0;
} }
} }
@ -12713,7 +12713,7 @@ void MessagesManager::toggle_dialog_is_pinned_on_server(DialogId dialog_id, bool
auto storer = LogEventStorerImpl<ToggleDialogIsPinnedOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<ToggleDialogIsPinnedOnServerLogEvent>(logevent);
logevent_id = logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogIsPinnedOnServer, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogIsPinnedOnServer, storer);
} }
td_->create_handler<ToggleDialogPinQuery>(get_erase_logevent_promise(logevent_id))->send(dialog_id, is_pinned); td_->create_handler<ToggleDialogPinQuery>(get_erase_logevent_promise(logevent_id))->send(dialog_id, is_pinned);
@ -12811,7 +12811,7 @@ void MessagesManager::reorder_pinned_dialogs_on_server(const vector<DialogId> &d
auto storer = LogEventStorerImpl<ReorderPinnedDialogsOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<ReorderPinnedDialogsOnServerLogEvent>(logevent);
logevent_id = logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReorderPinnedDialogsOnServer, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReorderPinnedDialogsOnServer, storer);
} }
td_->create_handler<ReorderPinnedDialogsQuery>(get_erase_logevent_promise(logevent_id))->send(dialog_ids); td_->create_handler<ReorderPinnedDialogsQuery>(get_erase_logevent_promise(logevent_id))->send(dialog_ids);
@ -12868,7 +12868,7 @@ void MessagesManager::toggle_dialog_is_marked_as_unread_on_server(DialogId dialo
logevent.is_marked_as_unread_ = is_marked_as_unread; logevent.is_marked_as_unread_ = is_marked_as_unread;
auto storer = LogEventStorerImpl<ToggleDialogIsMarkedAsUnreadOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<ToggleDialogIsMarkedAsUnreadOnServerLogEvent>(logevent);
logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), logevent_id = binlog_add(G()->td_db()->get_binlog(),
LogEvent::HandlerType::ToggleDialogIsMarkedAsUnreadOnServer, storer); LogEvent::HandlerType::ToggleDialogIsMarkedAsUnreadOnServer, storer);
} }
@ -12919,12 +12919,12 @@ void MessagesManager::update_dialog_notification_settings_on_server(DialogId dia
logevent.dialog_id_ = dialog_id; logevent.dialog_id_ = dialog_id;
auto storer = LogEventStorerImpl<UpdateDialogNotificationSettingsOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<UpdateDialogNotificationSettingsOnServerLogEvent>(logevent);
if (d->save_notification_settings_logevent_id == 0) { if (d->save_notification_settings_logevent_id == 0) {
d->save_notification_settings_logevent_id = BinlogHelper::add( d->save_notification_settings_logevent_id = binlog_add(
G()->td_db()->get_binlog(), LogEvent::HandlerType::UpdateDialogNotificationSettingsOnServer, storer); G()->td_db()->get_binlog(), LogEvent::HandlerType::UpdateDialogNotificationSettingsOnServer, storer);
LOG(INFO) << "Add notification settings logevent " << d->save_notification_settings_logevent_id; LOG(INFO) << "Add notification settings logevent " << d->save_notification_settings_logevent_id;
} else { } else {
auto new_logevent_id = auto new_logevent_id =
BinlogHelper::rewrite(G()->td_db()->get_binlog(), d->save_notification_settings_logevent_id, binlog_rewrite(G()->td_db()->get_binlog(), d->save_notification_settings_logevent_id,
LogEvent::HandlerType::UpdateDialogNotificationSettingsOnServer, storer); LogEvent::HandlerType::UpdateDialogNotificationSettingsOnServer, storer);
LOG(INFO) << "Rewrite notification settings logevent " << d->save_notification_settings_logevent_id << " with " LOG(INFO) << "Rewrite notification settings logevent " << d->save_notification_settings_logevent_id << " with "
<< new_logevent_id; << new_logevent_id;
@ -12955,7 +12955,7 @@ void MessagesManager::on_updated_dialog_notification_settings(DialogId dialog_id
if (d->save_notification_settings_logevent_id_generation == generation) { if (d->save_notification_settings_logevent_id_generation == generation) {
CHECK(d->save_notification_settings_logevent_id != 0); CHECK(d->save_notification_settings_logevent_id != 0);
LOG(INFO) << "Delete notification settings logevent " << d->save_notification_settings_logevent_id; LOG(INFO) << "Delete notification settings logevent " << d->save_notification_settings_logevent_id;
BinlogHelper::erase(G()->td_db()->get_binlog(), d->save_notification_settings_logevent_id); binlog_erase(G()->td_db()->get_binlog(), d->save_notification_settings_logevent_id);
d->save_notification_settings_logevent_id = 0; d->save_notification_settings_logevent_id = 0;
} }
} }
@ -13280,7 +13280,7 @@ void MessagesManager::read_message_contents_on_server(DialogId dialog_id, vector
auto storer = LogEventStorerImpl<ReadMessageContentsOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<ReadMessageContentsOnServerLogEvent>(logevent);
logevent_id = logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadMessageContentsOnServer, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadMessageContentsOnServer, storer);
} }
auto promise = get_erase_logevent_promise(logevent_id); auto promise = get_erase_logevent_promise(logevent_id);
@ -13693,7 +13693,7 @@ void MessagesManager::update_scope_notification_settings_on_server(NotificationS
logevent.scope_ = scope; logevent.scope_ = scope;
auto storer = LogEventStorerImpl<UpdateScopeNotificationSettingsOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<UpdateScopeNotificationSettingsOnServerLogEvent>(logevent);
logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), logevent_id = binlog_add(G()->td_db()->get_binlog(),
LogEvent::HandlerType::UpdateScopeNotificationSettingsOnServer, storer); LogEvent::HandlerType::UpdateScopeNotificationSettingsOnServer, storer);
} }
@ -13735,7 +13735,7 @@ void MessagesManager::reset_all_notification_settings_on_server(uint64 logevent_
if (logevent_id == 0) { if (logevent_id == 0) {
ResetAllNotificationSettingsOnServerLogEvent logevent; ResetAllNotificationSettingsOnServerLogEvent logevent;
auto storer = LogEventStorerImpl<ResetAllNotificationSettingsOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<ResetAllNotificationSettingsOnServerLogEvent>(logevent);
logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), logevent_id = binlog_add(G()->td_db()->get_binlog(),
LogEvent::HandlerType::ResetAllNotificationSettingsOnServer, storer); LogEvent::HandlerType::ResetAllNotificationSettingsOnServer, storer);
} }
@ -13988,10 +13988,10 @@ void MessagesManager::read_history_on_server(Dialog *d, MessageId max_message_id
auto storer = LogEventStorerImpl<ReadHistoryInSecretChatLogEvent>(logevent); auto storer = LogEventStorerImpl<ReadHistoryInSecretChatLogEvent>(logevent);
if (d->read_history_logevent_id == 0) { if (d->read_history_logevent_id == 0) {
d->read_history_logevent_id = d->read_history_logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadHistoryInSecretChat, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadHistoryInSecretChat, storer);
LOG(INFO) << "Add read history logevent " << d->read_history_logevent_id; LOG(INFO) << "Add read history logevent " << d->read_history_logevent_id;
} else { } else {
auto new_logevent_id = BinlogHelper::rewrite(G()->td_db()->get_binlog(), d->read_history_logevent_id, auto new_logevent_id = binlog_rewrite(G()->td_db()->get_binlog(), d->read_history_logevent_id,
LogEvent::HandlerType::ReadHistoryInSecretChat, storer); LogEvent::HandlerType::ReadHistoryInSecretChat, storer);
LOG(INFO) << "Rewrite read history logevent " << d->read_history_logevent_id << " with " << new_logevent_id; LOG(INFO) << "Rewrite read history logevent " << d->read_history_logevent_id << " with " << new_logevent_id;
} }
@ -14004,10 +14004,10 @@ void MessagesManager::read_history_on_server(Dialog *d, MessageId max_message_id
auto storer = LogEventStorerImpl<ReadHistoryOnServerLogEvent>(logevent); auto storer = LogEventStorerImpl<ReadHistoryOnServerLogEvent>(logevent);
if (d->read_history_logevent_id == 0) { if (d->read_history_logevent_id == 0) {
d->read_history_logevent_id = d->read_history_logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadHistoryOnServer, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadHistoryOnServer, storer);
LOG(INFO) << "Add read history logevent " << d->read_history_logevent_id; LOG(INFO) << "Add read history logevent " << d->read_history_logevent_id;
} else { } else {
auto new_logevent_id = BinlogHelper::rewrite(G()->td_db()->get_binlog(), d->read_history_logevent_id, auto new_logevent_id = binlog_rewrite(G()->td_db()->get_binlog(), d->read_history_logevent_id,
LogEvent::HandlerType::ReadHistoryOnServer, storer); LogEvent::HandlerType::ReadHistoryOnServer, storer);
LOG(INFO) << "Rewrite read history logevent " << d->read_history_logevent_id << " with " << new_logevent_id; LOG(INFO) << "Rewrite read history logevent " << d->read_history_logevent_id << " with " << new_logevent_id;
} }
@ -14080,7 +14080,7 @@ void MessagesManager::on_read_history_finished(DialogId dialog_id, uint64 genera
if (d->read_history_logevent_id_generation == generation) { if (d->read_history_logevent_id_generation == generation) {
CHECK(d->read_history_logevent_id != 0); CHECK(d->read_history_logevent_id != 0);
LOG(INFO) << "Delete read history logevent " << d->read_history_logevent_id; LOG(INFO) << "Delete read history logevent " << d->read_history_logevent_id;
BinlogHelper::erase(G()->td_db()->get_binlog(), d->read_history_logevent_id); binlog_erase(G()->td_db()->get_binlog(), d->read_history_logevent_id);
d->read_history_logevent_id = 0; d->read_history_logevent_id = 0;
} }
} }
@ -16229,7 +16229,7 @@ void MessagesManager::cancel_send_message_query(DialogId dialog_id, unique_ptr<M
if (m->send_message_logevent_id != 0) { if (m->send_message_logevent_id != 0) {
LOG(INFO) << "Delete send message log event for " << m->message_id; LOG(INFO) << "Delete send message log event for " << m->message_id;
BinlogHelper::erase(G()->td_db()->get_binlog(), m->send_message_logevent_id); binlog_erase(G()->td_db()->get_binlog(), m->send_message_logevent_id);
m->send_message_logevent_id = 0; m->send_message_logevent_id = 0;
} }
@ -17062,7 +17062,7 @@ void MessagesManager::save_send_message_logevent(DialogId dialog_id, Message *m)
auto storer = LogEventStorerImpl<SendMessageLogEvent>(logevent); auto storer = LogEventStorerImpl<SendMessageLogEvent>(logevent);
CHECK(m->send_message_logevent_id == 0); CHECK(m->send_message_logevent_id == 0);
m->send_message_logevent_id = m->send_message_logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendMessage, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendMessage, storer);
} }
void MessagesManager::do_send_message(DialogId dialog_id, Message *m, vector<int> bad_parts) { void MessagesManager::do_send_message(DialogId dialog_id, Message *m, vector<int> bad_parts) {
@ -17653,7 +17653,7 @@ void MessagesManager::save_send_bot_start_message_logevent(UserId bot_user_id, D
auto storer = LogEventStorerImpl<SendBotStartMessageLogEvent>(logevent); auto storer = LogEventStorerImpl<SendBotStartMessageLogEvent>(logevent);
CHECK(m->send_message_logevent_id == 0); CHECK(m->send_message_logevent_id == 0);
m->send_message_logevent_id = m->send_message_logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendBotStartMessage, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendBotStartMessage, storer);
} }
void MessagesManager::do_send_bot_start_message(UserId bot_user_id, DialogId dialog_id, const string &parameter, void MessagesManager::do_send_bot_start_message(UserId bot_user_id, DialogId dialog_id, const string &parameter,
@ -17793,7 +17793,7 @@ void MessagesManager::save_send_inline_query_result_message_logevent(DialogId di
auto storer = LogEventStorerImpl<SendInlineQueryResultMessageLogEvent>(logevent); auto storer = LogEventStorerImpl<SendInlineQueryResultMessageLogEvent>(logevent);
CHECK(m->send_message_logevent_id == 0); CHECK(m->send_message_logevent_id == 0);
m->send_message_logevent_id = m->send_message_logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendInlineQueryResultMessage, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendInlineQueryResultMessage, storer);
} }
void MessagesManager::do_send_inline_query_result_message(DialogId dialog_id, Message *m, int64 query_id, void MessagesManager::do_send_inline_query_result_message(DialogId dialog_id, Message *m, int64 query_id,
@ -18915,7 +18915,7 @@ void MessagesManager::do_forward_messages(DialogId to_dialog_id, DialogId from_d
if (logevent_id == 0 && G()->parameters().use_message_db) { if (logevent_id == 0 && G()->parameters().use_message_db) {
auto logevent = ForwardMessagesLogEvent{to_dialog_id, from_dialog_id, message_ids, messages, Auto()}; auto logevent = ForwardMessagesLogEvent{to_dialog_id, from_dialog_id, message_ids, messages, Auto()};
auto storer = LogEventStorerImpl<ForwardMessagesLogEvent>(logevent); auto storer = LogEventStorerImpl<ForwardMessagesLogEvent>(logevent);
logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ForwardMessages, storer); logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ForwardMessages, storer);
} }
int32 flags = 0; int32 flags = 0;
@ -19230,7 +19230,7 @@ uint64 MessagesManager::save_send_screenshot_taken_notification_message_logevent
logevent.dialog_id = dialog_id; logevent.dialog_id = dialog_id;
logevent.m_in = m; logevent.m_in = m;
auto storer = LogEventStorerImpl<SendScreenshotTakenNotificationMessageLogEvent>(logevent); auto storer = LogEventStorerImpl<SendScreenshotTakenNotificationMessageLogEvent>(logevent);
return BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendScreenshotTakenNotificationMessage, return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendScreenshotTakenNotificationMessage,
storer); storer);
} }
@ -19980,7 +19980,7 @@ void MessagesManager::on_send_message_file_part_missing(int64 random_id, int bad
auto logevent = SendMessageLogEvent(dialog_id, m); auto logevent = SendMessageLogEvent(dialog_id, m);
auto storer = LogEventStorerImpl<SendMessageLogEvent>(logevent); auto storer = LogEventStorerImpl<SendMessageLogEvent>(logevent);
CHECK(m->send_message_logevent_id != 0); CHECK(m->send_message_logevent_id != 0);
BinlogHelper::rewrite(G()->td_db()->get_binlog(), m->send_message_logevent_id, LogEvent::HandlerType::SendMessage, binlog_rewrite(G()->td_db()->get_binlog(), m->send_message_logevent_id, LogEvent::HandlerType::SendMessage,
storer); storer);
} }
@ -20553,13 +20553,13 @@ class MessagesManager::GetDialogFromServerLogEvent {
void MessagesManager::send_get_dialog_query(DialogId dialog_id, Promise<Unit> &&promise, uint64 logevent_id) { void MessagesManager::send_get_dialog_query(DialogId dialog_id, Promise<Unit> &&promise, uint64 logevent_id) {
if (td_->auth_manager_->is_bot() || dialog_id.get_type() == DialogType::SecretChat) { if (td_->auth_manager_->is_bot() || dialog_id.get_type() == DialogType::SecretChat) {
if (logevent_id != 0) { if (logevent_id != 0) {
BinlogHelper::erase(G()->td_db()->get_binlog(), logevent_id); binlog_erase(G()->td_db()->get_binlog(), logevent_id);
} }
return promise.set_error(Status::Error(500, "Wrong getDialog query")); return promise.set_error(Status::Error(500, "Wrong getDialog query"));
} }
if (!have_input_peer(dialog_id, AccessRights::Read)) { if (!have_input_peer(dialog_id, AccessRights::Read)) {
if (logevent_id != 0) { if (logevent_id != 0) {
BinlogHelper::erase(G()->td_db()->get_binlog(), logevent_id); binlog_erase(G()->td_db()->get_binlog(), logevent_id);
} }
return promise.set_error(Status::Error(400, "Can't access the chat")); return promise.set_error(Status::Error(400, "Can't access the chat"));
} }
@ -20569,7 +20569,7 @@ void MessagesManager::send_get_dialog_query(DialogId dialog_id, Promise<Unit> &&
if (promises.size() != 1) { if (promises.size() != 1) {
if (logevent_id != 0) { if (logevent_id != 0) {
LOG(ERROR) << "Duplicate getDialog query for " << dialog_id; LOG(ERROR) << "Duplicate getDialog query for " << dialog_id;
BinlogHelper::erase(G()->td_db()->get_binlog(), logevent_id); binlog_erase(G()->td_db()->get_binlog(), logevent_id);
} }
// query has already been sent, just wait for the result // query has already been sent, just wait for the result
return; return;
@ -20580,7 +20580,7 @@ void MessagesManager::send_get_dialog_query(DialogId dialog_id, Promise<Unit> &&
logevent.dialog_id_ = dialog_id; logevent.dialog_id_ = dialog_id;
auto storer = LogEventStorerImpl<GetDialogFromServerLogEvent>(logevent); auto storer = LogEventStorerImpl<GetDialogFromServerLogEvent>(logevent);
logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::GetDialogFromServer, storer); logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::GetDialogFromServer, storer);
} }
if (logevent_id != 0) { if (logevent_id != 0) {
get_dialog_query_logevent_id_[dialog_id] = logevent_id; get_dialog_query_logevent_id_[dialog_id] = logevent_id;
@ -20599,7 +20599,7 @@ void MessagesManager::on_get_dialog_query_finished(DialogId dialog_id, Status &&
auto logevent_it = get_dialog_query_logevent_id_.find(dialog_id); auto logevent_it = get_dialog_query_logevent_id_.find(dialog_id);
if (logevent_it != get_dialog_query_logevent_id_.end()) { if (logevent_it != get_dialog_query_logevent_id_.end()) {
BinlogHelper::erase(G()->td_db()->get_binlog(), logevent_it->second); binlog_erase(G()->td_db()->get_binlog(), logevent_it->second);
get_dialog_query_logevent_id_.erase(logevent_it); get_dialog_query_logevent_id_.erase(logevent_it);
} }
@ -23621,7 +23621,7 @@ void MessagesManager::do_delete_message_logevent(const DeleteMessageLogEvent &lo
auto logevent_id = logevent.id_; auto logevent_id = logevent.id_;
if (!logevent_id) { if (!logevent_id) {
auto storer = LogEventStorerImpl<DeleteMessageLogEvent>(logevent); auto storer = LogEventStorerImpl<DeleteMessageLogEvent>(logevent);
logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessage, storer); logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessage, storer);
} }
MultiPromiseActorSafe mpas; MultiPromiseActorSafe mpas;
@ -23629,7 +23629,7 @@ void MessagesManager::do_delete_message_logevent(const DeleteMessageLogEvent &lo
if (result.is_error()) { if (result.is_error()) {
return; return;
} }
BinlogHelper::erase(G()->td_db()->get_binlog(), logevent_id); binlog_erase(G()->td_db()->get_binlog(), logevent_id);
})); }));
auto lock = mpas.get_promise(); auto lock = mpas.get_promise();
@ -25290,7 +25290,7 @@ void MessagesManager::get_channel_difference(DialogId dialog_id, int32 pts, bool
auto logevent = GetChannelDifferenceLogEvent(channel_id, access_hash); auto logevent = GetChannelDifferenceLogEvent(channel_id, access_hash);
auto storer = LogEventStorerImpl<GetChannelDifferenceLogEvent>(logevent); auto storer = LogEventStorerImpl<GetChannelDifferenceLogEvent>(logevent);
auto logevent_id = auto logevent_id =
BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::GetChannelDifference, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::GetChannelDifference, storer);
get_channel_difference_to_logevent_id_.emplace(dialog_id, logevent_id); get_channel_difference_to_logevent_id_.emplace(dialog_id, logevent_id);
} }
@ -25607,7 +25607,7 @@ void MessagesManager::after_get_channel_difference(DialogId dialog_id, bool succ
auto logevent_it = get_channel_difference_to_logevent_id_.find(dialog_id); auto logevent_it = get_channel_difference_to_logevent_id_.find(dialog_id);
if (logevent_it != get_channel_difference_to_logevent_id_.end()) { if (logevent_it != get_channel_difference_to_logevent_id_.end()) {
BinlogHelper::erase(G()->td_db()->get_binlog(), logevent_it->second); binlog_erase(G()->td_db()->get_binlog(), logevent_it->second);
get_channel_difference_to_logevent_id_.erase(logevent_it); get_channel_difference_to_logevent_id_.erase(logevent_it);
} }
@ -25718,7 +25718,7 @@ MessagesManager::Message *MessagesManager::continue_send_message(DialogId dialog
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) { if (d == nullptr) {
LOG(ERROR) << "Can't find " << dialog_id << " to resend a message"; LOG(ERROR) << "Can't find " << dialog_id << " to resend a message";
BinlogHelper::erase(G()->td_db()->get_binlog(), logevent_id); binlog_erase(G()->td_db()->get_binlog(), logevent_id);
return nullptr; return nullptr;
} }
@ -25731,7 +25731,7 @@ MessagesManager::Message *MessagesManager::continue_send_message(DialogId dialog
LOG(INFO) << "Continue to send " << m->message_id << " to " << dialog_id << " from binlog"; LOG(INFO) << "Continue to send " << m->message_id << " to " << dialog_id << " from binlog";
if (!have_input_peer(dialog_id, AccessRights::Read)) { if (!have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), logevent_id); binlog_erase(G()->td_db()->get_binlog(), logevent_id);
return nullptr; return nullptr;
} }
@ -25765,7 +25765,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
switch (event.type_) { switch (event.type_) {
case LogEvent::HandlerType::SendMessage: { case LogEvent::HandlerType::SendMessage: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -25778,7 +25778,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
if (m->content->get_id() == MessageUnsupported::ID) { if (m->content->get_id() == MessageUnsupported::ID) {
LOG(ERROR) << "Message content is invalid: " << format::as_hex_dump<4>(Slice(event.data_)); LOG(ERROR) << "Message content is invalid: " << format::as_hex_dump<4>(Slice(event.data_));
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
continue; continue;
} }
@ -25797,7 +25797,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::SendBotStartMessage: { case LogEvent::HandlerType::SendBotStartMessage: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -25818,7 +25818,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto bot_user_id = log_event.bot_user_id; auto bot_user_id = log_event.bot_user_id;
if (!td_->contacts_manager_->have_user_force(bot_user_id)) { if (!td_->contacts_manager_->have_user_force(bot_user_id)) {
LOG(ERROR) << "Can't find bot " << bot_user_id; LOG(ERROR) << "Can't find bot " << bot_user_id;
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
continue; continue;
} }
@ -25830,7 +25830,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::SendInlineQueryResultMessage: { case LogEvent::HandlerType::SendInlineQueryResultMessage: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -25843,7 +25843,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
if (m->content->get_id() == MessageUnsupported::ID) { if (m->content->get_id() == MessageUnsupported::ID) {
LOG(ERROR) << "Message content is invalid: " << format::as_hex_dump<4>(Slice(event.data_)); LOG(ERROR) << "Message content is invalid: " << format::as_hex_dump<4>(Slice(event.data_));
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
continue; continue;
} }
@ -25862,7 +25862,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::SendScreenshotTakenNotificationMessage: { case LogEvent::HandlerType::SendScreenshotTakenNotificationMessage: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -25888,7 +25888,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::ForwardMessages: { case LogEvent::HandlerType::ForwardMessages: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -25910,13 +25910,13 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
Dialog *to_dialog = get_dialog_force(to_dialog_id); Dialog *to_dialog = get_dialog_force(to_dialog_id);
if (to_dialog == nullptr) { if (to_dialog == nullptr) {
LOG(ERROR) << "Can't find " << to_dialog_id << " to forward messages to"; LOG(ERROR) << "Can't find " << to_dialog_id << " to forward messages to";
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
continue; continue;
} }
Dialog *from_dialog = get_dialog_force(from_dialog_id); Dialog *from_dialog = get_dialog_force(from_dialog_id);
if (from_dialog == nullptr) { if (from_dialog == nullptr) {
LOG(ERROR) << "Can't find " << from_dialog_id << " to forward messages from"; LOG(ERROR) << "Can't find " << from_dialog_id << " to forward messages from";
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
continue; continue;
} }
for (auto &m : messages) { for (auto &m : messages) {
@ -25931,7 +25931,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
LOG(INFO) << "Continue to forward " << messages.size() << " messages to " << to_dialog_id << " from binlog"; LOG(INFO) << "Continue to forward " << messages.size() << " messages to " << to_dialog_id << " from binlog";
if (!have_input_peer(from_dialog_id, AccessRights::Read) || can_send_message(to_dialog_id).is_error()) { if (!have_input_peer(from_dialog_id, AccessRights::Read) || can_send_message(to_dialog_id).is_error()) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -25953,7 +25953,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::DeleteMessage: { case LogEvent::HandlerType::DeleteMessage: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -25971,7 +25971,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::DeleteMessagesFromServer: { case LogEvent::HandlerType::DeleteMessagesFromServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -25981,7 +25981,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) { if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -25992,7 +25992,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::DeleteDialogHistoryFromServer: { case LogEvent::HandlerType::DeleteDialogHistoryFromServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26002,7 +26002,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) { if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26012,7 +26012,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::DeleteAllChannelMessagesFromUserOnServer: { case LogEvent::HandlerType::DeleteAllChannelMessagesFromUserOnServer: {
if (!G()->parameters().use_chat_info_db) { if (!G()->parameters().use_chat_info_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26022,14 +26022,14 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto channel_id = log_event.channel_id_; auto channel_id = log_event.channel_id_;
if (!td_->contacts_manager_->have_channel_force(channel_id)) { if (!td_->contacts_manager_->have_channel_force(channel_id)) {
LOG(ERROR) << "Can't find " << channel_id; LOG(ERROR) << "Can't find " << channel_id;
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
auto user_id = log_event.user_id_; auto user_id = log_event.user_id_;
if (!td_->contacts_manager_->have_user_force(user_id)) { if (!td_->contacts_manager_->have_user_force(user_id)) {
LOG(ERROR) << "Can't find user " << user_id; LOG(ERROR) << "Can't find user " << user_id;
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26038,7 +26038,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::ReadHistoryOnServer: { case LogEvent::HandlerType::ReadHistoryOnServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26048,12 +26048,12 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) { if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
if (d->read_history_logevent_id != 0) { if (d->read_history_logevent_id != 0) {
// we need only latest read history event // we need only latest read history event
BinlogHelper::erase(G()->td_db()->get_binlog(), d->read_history_logevent_id); binlog_erase(G()->td_db()->get_binlog(), d->read_history_logevent_id);
} }
d->read_history_logevent_id = event.id_; d->read_history_logevent_id = event.id_;
d->read_history_logevent_id_generation++; d->read_history_logevent_id_generation++;
@ -26069,18 +26069,18 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
CHECK(dialog_id.get_type() == DialogType::SecretChat); CHECK(dialog_id.get_type() == DialogType::SecretChat);
if (!td_->contacts_manager_->have_secret_chat_force(dialog_id.get_secret_chat_id())) { if (!td_->contacts_manager_->have_secret_chat_force(dialog_id.get_secret_chat_id())) {
LOG(ERROR) << "Have no info about " << dialog_id; LOG(ERROR) << "Have no info about " << dialog_id;
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
force_create_dialog(dialog_id, "ReadHistoryInSecretChatLogEvent"); force_create_dialog(dialog_id, "ReadHistoryInSecretChatLogEvent");
Dialog *d = get_dialog(dialog_id); Dialog *d = get_dialog(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) { if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
if (d->read_history_logevent_id != 0) { if (d->read_history_logevent_id != 0) {
// we need only latest read history event // we need only latest read history event
BinlogHelper::erase(G()->td_db()->get_binlog(), d->read_history_logevent_id); binlog_erase(G()->td_db()->get_binlog(), d->read_history_logevent_id);
} }
d->read_history_logevent_id = event.id_; d->read_history_logevent_id = event.id_;
d->read_history_logevent_id_generation++; d->read_history_logevent_id_generation++;
@ -26091,7 +26091,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::ReadMessageContentsOnServer: { case LogEvent::HandlerType::ReadMessageContentsOnServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26101,7 +26101,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) { if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26110,7 +26110,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::ReadAllDialogMentionsOnServer: { case LogEvent::HandlerType::ReadAllDialogMentionsOnServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26120,7 +26120,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) { if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26129,7 +26129,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::ToggleDialogIsPinnedOnServer: { case LogEvent::HandlerType::ToggleDialogIsPinnedOnServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26139,7 +26139,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) { if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26148,7 +26148,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::ReorderPinnedDialogsOnServer: { case LogEvent::HandlerType::ReorderPinnedDialogsOnServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26163,7 +26163,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
} }
if (dialog_ids.empty()) { if (dialog_ids.empty()) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26172,7 +26172,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::ToggleDialogIsMarkedAsUnreadOnServer: { case LogEvent::HandlerType::ToggleDialogIsMarkedAsUnreadOnServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26182,7 +26182,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) { if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26191,7 +26191,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::SaveDialogDraftMessageOnServer: { case LogEvent::HandlerType::SaveDialogDraftMessageOnServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26201,7 +26201,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Write)) { if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Write)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
d->save_draft_message_logevent_id = event.id_; d->save_draft_message_logevent_id = event.id_;
@ -26212,7 +26212,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::UpdateDialogNotificationSettingsOnServer: { case LogEvent::HandlerType::UpdateDialogNotificationSettingsOnServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26222,7 +26222,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) { if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
d->save_notification_settings_logevent_id = event.id_; d->save_notification_settings_logevent_id = event.id_;
@ -26247,7 +26247,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::ChangeDialogReportSpamStateOnServer: { case LogEvent::HandlerType::ChangeDialogReportSpamStateOnServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26257,7 +26257,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.dialog_id_; auto dialog_id = log_event.dialog_id_;
Dialog *d = get_dialog_force(dialog_id); Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) { if (d == nullptr || !have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26266,7 +26266,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
} }
case LogEvent::HandlerType::GetDialogFromServer: { case LogEvent::HandlerType::GetDialogFromServer: {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }
@ -26281,7 +26281,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
get_dialog_force(dialog_id); // load it if exists get_dialog_force(dialog_id); // load it if exists
if (!have_input_peer(dialog_id, AccessRights::Read)) { if (!have_input_peer(dialog_id, AccessRights::Read)) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
break; break;
} }

View File

@ -83,7 +83,7 @@ void SecretChatActor::create_chat(int32 user_id, int64 user_access_hash, int32 r
event->user_access_hash = user_access_hash; event->user_access_hash = user_access_hash;
event->random_id = random_id; event->random_id = random_id;
event->set_logevent_id( event->set_logevent_id(
BinlogHelper::add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*event))); binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*event)));
do_create_chat_impl(std::move(event)); do_create_chat_impl(std::move(event));
promise.set_value(SecretChatId(random_id)); promise.set_value(SecretChatId(random_id));
loop(); loop();
@ -699,17 +699,17 @@ void SecretChatActor::cancel_chat(Promise<> promise) {
// TODO: It must be a transaction // TODO: It must be a transaction
for (auto id : to_delete) { for (auto id : to_delete) {
BinlogHelper::erase(context_->binlog(), id); binlog_erase(context_->binlog(), id);
} }
if (create_logevent_id_ != 0) { if (create_logevent_id_ != 0) {
BinlogHelper::erase(context_->binlog(), create_logevent_id_); binlog_erase(context_->binlog(), create_logevent_id_);
create_logevent_id_ = 0; create_logevent_id_ = 0;
} }
auto event = std::make_unique<logevent::CloseSecretChat>(); auto event = std::make_unique<logevent::CloseSecretChat>();
event->chat_id = auth_state_.id; event->chat_id = auth_state_.id;
event->set_logevent_id( event->set_logevent_id(
BinlogHelper::add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*event))); binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*event)));
auto on_sync = PromiseCreator::lambda( auto on_sync = PromiseCreator::lambda(
[actor_id = actor_id(this), event = std::move(event), promise = std::move(promise)](Result<Unit> result) mutable { [actor_id = actor_id(this), event = std::move(event), promise = std::move(promise)](Result<Unit> result) mutable {
@ -761,14 +761,14 @@ void SecretChatActor::do_create_chat_impl(std::unique_ptr<logevent::CreateSecret
} else if (auth_state_.state == State::SendRequest) { } else if (auth_state_.state == State::SendRequest) {
} else if (auth_state_.state == State::WaitRequestResponse) { } else if (auth_state_.state == State::WaitRequestResponse) {
} else { } else {
BinlogHelper::erase(context_->binlog(), create_logevent_id_); binlog_erase(context_->binlog(), create_logevent_id_);
create_logevent_id_ = 0; create_logevent_id_ = 0;
} }
} }
void SecretChatActor::on_discard_encryption_result(NetQueryPtr result) { void SecretChatActor::on_discard_encryption_result(NetQueryPtr result) {
CHECK(close_flag_); CHECK(close_flag_);
LOG(INFO) << "Got result for messages.discardEncryption"; LOG(INFO) << "Got result for messages.discardEncryption";
BinlogHelper::erase(context_->binlog(), close_logevent_id_); binlog_erase(context_->binlog(), close_logevent_id_);
// skip flush // skip flush
stop(); stop();
} }
@ -956,7 +956,7 @@ Status SecretChatActor::do_inbound_message_decrypted_unchecked(
message->qts_ack.set_value(Unit()); message->qts_ack.set_value(Unit());
if (message->logevent_id()) { if (message->logevent_id()) {
LOG(INFO) << "Erase binlog event: " << tag("logevent_id", message->logevent_id()); LOG(INFO) << "Erase binlog event: " << tag("logevent_id", message->logevent_id());
BinlogHelper::erase(context_->binlog(), message->logevent_id()); binlog_erase(context_->binlog(), message->logevent_id());
} }
auto warning_message = PSTRING() << status << tag("seq_no_state_.my_in_seq_no", seq_no_state_.my_in_seq_no) auto warning_message = PSTRING() << status << tag("seq_no_state_.my_in_seq_no", seq_no_state_.my_in_seq_no)
<< tag("seq_no_state_.my_out_seq_no", seq_no_state_.my_out_seq_no) << tag("seq_no_state_.my_out_seq_no", seq_no_state_.my_out_seq_no)
@ -1087,7 +1087,7 @@ void SecretChatActor::do_outbound_message_impl(std::unique_ptr<logevent::Outboun
auto logevent_id = state->message->logevent_id(); auto logevent_id = state->message->logevent_id();
if (logevent_id == 0) { if (logevent_id == 0) {
logevent_id = logevent_id =
BinlogHelper::add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*state->message)); binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*state->message));
LOG(INFO) << "Outbound secret message [save_logevent] start " << tag("logevent_id", logevent_id); LOG(INFO) << "Outbound secret message [save_logevent] start " << tag("logevent_id", logevent_id);
context_->binlog()->force_sync(std::move(save_logevent_finish)); context_->binlog()->force_sync(std::move(save_logevent_finish));
state->message->set_logevent_id(logevent_id); state->message->set_logevent_id(logevent_id);
@ -1175,7 +1175,7 @@ Status SecretChatActor::do_inbound_message_decrypted_pending(std::unique_ptr<log
if (logevent_id == 0) { if (logevent_id == 0) {
message->is_pending = true; message->is_pending = true;
message->set_logevent_id(BinlogHelper::add(context_->binlog(), LogEvent::HandlerType::SecretChats, message->set_logevent_id(binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats,
create_storer(*message), std::move(qts_promise))); create_storer(*message), std::move(qts_promise)));
LOG(INFO) << "Inbound PENDING secret message [save_logevent] start (do not expect finish) " LOG(INFO) << "Inbound PENDING secret message [save_logevent] start (do not expect finish) "
<< tag("logevent_id", message->logevent_id()); << tag("logevent_id", message->logevent_id());
@ -1210,15 +1210,15 @@ Status SecretChatActor::do_inbound_message_decrypted(std::unique_ptr<logevent::I
auto logevent_id = message->logevent_id(); auto logevent_id = message->logevent_id();
bool need_sync = false; bool need_sync = false;
if (logevent_id == 0) { if (logevent_id == 0) {
logevent_id = BinlogHelper::add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*message)); logevent_id = binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*message));
LOG(INFO) << "Inbound secret message [save_logevent] start " << tag("logevent_id", logevent_id); LOG(INFO) << "Inbound secret message [save_logevent] start " << tag("logevent_id", logevent_id);
need_sync = true; need_sync = true;
} else { } else {
if (message->is_pending) { if (message->is_pending) {
message->is_pending = false; message->is_pending = false;
auto old_logevent_id = logevent_id; auto old_logevent_id = logevent_id;
logevent_id = BinlogHelper::add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*message)); logevent_id = binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*message));
BinlogHelper::erase(context_->binlog(), old_logevent_id); binlog_erase(context_->binlog(), old_logevent_id);
LOG(INFO) << "Inbound secret message [save_logevent] rewrite (after pending state) " LOG(INFO) << "Inbound secret message [save_logevent] rewrite (after pending state) "
<< tag("logevent_id", logevent_id) << tag("old_logevent_id", old_logevent_id); << tag("logevent_id", logevent_id) << tag("old_logevent_id", old_logevent_id);
need_sync = true; need_sync = true;
@ -1422,7 +1422,7 @@ void SecretChatActor::inbound_loop(InboundMessageState *state, uint64 state_id)
return; return;
} }
LOG(INFO) << "Inbound message [remove_logevent] start " << tag("logevent_id", state->logevent_id); LOG(INFO) << "Inbound message [remove_logevent] start " << tag("logevent_id", state->logevent_id);
BinlogHelper::erase(context_->binlog(), state->logevent_id); binlog_erase(context_->binlog(), state->logevent_id);
inbound_message_states_.erase(state_id); inbound_message_states_.erase(state_id);
} }
@ -1496,7 +1496,7 @@ void SecretChatActor::outbound_resend(uint64 state_id) {
LOG(INFO) << "Oubound message [resend] " << tag("logevent_id", state->message->logevent_id()) LOG(INFO) << "Oubound message [resend] " << tag("logevent_id", state->message->logevent_id())
<< tag("state_id", state_id); << tag("state_id", state_id);
BinlogHelper::rewrite(context_->binlog(), state->message->logevent_id(), LogEvent::HandlerType::SecretChats, binlog_rewrite(context_->binlog(), state->message->logevent_id(), LogEvent::HandlerType::SecretChats,
create_storer(*state->message)); create_storer(*state->message));
auto send_message_start = PromiseCreator::lambda([actor_id = actor_id(this), state_id](Result<> result) { auto send_message_start = PromiseCreator::lambda([actor_id = actor_id(this), state_id](Result<> result) {
if (result.is_ok()) { if (result.is_ok()) {
@ -1535,7 +1535,7 @@ Status SecretChatActor::outbound_rewrite_with_empty(uint64 state_id) {
state->message->is_external = false; state->message->is_external = false;
state->message->is_service = true; state->message->is_service = true;
state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file(nullptr); state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file(nullptr);
BinlogHelper::rewrite(context_->binlog(), state->message->logevent_id(), LogEvent::HandlerType::SecretChats, binlog_rewrite(context_->binlog(), state->message->logevent_id(), LogEvent::HandlerType::SecretChats,
create_storer(*state->message)); create_storer(*state->message));
return Status::OK(); return Status::OK();
} }
@ -1765,7 +1765,7 @@ void SecretChatActor::outbound_loop(OutboundMessageState *state, uint64 state_id
} }
if (state->save_changes_finish_flag /*&& state->send_message_finish_flag*/ && state->ack_flag) { if (state->save_changes_finish_flag /*&& state->send_message_finish_flag*/ && state->ack_flag) {
LOG(INFO) << "Outbound message [remove_logevent] start " << tag("logevent_id", state->message->logevent_id()); LOG(INFO) << "Outbound message [remove_logevent] start " << tag("logevent_id", state->message->logevent_id());
BinlogHelper::erase(context_->binlog(), state->message->logevent_id()); binlog_erase(context_->binlog(), state->message->logevent_id());
random_id_to_outbound_message_state_token_.erase(state->message->random_id); random_id_to_outbound_message_state_token_.erase(state->message->random_id);
LOG(INFO) << "Outbound message finish (lazy) " << tag("logevent_id", state->message->logevent_id()); LOG(INFO) << "Outbound message finish (lazy) " << tag("logevent_id", state->message->logevent_id());
@ -1777,7 +1777,7 @@ void SecretChatActor::outbound_loop(OutboundMessageState *state, uint64 state_id
!state->message->is_sent) { // [rewrite_logevent] !state->message->is_sent) { // [rewrite_logevent]
LOG(INFO) << "Outbound message [rewrite_logevent] start " << tag("logevent_id", state->message->logevent_id()); LOG(INFO) << "Outbound message [rewrite_logevent] start " << tag("logevent_id", state->message->logevent_id());
state->message->is_sent = true; state->message->is_sent = true;
BinlogHelper::rewrite(context_->binlog(), state->message->logevent_id(), LogEvent::HandlerType::SecretChats, binlog_rewrite(context_->binlog(), state->message->logevent_id(), LogEvent::HandlerType::SecretChats,
create_storer(*state->message)); create_storer(*state->message));
} }
} }
@ -1836,7 +1836,7 @@ Status SecretChatActor::on_update_chat(telegram_api::encryptedChat &update) {
} }
auth_state_.state = State::Ready; auth_state_.state = State::Ready;
if (create_logevent_id_ != 0) { if (create_logevent_id_ != 0) {
BinlogHelper::erase(context_->binlog(), create_logevent_id_); binlog_erase(context_->binlog(), create_logevent_id_);
create_logevent_id_ = 0; create_logevent_id_ = 0;
} }

View File

@ -1412,7 +1412,7 @@ WebPageId WebPagesManager::on_get_web_page(tl_object_ptr<telegram_api::WebPage>
if (web_page_to_delete != nullptr) { if (web_page_to_delete != nullptr) {
if (web_page_to_delete->logevent_id != 0) { if (web_page_to_delete->logevent_id != 0) {
LOG(INFO) << "Erase " << web_page_id << " from binlog"; LOG(INFO) << "Erase " << web_page_id << " from binlog";
BinlogHelper::erase(G()->td_db()->get_binlog(), web_page_to_delete->logevent_id); binlog_erase(G()->td_db()->get_binlog(), web_page_to_delete->logevent_id);
web_page_to_delete->logevent_id = 0; web_page_to_delete->logevent_id = 0;
} }
web_pages_.erase(web_page_id); web_pages_.erase(web_page_id);
@ -2636,9 +2636,9 @@ void WebPagesManager::save_web_page(WebPage *web_page, WebPageId web_page_id, bo
WebPageLogEvent logevent(web_page_id, web_page); WebPageLogEvent logevent(web_page_id, web_page);
LogEventStorerImpl<WebPageLogEvent> storer(logevent); LogEventStorerImpl<WebPageLogEvent> storer(logevent);
if (web_page->logevent_id == 0) { if (web_page->logevent_id == 0) {
web_page->logevent_id = BinlogHelper::add(G()->td_db()->get_binlog(), LogEvent::HandlerType::WebPages, storer); web_page->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::WebPages, storer);
} else { } else {
BinlogHelper::rewrite(G()->td_db()->get_binlog(), web_page->logevent_id, LogEvent::HandlerType::WebPages, storer); binlog_rewrite(G()->td_db()->get_binlog(), web_page->logevent_id, LogEvent::HandlerType::WebPages, storer);
} }
} }
@ -2657,7 +2657,7 @@ string WebPagesManager::get_web_page_url_database_key(const string &url) {
void WebPagesManager::on_binlog_web_page_event(BinlogEvent &&event) { void WebPagesManager::on_binlog_web_page_event(BinlogEvent &&event) {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
BinlogHelper::erase(G()->td_db()->get_binlog(), event.id_); binlog_erase(G()->td_db()->get_binlog(), event.id_);
return; return;
} }
@ -2692,7 +2692,7 @@ void WebPagesManager::on_save_web_page_to_database(WebPageId web_page_id, bool s
LOG(INFO) << "Successfully saved " << web_page_id << " to database"; LOG(INFO) << "Successfully saved " << web_page_id << " to database";
if (web_page->logevent_id != 0) { if (web_page->logevent_id != 0) {
LOG(INFO) << "Erase " << web_page_id << " from binlog"; LOG(INFO) << "Erase " << web_page_id << " from binlog";
BinlogHelper::erase(G()->td_db()->get_binlog(), web_page->logevent_id); binlog_erase(G()->td_db()->get_binlog(), web_page->logevent_id);
web_page->logevent_id = 0; web_page->logevent_id = 0;
} }
} }

View File

@ -24,7 +24,7 @@ inline Promise<Unit> get_erase_logevent_promise(uint64 logevent_id, Promise<Unit
return PromiseCreator::lambda([logevent_id, promise = std::move(promise)](Result<Unit> result) mutable { return PromiseCreator::lambda([logevent_id, promise = std::move(promise)](Result<Unit> result) mutable {
if (!G()->close_flag()) { if (!G()->close_flag()) {
BinlogHelper::erase(G()->td_db()->get_binlog(), logevent_id); binlog_erase(G()->td_db()->get_binlog(), logevent_id);
} }
promise.set_result(std::move(result)); promise.set_result(std::move(result));

View File

@ -14,17 +14,16 @@
#include "td/utils/Storer.h" #include "td/utils/Storer.h"
namespace td { namespace td {
class BinlogHelper {
public:
template <class BinlogT, class StorerT> template <class BinlogT, class StorerT>
static uint64 add(const BinlogT &binlog_ptr, int32 type, const StorerT &storer, Promise<> promise = Promise<>()) { static uint64 binlog_add(const BinlogT &binlog_ptr, int32 type, const StorerT &storer,
Promise<> promise = Promise<>()) {
auto logevent_id = binlog_ptr->next_id(); 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)); binlog_ptr->add_raw_event(logevent_id, BinlogEvent::create_raw(logevent_id, type, 0, storer), std::move(promise));
return logevent_id; return logevent_id;
} }
template <class BinlogT, class StorerT> template <class BinlogT, class StorerT>
static uint64 rewrite(const BinlogT &binlog_ptr, uint64 logevent_id, int32 type, const StorerT &storer, static uint64 binlog_rewrite(const BinlogT &binlog_ptr, uint64 logevent_id, int32 type, const StorerT &storer,
Promise<> promise = Promise<>()) { Promise<> promise = Promise<>()) {
auto seq_no = binlog_ptr->next_id(); auto seq_no = binlog_ptr->next_id();
binlog_ptr->add_raw_event(seq_no, BinlogEvent::create_raw(logevent_id, type, BinlogEvent::Flags::Rewrite, storer), binlog_ptr->add_raw_event(seq_no, BinlogEvent::create_raw(logevent_id, type, BinlogEvent::Flags::Rewrite, storer),
@ -33,7 +32,7 @@ class BinlogHelper {
} }
template <class BinlogT> template <class BinlogT>
static uint64 erase(const BinlogT &binlog_ptr, uint64 logevent_id, Promise<> promise = Promise<>()) { static uint64 binlog_erase(const BinlogT &binlog_ptr, uint64 logevent_id, Promise<> promise = Promise<>()) {
auto seq_no = binlog_ptr->next_id(); auto seq_no = binlog_ptr->next_id();
binlog_ptr->add_raw_event(seq_no, binlog_ptr->add_raw_event(seq_no,
BinlogEvent::create_raw(logevent_id, BinlogEvent::ServiceTypes::Empty, BinlogEvent::create_raw(logevent_id, BinlogEvent::ServiceTypes::Empty,
@ -41,5 +40,4 @@ class BinlogHelper {
std::move(promise)); std::move(promise));
return seq_no; return seq_no;
} }
};
} // namespace td } // namespace td