Bugfixes for the *:Invalidate*Cache() calls.

This commit is contained in:
Gunnar Beutner 2013-03-06 13:01:51 +01:00
parent 70fa21dfbc
commit 6f7b553acd
10 changed files with 62 additions and 38 deletions

View File

@ -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();
}
}

View File

@ -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;

View File

@ -333,9 +333,9 @@ void Host::InvalidateServicesCache(void)
m_ServicesCacheTimer = boost::make_shared<Timer>();
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<String, map<String, Service::WeakPtr> > newServicesCache;

View File

@ -128,9 +128,9 @@ void HostGroup::InvalidateMembersCache(void)
m_MembersCacheTimer = boost::make_shared<Timer>();
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<String, vector<Host::WeakPtr> > newMembersCache;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {

View File

@ -184,9 +184,9 @@ void Service::InvalidateCommentsCache(void)
m_CommentsCacheTimer = boost::make_shared<Timer>();
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<int, String> newLegacyCommentsCache;
map<String, Service::WeakPtr> newCommentsCache;

View File

@ -258,9 +258,9 @@ void Service::InvalidateDowntimesCache(void)
m_DowntimesCacheTimer = boost::make_shared<Timer>();
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<int, String> newLegacyDowntimesCache;
map<String, Service::WeakPtr> newDowntimesCache;

View File

@ -94,9 +94,9 @@ void Service::InvalidateNotificationsCache(void)
m_NotificationsCacheTimer = boost::make_shared<Timer>();
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<String, set<Notification::WeakPtr> > newNotificationsCache;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Notification")) {

View File

@ -128,9 +128,9 @@ void ServiceGroup::InvalidateMembersCache(void)
m_MembersCacheTimer = boost::make_shared<Timer>();
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<String, vector<Service::WeakPtr> > newMembersCache;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {

View File

@ -23,7 +23,8 @@ using namespace icinga;
boost::mutex UserGroup::m_Mutex;
map<String, vector<User::WeakPtr> > 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<Timer>();
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<String, vector<User::WeakPtr> > newMembersCache;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) {

View File

@ -53,7 +53,8 @@ private:
static boost::mutex m_Mutex;
static map<String, vector<User::WeakPtr> > m_MembersCache;
static bool m_MembersCacheValid;
static bool m_MembersCacheNeedsUpdate;
static Timer::Ptr m_MembersCacheTimer;
static void RefreshMembersCache(void);
};