From 6f7b553acde0aae43353aceeef058e409c5d0e05 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 6 Mar 2013 13:01:51 +0100 Subject: [PATCH] Bugfixes for the *:Invalidate*Cache() calls. --- components/checker/checkercomponent.cpp | 10 +++++++--- lib/base/timer.cpp | 11 ++--------- lib/icinga/host.cpp | 9 +++++---- lib/icinga/hostgroup.cpp | 9 ++++++--- lib/icinga/service-comment.cpp | 9 ++++++--- lib/icinga/service-downtime.cpp | 9 ++++++--- lib/icinga/service-notification.cpp | 9 ++++++--- lib/icinga/servicegroup.cpp | 9 ++++++--- lib/icinga/usergroup.cpp | 22 ++++++++++++++++------ lib/icinga/usergroup.h | 3 ++- 10 files changed, 62 insertions(+), 38 deletions(-) diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 6eb395a26..8a9139492 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -109,6 +109,11 @@ void CheckerComponent::CheckThreadProc(void) continue; } + m_IdleServices.erase(service); + m_PendingServices.insert(service); + + lock.unlock(); + { ObjectLock olock(service); service->SetForceNextCheck(false); @@ -116,15 +121,14 @@ void CheckerComponent::CheckThreadProc(void) Logger::Write(LogDebug, "checker", "Executing service check for '" + service->GetName() + "'"); - m_IdleServices.erase(service); - m_PendingServices.insert(service); - try { CheckerComponent::Ptr self = GetSelf(); service->BeginExecuteCheck(boost::bind(&CheckerComponent::CheckCompletedHandler, self, service)); } catch (const exception& ex) { Logger::Write(LogCritical, "checker", "Exception occured while checking service '" + service->GetName() + "': " + diagnostic_information(ex)); } + + lock.lock(); } } diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 67813b736..fc5871ddb 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -173,15 +173,8 @@ void Timer::Reschedule(double next) boost::mutex::scoped_lock lock(m_Mutex); - if (next < 0) { - double now = Utility::GetTime(); - next = m_Next + m_Interval; - - if (next < now) - next = now + m_Interval; - else - next = next; - } + if (next < 0) + next = Utility::GetTime() + m_Interval; m_Next = next; diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 69b762af4..c72f47b1b 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -333,9 +333,9 @@ void Host::InvalidateServicesCache(void) m_ServicesCacheTimer = boost::make_shared(); m_ServicesCacheTimer->SetInterval(0.5); m_ServicesCacheTimer->OnTimerExpired.connect(boost::bind(&Host::RefreshServicesCache)); + m_ServicesCacheTimer->Start(); } - m_ServicesCacheTimer->Start(); m_ServicesCacheNeedsUpdate = true; } } @@ -345,12 +345,13 @@ void Host::RefreshServicesCache(void) { boost::mutex::scoped_lock lock(m_ServiceMutex); - assert(m_ServicesCacheNeedsUpdate); - m_ServicesCacheTimer->Stop(); + if (!m_ServicesCacheNeedsUpdate) + return; + m_ServicesCacheNeedsUpdate = false; } - Logger::Write(LogInformation, "icinga", "Updating services cache."); + Logger::Write(LogInformation, "icinga", "Updating Host services cache."); map > newServicesCache; diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp index a769736a4..fdcc06b22 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -128,9 +128,9 @@ void HostGroup::InvalidateMembersCache(void) m_MembersCacheTimer = boost::make_shared(); m_MembersCacheTimer->SetInterval(0.5); m_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&HostGroup::RefreshMembersCache)); + m_MembersCacheTimer->Start(); } - m_MembersCacheTimer->Start(); m_MembersCacheNeedsUpdate = true; } @@ -142,11 +142,14 @@ void HostGroup::RefreshMembersCache(void) { boost::mutex::scoped_lock lock(m_Mutex); - assert(m_MembersCacheNeedsUpdate); - m_MembersCacheTimer->Stop(); + if (!m_MembersCacheNeedsUpdate) + return; + m_MembersCacheNeedsUpdate = false; } + Logger::Write(LogInformation, "icinga", "Updating HostGroup members cache."); + map > newMembersCache; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) { diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp index 4bc38547f..f956954e7 100644 --- a/lib/icinga/service-comment.cpp +++ b/lib/icinga/service-comment.cpp @@ -184,9 +184,9 @@ void Service::InvalidateCommentsCache(void) m_CommentsCacheTimer = boost::make_shared(); m_CommentsCacheTimer->SetInterval(0.5); m_CommentsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshCommentsCache)); + m_CommentsCacheTimer->Start(); } - m_CommentsCacheTimer->Start(); m_CommentsCacheNeedsUpdate = true; } @@ -198,11 +198,14 @@ void Service::RefreshCommentsCache(void) { boost::mutex::scoped_lock lock(m_CommentMutex); - assert(m_CommentsCacheNeedsUpdate); - m_CommentsCacheTimer->Stop(); + if (!m_CommentsCacheNeedsUpdate) + return; + m_CommentsCacheNeedsUpdate = false; } + Logger::Write(LogInformation, "icinga", "Updating Service comments cache."); + map newLegacyCommentsCache; map newCommentsCache; diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp index de4387cfc..96b580198 100644 --- a/lib/icinga/service-downtime.cpp +++ b/lib/icinga/service-downtime.cpp @@ -258,9 +258,9 @@ void Service::InvalidateDowntimesCache(void) m_DowntimesCacheTimer = boost::make_shared(); m_DowntimesCacheTimer->SetInterval(0.5); m_DowntimesCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshNotificationsCache)); + m_DowntimesCacheTimer->Start(); } - m_DowntimesCacheTimer->Start(); m_DowntimesCacheNeedsUpdate = true; } @@ -272,11 +272,14 @@ void Service::RefreshDowntimesCache(void) { boost::mutex::scoped_lock lock(m_DowntimeMutex); - assert(m_DowntimesCacheNeedsUpdate); - m_DowntimesCacheTimer->Stop(); + if (!m_DowntimesCacheNeedsUpdate) + return; + m_DowntimesCacheNeedsUpdate = false; } + Logger::Write(LogInformation, "icinga", "Updating Service downtimes cache."); + map newLegacyDowntimesCache; map newDowntimesCache; diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index 1c4ff329b..dc55f4e53 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -94,9 +94,9 @@ void Service::InvalidateNotificationsCache(void) m_NotificationsCacheTimer = boost::make_shared(); m_NotificationsCacheTimer->SetInterval(0.5); m_NotificationsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshNotificationsCache)); + m_NotificationsCacheTimer->Start(); } - m_NotificationsCacheTimer->Start(); m_NotificationsCacheNeedsUpdate = true; } @@ -108,11 +108,14 @@ void Service::RefreshNotificationsCache(void) { boost::mutex::scoped_lock lock(m_NotificationMutex); - assert(m_NotificationsCacheNeedsUpdate); - m_NotificationsCacheTimer->Stop(); + if (!m_NotificationsCacheNeedsUpdate) + return; + m_NotificationsCacheNeedsUpdate = false; } + Logger::Write(LogInformation, "icinga", "Updating Service notifications cache."); + map > newNotificationsCache; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Notification")) { diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index 68eae8725..2d52c08f0 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -128,9 +128,9 @@ void ServiceGroup::InvalidateMembersCache(void) m_MembersCacheTimer = boost::make_shared(); m_MembersCacheTimer->SetInterval(0.5); m_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&ServiceGroup::RefreshMembersCache)); + m_MembersCacheTimer->Start(); } - m_MembersCacheTimer->Start(); m_MembersCacheNeedsUpdate = true; } @@ -142,11 +142,14 @@ void ServiceGroup::RefreshMembersCache(void) { boost::mutex::scoped_lock lock(m_Mutex); - assert(m_MembersCacheNeedsUpdate); - m_MembersCacheTimer->Stop(); + if (!m_MembersCacheNeedsUpdate) + return; + m_MembersCacheNeedsUpdate = false; } + Logger::Write(LogInformation, "icinga", "Updating ServiceGroup members cache."); + map > newMembersCache; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) { diff --git a/lib/icinga/usergroup.cpp b/lib/icinga/usergroup.cpp index 857f6a567..15c6f151d 100644 --- a/lib/icinga/usergroup.cpp +++ b/lib/icinga/usergroup.cpp @@ -23,7 +23,8 @@ using namespace icinga; boost::mutex UserGroup::m_Mutex; map > UserGroup::m_MembersCache; -bool UserGroup::m_MembersCacheValid = true; +bool UserGroup::m_MembersCacheNeedsUpdate = false; +Timer::Ptr UserGroup::m_MembersCacheTimer; REGISTER_TYPE(UserGroup); @@ -102,10 +103,17 @@ void UserGroup::InvalidateMembersCache(void) { boost::mutex::scoped_lock lock(m_Mutex); - if (m_MembersCacheValid) - Utility::QueueAsyncCallback(boost::bind(&UserGroup::RefreshMembersCache)); + if (m_MembersCacheNeedsUpdate) + return; /* Someone else has already requested a refresh. */ - m_MembersCacheValid = false; + if (!m_MembersCacheTimer) { + m_MembersCacheTimer = boost::make_shared(); + m_MembersCacheTimer->SetInterval(0.5); + m_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&UserGroup::RefreshMembersCache)); + m_MembersCacheTimer->Start(); + } + + m_MembersCacheNeedsUpdate = true; } /** @@ -116,12 +124,14 @@ void UserGroup::RefreshMembersCache(void) { boost::mutex::scoped_lock lock(m_Mutex); - if (m_MembersCacheValid) + if (!m_MembersCacheNeedsUpdate) return; - m_MembersCacheValid = true; + m_MembersCacheNeedsUpdate = false; } + Logger::Write(LogInformation, "icinga", "Updating UserGroup members cache."); + map > newMembersCache; BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) { diff --git a/lib/icinga/usergroup.h b/lib/icinga/usergroup.h index 986e530a6..962bd77f0 100644 --- a/lib/icinga/usergroup.h +++ b/lib/icinga/usergroup.h @@ -53,7 +53,8 @@ private: static boost::mutex m_Mutex; static map > m_MembersCache; - static bool m_MembersCacheValid; + static bool m_MembersCacheNeedsUpdate; + static Timer::Ptr m_MembersCacheTimer; static void RefreshMembersCache(void); };