Trying to repair broken messages in the database.

GitOrigin-RevId: 1720ff9641329b1b027dc2529f0b8df8e9124dae
This commit is contained in:
levlam 2018-12-12 05:22:26 +03:00
parent eb18842279
commit d0f8450726
2 changed files with 9 additions and 6 deletions

View File

@ -14075,16 +14075,19 @@ void MessagesManager::preload_older_messages(const Dialog *d, MessageId min_mess
} }
} }
unique_ptr<MessagesManager::Message> MessagesManager::parse_message(const BufferSlice &value) { unique_ptr<MessagesManager::Message> MessagesManager::parse_message(DialogId dialog_id, const BufferSlice &value) {
LOG(INFO) << "Loaded message of size " << value.size() << " from database"; LOG(INFO) << "Loaded message of size " << value.size() << " from database";
auto m = make_unique<Message>(); auto m = make_unique<Message>();
auto status = log_event_parse(*m, value.as_slice()); auto status = log_event_parse(*m, value.as_slice());
if (status.is_error() || !m->message_id.is_valid()) { if (status.is_error() || !m->message_id.is_valid()) {
// can't happen unless database is broken, but has been seen in the wild // can't happen unless database is broken, but has been seen in the wild
LOG(ERROR) << "Receive invalid message from database: " << m->message_id << ' ' << status << ' '
LOG(FATAL) << "Receive invalid message from database: " << m->message_id << ' ' << status << ' '
<< format::as_hex_dump<4>(value.as_slice()); << format::as_hex_dump<4>(value.as_slice());
if (dialog_id.get_type() != DialogType::SecretChat && m->message_id.is_valid() && m->message_id.is_server()) {
// trying to repair the message
get_messages_from_server({FullMessageId{dialog_id, m->message_id}}, Auto());
}
return nullptr; return nullptr;
} }
@ -14128,7 +14131,7 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId
if (!d->first_database_message_id.is_valid() && !d->have_full_history) { if (!d->first_database_message_id.is_valid() && !d->have_full_history) {
break; break;
} }
auto message = parse_message(std::move(message_slice)); auto message = parse_message(dialog_id, std::move(message_slice));
if (message == nullptr) { if (message == nullptr) {
if (d->have_full_history) { if (d->have_full_history) {
d->have_full_history = false; d->have_full_history = false;
@ -20479,7 +20482,7 @@ MessagesManager::Message *MessagesManager::on_get_message_from_database(DialogId
return nullptr; return nullptr;
} }
auto m = parse_message(std::move(value)); auto m = parse_message(dialog_id, std::move(value));
if (m == nullptr) { if (m == nullptr) {
return nullptr; return nullptr;
} }

View File

@ -1918,7 +1918,7 @@ class MessagesManager : public Actor {
string get_search_text(const Message *m) const; string get_search_text(const Message *m) const;
static unique_ptr<Message> parse_message(const BufferSlice &value); unique_ptr<Message> parse_message(DialogId dialog_id, const BufferSlice &value);
unique_ptr<Dialog> parse_dialog(DialogId dialog_id, const BufferSlice &value); unique_ptr<Dialog> parse_dialog(DialogId dialog_id, const BufferSlice &value);