From 7a48bb856bfb7a2f845963223e70a3d0454f0596 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 9 Apr 2020 15:46:38 +0200 Subject: [PATCH] ApiListener#ReplayLog(): replay messages from SQLite --- lib/remote/apilistener.cpp | 44 +++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 8a5f087f9..6af6267b4 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -1565,16 +1565,50 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client) } if (last_sync) { - { - ObjectLock olock2(endpoint); - endpoint->SetSyncing(false); - } - OpenLogFile(); 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)