From 59938791efbccfbda7e76cec0691714006aa8cf5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 18 Nov 2017 00:04:22 +0400 Subject: [PATCH] Closed beta 1.1.23.6: Log crash info. --- Telegram/SourceFiles/history/history.cpp | 93 +++++++++++++++++++ .../storage/storage_shared_media.cpp | 5 +- .../storage/storage_sparse_ids_list.cpp | 10 +- 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index e17ef2482e..edef4dc3c0 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1458,6 +1458,59 @@ template void History::addToSharedMedia(std::vector (&medias)[kSharedMediaTypeCount], bool force) { auto from = loadedAtTop() ? 0 : minMsgId(); auto till = loadedAtBottom() ? ServerMaxMsgId : maxMsgId(); + if (from > till) { + // History is desync, nothing good can be added. + //// Logging + auto value = QStringList(); + for (auto block : blocks) { + auto indices = QStringList(); + auto &items = block->items; + auto count = int(items.size()); + auto logItem = [&](auto &&item) { + indices.push_back(QString::number(item->id)); + }; + if (count < 4) { + for (auto item : items) { + logItem(item); + } + } else { + auto last = 0; + auto logLast = [&] { + logItem(items[last]); + }; + auto logTill = [&](int till) { + if (last < till - 1) { + indices.push_back("...[" + + QString::number(till - 1 - last) + + "]..."); + } + last = till; + logLast(); + }; + auto badPair = [&](int index) { + auto prev = items[index - 1]->id; + auto next = items[index]->id; + return IsServerMsgId(prev) + && IsServerMsgId(next) + && (next < prev); + }; + + logLast(); + for (auto i = 1; i != count - 1; ++i) { + if (badPair(i) || badPair(i + 1)) { + logTill(i); + } + } + logTill(count - 1); + } + value.push_back(indices.join(",")); + } + SignalHandlers::setCrashAnnotation("full", value.join(";")); + Assert(!"History desync caught!"); + //// Logging + + return; + } for (auto i = 0; i != Storage::kSharedMediaTypeCount; ++i) { if (force || !medias[i].empty()) { auto type = static_cast(i); @@ -1480,6 +1533,13 @@ void History::addOlderSlice(const QVector &slice) { return; } + auto logged = QStringList(); + logged.push_back(QString::number(minMsgId())); + logged.push_back(QString::number(maxMsgId())); + + auto minAdded = -1; + auto maxAdded = -1; + startBuildingFrontBlock(slice.size()); for (auto i = slice.cend(), e = slice.cbegin(); i != e;) { @@ -1487,6 +1547,13 @@ void History::addOlderSlice(const QVector &slice) { auto adding = createItem(*i, false, true); if (!adding) continue; + if (minAdded < 0 || minAdded > adding->id) { + minAdded = adding->id; + } + if (maxAdded < 0 || maxAdded < adding->id) { + maxAdded = adding->id; + } + addItemToBlock(adding); } @@ -1578,8 +1645,15 @@ void History::addOlderSlice(const QVector &slice) { Notify::peerUpdatedDelayed(update); } } + + logged.push_back(QString::number(minAdded)); + logged.push_back(QString::number(maxAdded)); + SignalHandlers::setCrashAnnotation("add", logged.join(";")); + addBlockToSharedMedia(block); + SignalHandlers::setCrashAnnotation("add", ""); + if (isChannel()) { asChannelHistory()->checkJoinedMessage(); asChannelHistory()->checkMaxReadMessageDate(); @@ -1599,6 +1673,13 @@ void History::addNewerSlice(const QVector &slice) { Assert(!isBuildingFrontBlock()); if (!slice.isEmpty()) { + auto logged = QStringList(); + logged.push_back(QString::number(minMsgId())); + logged.push_back(QString::number(maxMsgId())); + + auto minAdded = -1; + auto maxAdded = -1; + std::vector medias[Storage::kSharedMediaTypeCount]; auto atLeastOneAdded = false; for (auto i = slice.cend(), e = slice.cbegin(); i != e;) { @@ -1606,6 +1687,13 @@ void History::addNewerSlice(const QVector &slice) { auto adding = createItem(*i, false, true); if (!adding) continue; + if (minAdded < 0 || minAdded > adding->id) { + minAdded = adding->id; + } + if (maxAdded < 0 || maxAdded < adding->id) { + maxAdded = adding->id; + } + addItemToBlock(adding); atLeastOneAdded = true; if (auto types = adding->sharedMediaTypes()) { @@ -1620,12 +1708,17 @@ void History::addNewerSlice(const QVector &slice) { } } } + logged.push_back(QString::number(minAdded)); + logged.push_back(QString::number(maxAdded)); + SignalHandlers::setCrashAnnotation("add", logged.join(";")); if (!atLeastOneAdded) { newLoaded = true; setLastMessage(lastAvailableMessage()); } addToSharedMedia(medias, wasLoadedAtBottom != loadedAtBottom()); + + SignalHandlers::setCrashAnnotation("add", ""); } if (!wasLoadedAtBottom) { diff --git a/Telegram/SourceFiles/storage/storage_shared_media.cpp b/Telegram/SourceFiles/storage/storage_shared_media.cpp index 8099252856..3c0e76aff2 100644 --- a/Telegram/SourceFiles/storage/storage_shared_media.cpp +++ b/Telegram/SourceFiles/storage/storage_shared_media.cpp @@ -73,7 +73,10 @@ void SharedMedia::add(SharedMediaAddSlice &&query) { Expects(IsValidSharedMediaType(query.type)); auto peerIt = enforceLists(query.peerId); auto index = static_cast(query.type); - peerIt->second[index].addSlice(std::move(query.messageIds), query.noSkipRange, query.count); + peerIt->second[index].addSlice( + std::move(query.messageIds), + query.noSkipRange, + query.count); } void SharedMedia::remove(SharedMediaRemoveOne &&query) { diff --git a/Telegram/SourceFiles/storage/storage_sparse_ids_list.cpp b/Telegram/SourceFiles/storage/storage_sparse_ids_list.cpp index df11949f16..1242955ebd 100644 --- a/Telegram/SourceFiles/storage/storage_sparse_ids_list.cpp +++ b/Telegram/SourceFiles/storage/storage_sparse_ids_list.cpp @@ -75,9 +75,8 @@ int SparseIdsList::addRangeItemsAndCountNew( SparseIdsSliceUpdate &update, const Range &messages, MsgRange noSkipRange) { - Expects((noSkipRange.from < noSkipRange.till) - || (noSkipRange.from == noSkipRange.till && messages.begin() == messages.end())); - if (noSkipRange.from == noSkipRange.till) { + Expects(noSkipRange.from <= noSkipRange.till); + if (messages.begin() == messages.end()) { return 0; } @@ -114,7 +113,10 @@ void SparseIdsList::addRange( auto wasCount = _count; auto update = SparseIdsSliceUpdate(); - auto result = addRangeItemsAndCountNew(update, messages, noSkipRange); + auto result = addRangeItemsAndCountNew( + update, + messages, + noSkipRange); if (count) { _count = count; } else if (incrementCount && _count && result > 0) {