Skip to content

Commit 7f60c60

Browse files
Prune runtime-deleted object dictionary every 15 Minutes
1 parent 7d8aa99 commit 7f60c60

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

lib/remote/apilistener-configsync.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,23 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient
532532
Log(LogInformation, "ApiListener")
533533
<< "Finished syncing runtime objects to endpoint '" << endpoint->GetName() << "'.";
534534
}
535+
536+
void ApiListener::PruneDeletedRuntimeObjects()
537+
{
538+
auto deletedRuntimeObjects = GetDeletedRuntimeObjects();
539+
540+
auto endpoints = ConfigType::GetObjectsByType<Endpoint>();
541+
auto it = std::max_element(endpoints.begin(), endpoints.end(), [](const auto& a, const auto& b) {
542+
return a->GetLogDuration() < b->GetLogDuration();
543+
});
544+
ASSERT(it != endpoints.end());
545+
auto maxLogDuration = (*it)->GetLogDuration();
546+
547+
ObjectLock lock(deletedRuntimeObjects);
548+
549+
for (auto it = deletedRuntimeObjects->Begin(); it != deletedRuntimeObjects->End(); ++it) {
550+
if (it->second <= maxLogDuration) {
551+
deletedRuntimeObjects->Remove(it);
552+
};
553+
}
554+
}

lib/remote/apilistener.cpp

Lines changed: 6 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);

lib/remote/apilistener.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class ApiListener final : public ObjectImpl<ApiListener>
142142

143143
static void UpdateObjectAuthority();
144144

145+
void PruneDeletedRuntimeObjects();
146+
145147
static bool IsHACluster();
146148
static String GetFromZoneName(const Zone::Ptr& fromZone);
147149

@@ -183,6 +185,7 @@ class ApiListener final : public ObjectImpl<ApiListener>
183185
std::set<HttpServerConnection::Ptr> m_HttpClients;
184186

185187
Timer::Ptr m_Timer;
188+
Timer::Ptr m_DeletedRuntimeObjectsTimer;
186189
Timer::Ptr m_ReconnectTimer;
187190
Timer::Ptr m_AuthorityTimer;
188191
Timer::Ptr m_CleanupCertificateRequestsTimer;

0 commit comments

Comments
 (0)