ApiListener#ReplayLog(): replay messages from SQLite

This commit is contained in:
Alexander A. Klimov 2020-04-09 15:46:38 +02:00
parent 345e323481
commit 7a48bb856b

View File

@ -1565,16 +1565,50 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
} }
if (last_sync) { if (last_sync) {
{
ObjectLock olock2(endpoint);
endpoint->SetSyncing(false);
}
OpenLogFile(); OpenLogFile();
break; break;
} }
} }
Log(LogNotice, "ApiListener")
<< "Replaying log.";
count = 0;
for (auto& message : endpoint->GetReplayLog()) {
try {
client->SendRawMessage(message.second);
} catch (const std::exception& ex) {
Log(LogWarning, "ApiListener")
<< "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex, false);
Log(LogDebug, "ApiListener")
<< "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex);
break;
}
++count;
if (message.first > logpos_ts + 10) {
logpos_ts = message.first;
client->SendMessage(new Dictionary({
{ "jsonrpc", "2.0" },
{ "method", "log::SetLogPosition" },
{ "params", new Dictionary({
{ "log_position", logpos_ts }
}) }
}));
}
}
Log(count > 0u ? LogInformation : LogNotice, "ApiListener")
<< "Replayed " << count << " messages.";
ObjectLock olock2(endpoint);
endpoint->SetSyncing(false);
} }
void ApiListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata) void ApiListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)