[icinga-checkins] icinga.org: icinga2/master: Improve performance for Endpoint config validation

git at icinga.org git at icinga.org
Tue Aug 16 13:55:40 CEST 2016


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Aug 16 13:53:45 2016 +0200

Improve performance for Endpoint config validation

fixes #12450

---

 lib/remote/endpoint.cpp |   24 +++++++++---------------
 lib/remote/endpoint.hpp |    2 ++
 lib/remote/endpoint.ti  |    2 ++
 lib/remote/zone.cpp     |    8 ++++++++
 4 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/lib/remote/endpoint.cpp b/lib/remote/endpoint.cpp
index 1cfe9ed..e90e150 100644
--- a/lib/remote/endpoint.cpp
+++ b/lib/remote/endpoint.cpp
@@ -39,26 +39,20 @@ void Endpoint::OnAllConfigLoaded(void)
 {
 	ObjectImpl<Endpoint>::OnAllConfigLoaded();
 
-	BOOST_FOREACH(const Zone::Ptr& zone, ConfigType::GetObjectsByType<Zone>()) {
-		const std::set<Endpoint::Ptr> members = zone->GetEndpoints();
-
-		if (members.empty())
-			continue;
-
-		if (members.find(this) != members.end()) {
-			if (m_Zone)
-				BOOST_THROW_EXCEPTION(ScriptError("Endpoint '" + GetName()
-				    + "' is in more than one zone.", GetDebugInfo()));
-
-			m_Zone = zone;
-		}
-	}
-
 	if (!m_Zone)
 		BOOST_THROW_EXCEPTION(ScriptError("Endpoint '" + GetName() +
 		    "' does not belong to a zone.", GetDebugInfo()));
 }
 
+void Endpoint::SetCachedZone(const Zone::Ptr& zone)
+{
+	if (m_Zone)
+		BOOST_THROW_EXCEPTION(ScriptError("Endpoint '" + GetName()
+		    + "' is in more than one zone.", GetDebugInfo()));
+
+	m_Zone = zone;
+}
+
 void Endpoint::AddClient(const JsonRpcConnection::Ptr& client)
 {
 	bool was_master = ApiListener::GetInstance()->IsMaster();
diff --git a/lib/remote/endpoint.hpp b/lib/remote/endpoint.hpp
index 6e91dfc..2bc9159 100644
--- a/lib/remote/endpoint.hpp
+++ b/lib/remote/endpoint.hpp
@@ -54,6 +54,8 @@ public:
 
 	static Endpoint::Ptr GetLocalEndpoint(void);
 
+	void SetCachedZone(const intrusive_ptr<Zone>& zone);
+
 protected:
 	virtual void OnAllConfigLoaded(void) override;
 
diff --git a/lib/remote/endpoint.ti b/lib/remote/endpoint.ti
index 5253e13..a0272e7 100644
--- a/lib/remote/endpoint.ti
+++ b/lib/remote/endpoint.ti
@@ -26,6 +26,8 @@ namespace icinga
 
 class Endpoint : ConfigObject
 {
+	load_after Zone;
+
 	[config] String host;
 	[config, required] String port {
 		default {{{ return "5665"; }}}
diff --git a/lib/remote/zone.cpp b/lib/remote/zone.cpp
index 594fc6c..55c3c51 100644
--- a/lib/remote/zone.cpp
+++ b/lib/remote/zone.cpp
@@ -37,6 +37,14 @@ void Zone::OnAllConfigLoaded(void)
 	Zone::Ptr zone = m_Parent;
 	int levels = 0;
 
+	Array::Ptr endpoints = GetEndpointsRaw();
+
+	if (endpoints) {
+		BOOST_FOREACH(const String& endpoint, endpoints) {
+			Endpoint::GetByName(endpoint)->SetCachedZone(this);
+		}
+	}
+
 	while (zone) {
 		m_AllParents.push_back(zone);
 



More information about the icinga-checkins mailing list