From e9605168a11b7cbfdee210b3b378ba6aca3b4369 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 21 Jul 2016 12:27:18 +0200 Subject: [PATCH] Increase reconnection timer interval for cluster connections fixes #12193 --- lib/remote/apilistener.cpp | 82 +++++++++++++++++++++----------------- lib/remote/apilistener.hpp | 2 + 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 4a31eb8e9..01c7d6db3 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -142,6 +142,12 @@ void ApiListener::Start(bool runtimeCreated) m_Timer->Start(); m_Timer->Reschedule(0); + m_ReconnectTimer = new Timer(); + m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&ApiListener::ApiReconnectTimerHandler, this)); + m_ReconnectTimer->SetInterval(60); + m_ReconnectTimer->Start(); + m_ReconnectTimer->Reschedule(0); + OnMasterChanged(true); } @@ -489,6 +495,46 @@ void ApiListener::ApiTimerHandler(void) } } + BOOST_FOREACH(const Endpoint::Ptr& endpoint, ConfigType::GetObjectsByType()) { + if (!endpoint->GetConnected()) + continue; + + double ts = endpoint->GetRemoteLogPosition(); + + if (ts == 0) + continue; + + Dictionary::Ptr lparams = new Dictionary(); + lparams->Set("log_position", ts); + + Dictionary::Ptr lmessage = new Dictionary(); + lmessage->Set("jsonrpc", "2.0"); + lmessage->Set("method", "log::SetLogPosition"); + lmessage->Set("params", lparams); + + double maxTs = 0; + + BOOST_FOREACH(const JsonRpcConnection::Ptr& client, endpoint->GetClients()) { + if (client->GetTimestamp() > maxTs) + maxTs = client->GetTimestamp(); + } + + BOOST_FOREACH(const JsonRpcConnection::Ptr& client, endpoint->GetClients()) { + if (client->GetTimestamp() != maxTs) + client->Disconnect(); + else + client->SendMessage(lmessage); + } + + Log(LogNotice, "ApiListener") + << "Setting log position for identity '" << endpoint->GetName() << "': " + << Utility::FormatDateTime("%Y/%m/%d %H:%M:%S", ts); + } + +} + +void ApiListener::ApiReconnectTimerHandler(void) +{ Zone::Ptr my_zone = Zone::GetLocalZone(); BOOST_FOREACH(const Zone::Ptr& zone, ConfigType::GetObjectsByType()) { @@ -541,42 +587,6 @@ void ApiListener::ApiTimerHandler(void) } } - BOOST_FOREACH(const Endpoint::Ptr& endpoint, ConfigType::GetObjectsByType()) { - if (!endpoint->GetConnected()) - continue; - - double ts = endpoint->GetRemoteLogPosition(); - - if (ts == 0) - continue; - - Dictionary::Ptr lparams = new Dictionary(); - lparams->Set("log_position", ts); - - Dictionary::Ptr lmessage = new Dictionary(); - lmessage->Set("jsonrpc", "2.0"); - lmessage->Set("method", "log::SetLogPosition"); - lmessage->Set("params", lparams); - - double maxTs = 0; - - BOOST_FOREACH(const JsonRpcConnection::Ptr& client, endpoint->GetClients()) { - if (client->GetTimestamp() > maxTs) - maxTs = client->GetTimestamp(); - } - - BOOST_FOREACH(const JsonRpcConnection::Ptr& client, endpoint->GetClients()) { - if (client->GetTimestamp() != maxTs) - client->Disconnect(); - else - client->SendMessage(lmessage); - } - - Log(LogNotice, "ApiListener") - << "Setting log position for identity '" << endpoint->GetName() << "': " - << Utility::FormatDateTime("%Y/%m/%d %H:%M:%S", ts); - } - Endpoint::Ptr master = GetMaster(); if (master) diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index 895524f69..3f9a325a8 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -111,11 +111,13 @@ private: std::set m_AnonymousClients; std::set m_HttpClients; Timer::Ptr m_Timer; + Timer::Ptr m_ReconnectTimer; Endpoint::Ptr m_LocalEndpoint; static ApiListener::Ptr m_Instance; void ApiTimerHandler(void); + void ApiReconnectTimerHandler(void); bool AddListener(const String& node, const String& service); void AddConnection(const Endpoint::Ptr& endpoint);