Skip to content

Commit 8fe26b3

Browse files
Prune runtime-deleted object dictionary every 15 Minutes
1 parent 8740638 commit 8fe26b3

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
@@ -558,6 +558,37 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient
558558
<< "Finished syncing runtime objects to endpoint '" << endpoint->GetName() << "'.";
559559
}
560560

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