Skip to content

Commit bfafef7

Browse files
Prune runtime-deleted object dictionary every 15 Minutes
1 parent 925d862 commit bfafef7

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

lib/remote/apilistener-configsync.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,37 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient
552552
<< "Finished syncing runtime objects to endpoint '" << endpoint->GetName() << "'.";
553553
}
554554

555+
/**
556+
* Prunes the list of deleted runtime objects.
557+
*
558+
* This takes into account the longest log duration of all the endpoints in the cluster and
559+
* then deletes the entries for objects that are older than that.
560+
*
561+
* The reasoning is that once a deletion is older than log duration of an endpoint it is
562+
* unlikely that we could still get any delayed updates to the object versions that were deleted.
563+
* At that point, either all endpoints are up-to-date, or the problematic messages have been
564+
* dropped from the replay log anyway.
565+
*/
566+
void ApiListener::PruneDeletedRuntimeObjects()
567+
{
568+
auto deletedRuntimeObjects = GetDeletedRuntimeObjects();
569+
570+
double maxLogDuration = 0;
571+
for (const auto &endpoint : ConfigType::GetObjectsByType<Endpoint>()) {
572+
maxLogDuration = std::max(maxLogDuration, endpoint->GetLogDuration());
573+
}
574+
575+
ObjectLock lock(deletedRuntimeObjects);
576+
577+
for (auto it = deletedRuntimeObjects->Begin(); it != deletedRuntimeObjects->End();) {
578+
if (it->second <= maxLogDuration) {
579+
it = deletedRuntimeObjects->Remove(it);
580+
} else {
581+
it++;
582+
};
583+
}
584+
}
585+
555586
static String MakeDeletionTimestampKey(const String& typeName, const String& objName)
556587
{
557588
return typeName + ":" + objName;

lib/remote/apilistener.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ void ApiListener::Start(bool runtimeCreated)
285285
m_Timer->Start();
286286
m_Timer->Reschedule(0);
287287

288+
m_DeletedRuntimeObjectsTimer = Timer::Create();
289+
m_DeletedRuntimeObjectsTimer->OnTimerExpired.connect([this](const Timer* const&) { PruneDeletedRuntimeObjects(); });
290+
m_DeletedRuntimeObjectsTimer->SetInterval(15 * 60);
291+
m_DeletedRuntimeObjectsTimer->Start();
292+
m_DeletedRuntimeObjectsTimer->Reschedule(0);
293+
288294
m_ReconnectTimer = Timer::Create();
289295
m_ReconnectTimer->OnTimerExpired.connect([this](const Timer * const&) { ApiReconnectTimerHandler(); });
290296
m_ReconnectTimer->SetInterval(10);
@@ -367,6 +373,7 @@ void ApiListener::Stop(bool runtimeDeleted)
367373
m_CleanupCertificateRequestsTimer->Stop(true);
368374
m_AuthorityTimer->Stop(true);
369375
m_ReconnectTimer->Stop(true);
376+
m_DeletedRuntimeObjectsTimer->Stop(true);
370377
m_Timer->Stop(true);
371378
m_RenewOwnCertTimer->Stop(true);
372379

lib/remote/apilistener.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class ApiListener final : public ObjectImpl<ApiListener>
183183
std::set<HttpServerConnection::Ptr> m_HttpClients;
184184

185185
Timer::Ptr m_Timer;
186+
Timer::Ptr m_DeletedRuntimeObjectsTimer;
186187
Timer::Ptr m_ReconnectTimer;
187188
Timer::Ptr m_AuthorityTimer;
188189
Timer::Ptr m_CleanupCertificateRequestsTimer;
@@ -204,6 +205,7 @@ class ApiListener final : public ObjectImpl<ApiListener>
204205
void CleanupCertificateRequestsTimerHandler();
205206
void CheckApiPackageIntegrity();
206207

208+
void PruneDeletedRuntimeObjects();
207209
double GetRuntimeObjectDeletionTs(const String& typeName, const String& objName);
208210
bool UpdateRuntimeObjectDeletionTs(const String& typeName, const String& objName, double ts);
209211

0 commit comments

Comments
 (0)