From e98fd3e3eba629b9b17cc4658b59eeea666d4b59 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 27 Feb 2013 16:04:49 +0100 Subject: [PATCH] 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 2135ce856..c04e59070 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 f3dd049b5..62b9c1673 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -23,7 +23,7 @@ using namespace icinga; boost::mutex Host::m_ServiceMutex; map > > 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(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 1ed671a05..ef97c42ff 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 371d9ad90..c3277b2f2 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 499bc1231..95ecfc3a7 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 5381ad173..506410694 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 248cce139..3ba7d670d 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 42e984112..2700ec981 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 c2c4a40e4..b1f705a38 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(configObject); } -- 2.40.0