Skip to content

Commit 8141a34

Browse files
Prune runtime-deleted object dictionary every 15 Minutes
1 parent 08fcc5a commit 8141a34

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

lib/remote/apilistener-configsync.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,38 @@ 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+
double cutoff = Utility::GetTime() - maxLogDuration;
575+
576+
ObjectLock lock(deletedRuntimeObjects);
577+
578+
for (auto it = deletedRuntimeObjects->Begin(); it != deletedRuntimeObjects->End();) {
579+
if (it->second < cutoff) {
580+
it = deletedRuntimeObjects->Remove(it);
581+
} else {
582+
it++;
583+
};
584+
}
585+
}
586+
555587
static String MakeDeletionTimestampKey(const String& typeName, const String& objName)
556588
{
557589
return typeName + ":" + objName;

lib/remote/apilistener.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ void ApiListener::Start(bool runtimeCreated)
297297
m_Timer->Start();
298298
m_Timer->Reschedule(0);
299299

300+
m_DeletedRuntimeObjectsTimer = Timer::Create();
301+
m_DeletedRuntimeObjectsTimer->OnTimerExpired.connect([this](const Timer* const&) { PruneDeletedRuntimeObjects(); });
302+
m_DeletedRuntimeObjectsTimer->SetInterval(15 * 60);
303+
m_DeletedRuntimeObjectsTimer->Start();
304+
m_DeletedRuntimeObjectsTimer->Reschedule(0);
305+
300306
m_ReconnectTimer = Timer::Create();
301307
m_ReconnectTimer->OnTimerExpired.connect([this](const Timer * const&) { ApiReconnectTimerHandler(); });
302308
m_ReconnectTimer->SetInterval(10);
@@ -379,6 +385,7 @@ void ApiListener::Stop(bool runtimeDeleted)
379385
m_CleanupCertificateRequestsTimer->Stop(true);
380386
m_AuthorityTimer->Stop(true);
381387
m_ReconnectTimer->Stop(true);
388+
m_DeletedRuntimeObjectsTimer->Stop(true);
382389
m_Timer->Stop(true);
383390
m_RenewOwnCertTimer->Stop(true);
384391

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)