[icinga-checkins] icinga.org: icinga2/master: Increase reconnection timer interval for cluster connections

git at icinga.org git at icinga.org
Thu Jul 21 12:27:34 CEST 2016


Module: icinga2
Branch: master
Commit: e9605168a11b7cbfdee210b3b378ba6aca3b4369
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=e9605168a11b7cbfdee210b3b378ba6aca3b4369

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Thu Jul 21 12:27:18 2016 +0200

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 4a31eb8..01c7d6d 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<Endpoint>()) {
+		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<Zone>()) {
@@ -541,42 +587,6 @@ void ApiListener::ApiTimerHandler(void)
 		}
 	}
 
-	BOOST_FOREACH(const Endpoint::Ptr& endpoint, ConfigType::GetObjectsByType<Endpoint>()) {
-		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 895524f..3f9a325 100644
--- a/lib/remote/apilistener.hpp
+++ b/lib/remote/apilistener.hpp
@@ -111,11 +111,13 @@ private:
 	std::set<JsonRpcConnection::Ptr> m_AnonymousClients;
 	std::set<HttpServerConnection::Ptr> 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);



More information about the icinga-checkins mailing list