]> granicus.if.org Git - icinga2/commitdiff
Bug fixes for the new cache code.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 27 Feb 2013 15:04:49 +0000 (16:04 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 27 Feb 2013 15:04:49 +0000 (16:04 +0100)
components/compat/compatcomponent.cpp
lib/icinga/host.cpp
lib/icinga/hostgroup.cpp
lib/icinga/service-comment.cpp
lib/icinga/service-downtime.cpp
lib/icinga/service-notification.cpp
lib/icinga/service.cpp
lib/icinga/servicegroup.cpp
lib/icinga/user.cpp

index 2135ce85687b4a6b37a2d2885eae565b8819515e..c04e59070cc4b38024e8a4c0f0df6386a18bb813 100644 (file)
@@ -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();
index f3dd049b515660a6b04157bb6e517be2b91de023..62b9c1673040e098d50da93aa466784000d29a6f 100644 (file)
@@ -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;
 
                {
index 1ed671a05ee4203a56a574d41531e1c1e0747c0c..ef97c42ff3452a885b2696415b6a5207981e497d 100644 (file)
@@ -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)
index 371d9ad90f71759a7ce687f344a5105486ed2a1e..c3277b2f21b456011f3add683ccca05eae0804c3 100644 (file)
@@ -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)
index 499bc1231c67e13e18567dd0d726d060b39fabc0..95ecfc3a74ea87bf0b091ce8c90846c19701d5cd 100644 (file)
@@ -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)
index 5381ad1736932fc5fbf6d7a8d15c757bc4607a52..50641069422d9060743b207f0530483cc0035fdb 100644 (file)
@@ -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)
index 248cce1395bc83c72f6c50499e885c2e7e7d53d2..3ba7d670d19d0502f9fefd6e43c7503fad51550a 100644 (file)
@@ -79,8 +79,6 @@ Service::~Service(void)
 void Service::OnRegistrationCompleted(void)
 {
        DynamicObject::OnRegistrationCompleted();
-
-       Host::InvalidateServicesCache();
 }
 
 String Service::GetDisplayName(void) const
index 42e98411242f71aca1085f1329ed3b404d7bf6ab..2700ec981a0741392e35e13375faf53330b3f51d 100644 (file)
@@ -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)
index c2c4a40e44092da6899fbad862f3698b62d03047..b1f705a38f503a8bd1d977fa3fcfbf71aa3e9ca7 100644 (file)
@@ -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);
 }