Closed beta 1.1.23.6: Log crash info.

This commit is contained in:
John Preston 2017-11-18 00:04:22 +04:00
parent 3ef0bcc5d5
commit 59938791ef
3 changed files with 103 additions and 5 deletions

View File

@ -1458,6 +1458,59 @@ template <int kSharedMediaTypeCount>
void History::addToSharedMedia(std::vector<MsgId> (&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<Storage::SharedMediaType>(i);
@ -1480,6 +1533,13 @@ void History::addOlderSlice(const QVector<MTPMessage> &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<MTPMessage> &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<MTPMessage> &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<MTPMessage> &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<MsgId> 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<MTPMessage> &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<MTPMessage> &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) {

View File

@ -73,7 +73,10 @@ void SharedMedia::add(SharedMediaAddSlice &&query) {
Expects(IsValidSharedMediaType(query.type));
auto peerIt = enforceLists(query.peerId);
auto index = static_cast<int>(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) {

View File

@ -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) {