[icinga-checkins] icinga.org: icinga2/master: Bug fixes for the new cache code.

git at icinga.org git at icinga.org
Wed Feb 27 16:04:56 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed Feb 27 16:04:49 2013 +0100

Bug fixes for the new cache code.

---

 components/compat/compatcomponent.cpp |    3 +++
 lib/icinga/host.cpp                   |   15 +++++++++------
 lib/icinga/hostgroup.cpp              |    6 ++++--
 lib/icinga/service-comment.cpp        |    6 ++++--
 lib/icinga/service-downtime.cpp       |    6 ++++--
 lib/icinga/service-notification.cpp   |    6 ++++--
 lib/icinga/service.cpp                |    2 --
 lib/icinga/servicegroup.cpp           |    6 ++++--
 lib/icinga/user.cpp                   |    3 ---
 9 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp
index 2135ce8..c04e590 100644
--- a/components/compat/compatcomponent.cpp
+++ b/components/compat/compatcomponent.cpp
@@ -438,6 +438,9 @@ void CompatComponent::DumpServiceObject(ostream& fp, const Service::Ptr& service
 		short_name = service->GetShortName();
 	}
 
+	if (!host)
+		return;
+
 	{
 		ObjectLock olock(host);
 		host_name = host->GetName();
diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp
index f3dd049..62b9c16 100644
--- a/lib/icinga/host.cpp
+++ b/lib/icinga/host.cpp
@@ -23,7 +23,7 @@ using namespace icinga;
 
 boost::mutex Host::m_ServiceMutex;
 map<String, map<String, weak_ptr<Service> > > Host::m_ServicesCache;
-bool Host::m_ServicesCacheValid = false;
+bool Host::m_ServicesCacheValid = true;
 
 REGISTER_SCRIPTFUNCTION("ValidateServiceDictionary", &Host::ValidateServiceDictionary);
 
@@ -57,6 +57,7 @@ void Host::OnRegistrationCompleted(void)
 {
 	DynamicObject::OnRegistrationCompleted();
 
+	Host::InvalidateServicesCache();
 	Host::UpdateSlaveServices(GetSelf());
 }
 
@@ -75,9 +76,6 @@ Host::Ptr Host::GetByName(const String& name)
 {
 	DynamicObject::Ptr configObject = DynamicObject::GetObject("Host", name);
 
-	if (!configObject)
-		BOOST_THROW_EXCEPTION(invalid_argument("Host '" + name + "' does not exist."));
-
 	return dynamic_pointer_cast<Host>(configObject);
 }
 
@@ -324,10 +322,12 @@ void Host::InvalidateServicesCache(void)
 {
 	{
 		boost::mutex::scoped_lock lock(m_ServiceMutex);
+
+		if (m_ServicesCacheValid)
+			Utility::QueueAsyncCallback(boost::bind(&Host::RefreshServicesCache));
+
 		m_ServicesCacheValid = false;
 	}
-
-	Utility::QueueAsyncCallback(boost::bind(&Host::RefreshServicesCache));
 }
 
 void Host::RefreshServicesCache(void)
@@ -355,6 +355,9 @@ void Host::RefreshServicesCache(void)
 			short_name = service->GetShortName();
 		}
 
+		if (!host)
+			continue;
+
 		String host_name;
 
 		{
diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp
index 1ed671a..ef97c42 100644
--- a/lib/icinga/hostgroup.cpp
+++ b/lib/icinga/hostgroup.cpp
@@ -107,10 +107,12 @@ void HostGroup::InvalidateMembersCache(void)
 {
 	{
 		boost::mutex::scoped_lock lock(m_Mutex);
+
+		if (m_MembersCacheValid)
+			Utility::QueueAsyncCallback(boost::bind(&HostGroup::RefreshMembersCache));
+
 		m_MembersCacheValid = false;
 	}
-
-	Utility::QueueAsyncCallback(boost::bind(&HostGroup::RefreshMembersCache));
 }
 
 void HostGroup::RefreshMembersCache(void)
diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp
index 371d9ad..c3277b2 100644
--- a/lib/icinga/service-comment.cpp
+++ b/lib/icinga/service-comment.cpp
@@ -140,10 +140,12 @@ void Service::InvalidateCommentsCache(void)
 {
 	{
 		boost::mutex::scoped_lock lock(m_CommentMutex);
+
+		if (m_CommentsCacheValid)
+			Utility::QueueAsyncCallback(boost::bind(&Service::RefreshCommentsCache));
+
 		m_CommentsCacheValid = false;
 	}
-
-	Utility::QueueAsyncCallback(boost::bind(&Service::RefreshCommentsCache));
 }
 
 void Service::RefreshCommentsCache(void)
diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp
index 499bc12..95ecfc3 100644
--- a/lib/icinga/service-downtime.cpp
+++ b/lib/icinga/service-downtime.cpp
@@ -217,10 +217,12 @@ void Service::InvalidateDowntimesCache(void)
 {
 	{
 		boost::mutex::scoped_lock lock(m_DowntimeMutex);
+
+		if (m_DowntimesCacheValid)
+			Utility::QueueAsyncCallback(boost::bind(&Service::RefreshDowntimesCache));
+
 		m_DowntimesCacheValid = false;
 	}
-
-	Utility::QueueAsyncCallback(boost::bind(&Service::RefreshDowntimesCache));
 }
 
 void Service::RefreshDowntimesCache(void)
diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp
index 5381ad1..5064106 100644
--- a/lib/icinga/service-notification.cpp
+++ b/lib/icinga/service-notification.cpp
@@ -83,10 +83,12 @@ void Service::InvalidateNotificationsCache(void)
 {
 	{
 		boost::mutex::scoped_lock lock(m_NotificationMutex);
+
+		if (m_NotificationsCacheValid)
+			Utility::QueueAsyncCallback(boost::bind(&Service::RefreshNotificationsCache));
+
 		m_NotificationsCacheValid = false;
 	}
-
-	Utility::QueueAsyncCallback(boost::bind(&Service::RefreshNotificationsCache));
 }
 
 void Service::RefreshNotificationsCache(void)
diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp
index 248cce1..3ba7d67 100644
--- a/lib/icinga/service.cpp
+++ b/lib/icinga/service.cpp
@@ -79,8 +79,6 @@ Service::~Service(void)
 void Service::OnRegistrationCompleted(void)
 {
 	DynamicObject::OnRegistrationCompleted();
-
-	Host::InvalidateServicesCache();
 }
 
 String Service::GetDisplayName(void) const
diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp
index 42e9841..2700ec9 100644
--- a/lib/icinga/servicegroup.cpp
+++ b/lib/icinga/servicegroup.cpp
@@ -107,10 +107,12 @@ void ServiceGroup::InvalidateMembersCache(void)
 {
 	{
 		boost::mutex::scoped_lock lock(m_Mutex);
+
+		if (m_MembersCacheValid)
+			Utility::QueueAsyncCallback(boost::bind(&ServiceGroup::RefreshMembersCache));
+
 		m_MembersCacheValid = false;
 	}
-
-	Utility::QueueAsyncCallback(boost::bind(&ServiceGroup::RefreshMembersCache));
 }
 
 void ServiceGroup::RefreshMembersCache(void)
diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp
index c2c4a40..b1f705a 100644
--- a/lib/icinga/user.cpp
+++ b/lib/icinga/user.cpp
@@ -33,9 +33,6 @@ User::Ptr User::GetByName(const String& name)
 {
 	DynamicObject::Ptr configObject = DynamicObject::GetObject("User", name);
 
-	if (!configObject)
-		BOOST_THROW_EXCEPTION(invalid_argument("User '" + name + "' does not exist."));
-
 	return dynamic_pointer_cast<User>(configObject);
 }
 





More information about the icinga-checkins mailing list