Use Defer class for cleanup in ApiListener::ReplayLog()

This commit is contained in:
Yonas Habteab 2024-02-13 09:30:26 +01:00 committed by Alexander A. Klimov
parent 9a0c7d7c75
commit 5f2d31bf3c

View File

@ -1434,10 +1434,12 @@ void ApiListener::LogGlobHandler(std::vector<int>& files, const String& file)
void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
{
Endpoint::Ptr endpoint = client->GetEndpoint();
Defer resetEndpointSyncing ([&endpoint]() {
ObjectLock olock(endpoint);
endpoint->SetSyncing(false);
});
if (endpoint->GetLogDuration() == 0) {
ObjectLock olock2(endpoint);
endpoint->SetSyncing(false);
return;
}
@ -1454,14 +1456,10 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
Zone::Ptr target_zone = target_endpoint->GetZone();
if (!target_zone) {
ObjectLock olock2(endpoint);
endpoint->SetSyncing(false);
return;
}
bool stopReplay = false;
do {
for (;;) {
std::unique_lock<std::mutex> lock(m_LogLock);
CloseLogFile();
@ -1543,9 +1541,7 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
Log(LogDebug, "ApiListener")
<< "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex);
stopReplay = true;
break;
return;
}
peer_ts = pmessage->Get("timestamp");
@ -1566,10 +1562,6 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
}
logStream->Close();
if (stopReplay) {
break;
}
}
if (count > 0) {
@ -1584,12 +1576,9 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
if (last_sync) {
OpenLogFile();
break;
return;
}
} while (!stopReplay);
ObjectLock olock2 (endpoint);
endpoint->SetSyncing(false);
}
}
void ApiListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)