From 3a2af5d4b153ce78872c0bf531270a80270db817 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 3 Apr 2019 02:22:34 +0300 Subject: [PATCH] Add TdDb::get_binlog debug. GitOrigin-RevId: c1a155df722fbc8901f02875eabb00e857179914 --- td/telegram/NotificationManager.cpp | 12 ++++++++---- td/telegram/NotificationManager.h | 1 + td/telegram/PollManager.cpp | 15 ++++++++------- td/telegram/TdDb.cpp | 5 +++-- td/telegram/TdDb.h | 2 +- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 9696ea659..11c93e8e7 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -1626,7 +1626,9 @@ void NotificationManager::on_notification_removed(NotificationId notification_id return; } VLOG(notifications) << "Remove from binlog " << notification_id << " with logevent " << it->second; - binlog_erase(G()->td_db()->get_binlog(), it->second); + if (!is_being_destroyed_) { + binlog_erase(G()->td_db()->get_binlog("on_notification_removed"), it->second); + } temporary_notification_logevent_ids_.erase(it); } @@ -3170,7 +3172,7 @@ void NotificationManager::process_message_push_notification(DialogId dialog_id, VLOG(notifications) << "Don't need message push notification for " << message_id << "/" << random_id << " from " << dialog_id << ": " << r_info.error(); if (logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), logevent_id); + binlog_erase(G()->td_db()->get_binlog("process_message_push_notification"), logevent_id); } if (r_info.error().code() == 406) { promise.set_error(r_info.move_as_error()); @@ -3223,7 +3225,8 @@ void NotificationManager::process_message_push_notification(DialogId dialog_id, sender_name, date, contains_mention, is_silent, loc_key, arg, notification_id}; auto storer = LogEventStorerImpl(logevent); - logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::AddMessagePushNotification, storer); + logevent_id = binlog_add(G()->td_db()->get_binlog("process_message_push_notification 2"), + LogEvent::HandlerType::AddMessagePushNotification, storer); } if (logevent_id != 0) { @@ -3451,6 +3454,7 @@ void NotificationManager::destroy_all_notifications() { if (is_destroyed_) { return; } + is_being_destroyed_ = true; size_t cur_pos = 0; for (auto it = groups_.begin(); it != groups_.end() && cur_pos < max_notification_group_count_; ++it, cur_pos++) { @@ -3548,7 +3552,7 @@ void NotificationManager::on_binlog_events(vector &&events) { switch (event.type_) { case LogEvent::HandlerType::AddMessagePushNotification: { if (!G()->parameters().use_message_db || is_disabled() || max_notification_group_count_ == 0) { - binlog_erase(G()->td_db()->get_binlog(), event.id_); + binlog_erase(G()->td_db()->get_binlog("AddMessagePushNotification"), event.id_); break; } diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 1913896e9..392b1b76b 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -331,6 +331,7 @@ class NotificationManager : public Actor { SyncState contact_registered_notifications_sync_state_ = SyncState::NotSynced; bool disable_contact_registered_notifications_ = false; + bool is_being_destroyed_ = false; bool is_destroyed_ = false; bool is_inited_ = false; diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index 886f91f92..d0be260b0 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -598,13 +598,14 @@ void PollManager::do_set_poll_answer(PollId poll_id, FullMessageId full_message_ auto storer = LogEventStorerImpl(logevent); if (pending_answer.generation_ == 0) { CHECK(pending_answer.logevent_id_ == 0); - logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SetPollAnswer, storer); + logevent_id = + binlog_add(G()->td_db()->get_binlog("do_set_poll_answer"), LogEvent::HandlerType::SetPollAnswer, storer); LOG(INFO) << "Add set poll answer logevent " << logevent_id; } else { CHECK(pending_answer.logevent_id_ != 0); logevent_id = pending_answer.logevent_id_; - auto new_logevent_id = binlog_rewrite(G()->td_db()->get_binlog(), pending_answer.logevent_id_, - LogEvent::HandlerType::SetPollAnswer, storer); + auto new_logevent_id = binlog_rewrite(G()->td_db()->get_binlog("do_set_poll_answer_2"), + pending_answer.logevent_id_, LogEvent::HandlerType::SetPollAnswer, storer); LOG(INFO) << "Rewrite set poll answer logevent " << logevent_id << " with " << new_logevent_id; } } @@ -663,7 +664,7 @@ void PollManager::on_set_poll_answer(PollId poll_id, uint64 generation, if (pending_answer.logevent_id_ != 0) { LOG(INFO) << "Delete set poll answer logevent " << pending_answer.logevent_id_; - binlog_erase(G()->td_db()->get_binlog(), pending_answer.logevent_id_); + binlog_erase(G()->td_db()->get_binlog("on_set_poll_answer"), pending_answer.logevent_id_); } auto promises = std::move(pending_answer.promises_); @@ -729,7 +730,7 @@ void PollManager::do_stop_poll(PollId poll_id, FullMessageId full_message_id, ui if (logevent_id == 0 && G()->parameters().use_message_db) { StopPollLogEvent logevent{poll_id, full_message_id}; auto storer = LogEventStorerImpl(logevent); - logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::StopPoll, storer); + logevent_id = binlog_add(G()->td_db()->get_binlog("do_stop_poll"), LogEvent::HandlerType::StopPoll, storer); } auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise)); @@ -978,7 +979,7 @@ void PollManager::on_binlog_events(vector &&events) { switch (event.type_) { case LogEvent::HandlerType::SetPollAnswer: { if (!G()->parameters().use_message_db) { - binlog_erase(G()->td_db()->get_binlog(), event.id_); + binlog_erase(G()->td_db()->get_binlog("SetPollAnswer"), event.id_); break; } @@ -997,7 +998,7 @@ void PollManager::on_binlog_events(vector &&events) { } case LogEvent::HandlerType::StopPoll: { if (!G()->parameters().use_message_db) { - binlog_erase(G()->td_db()->get_binlog(), event.id_); + binlog_erase(G()->td_db()->get_binlog("StopPoll"), event.id_); break; } diff --git a/td/telegram/TdDb.cpp b/td/telegram/TdDb.cpp index 15f1df6b9..f850b8460 100644 --- a/td/telegram/TdDb.cpp +++ b/td/telegram/TdDb.cpp @@ -8,6 +8,7 @@ #include "td/telegram/DialogDb.h" #include "td/telegram/files/FileDb.h" +#include "td/telegram/Global.h" #include "td/telegram/logevent/LogEvent.h" #include "td/telegram/MessagesDb.h" #include "td/telegram/TdParameters.h" @@ -146,8 +147,8 @@ std::shared_ptr &TdDb::get_sqlite_connection_safe() { return sql_connection_; } -BinlogInterface *TdDb::get_binlog() { - CHECK(binlog_); +BinlogInterface *TdDb::get_binlog(const char *source) { + LOG_CHECK(binlog_) << G()->close_flag() << " " << source; return binlog_.get(); } diff --git a/td/telegram/TdDb.h b/td/telegram/TdDb.h index ecc219e8f..6a9e1d292 100644 --- a/td/telegram/TdDb.h +++ b/td/telegram/TdDb.h @@ -70,7 +70,7 @@ class TdDb { std::shared_ptr get_file_db_shared(); std::shared_ptr &get_sqlite_connection_safe(); - BinlogInterface *get_binlog(); + BinlogInterface *get_binlog(const char *source = "unknown"); std::shared_ptr get_binlog_pmc_shared(); std::shared_ptr get_config_pmc_shared();