Fix deadlock when querying comments or downtimes through livestatus

fixes #5332
This commit is contained in:
Johannes Meyer 2013-12-16 14:14:01 +01:00
parent e8cf349451
commit 4a6fddadb8
2 changed files with 29 additions and 24 deletions

View File

@ -63,21 +63,23 @@ void CommentsTable::FetchRows(const AddRowFunction& addRowFn)
ObjectLock olock(comments); ObjectLock olock(comments);
String id; String id;
BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), comments) { Comment::Ptr comment;
BOOST_FOREACH(boost::tie(id, comment), comments) {
if (Service::GetOwnerByCommentID(id) == service) if (Service::GetOwnerByCommentID(id) == service)
addRowFn(id); addRowFn(comment);
} }
} }
} }
Object::Ptr CommentsTable::ServiceAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor) Object::Ptr CommentsTable::ServiceAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor)
{ {
return Service::GetOwnerByCommentID(row); Comment::Ptr comment = static_cast<Comment::Ptr>(row);
return Service::GetOwnerByCommentID(comment->GetId());
} }
Value CommentsTable::AuthorAccessor(const Value& row) Value CommentsTable::AuthorAccessor(const Value& row)
{ {
Comment::Ptr comment = Service::GetCommentByID(row); Comment::Ptr comment = static_cast<Comment::Ptr>(row);
if (!comment) if (!comment)
return Empty; return Empty;
@ -87,7 +89,7 @@ Value CommentsTable::AuthorAccessor(const Value& row)
Value CommentsTable::CommentAccessor(const Value& row) Value CommentsTable::CommentAccessor(const Value& row)
{ {
Comment::Ptr comment = Service::GetCommentByID(row); Comment::Ptr comment = static_cast<Comment::Ptr>(row);
if (!comment) if (!comment)
return Empty; return Empty;
@ -97,7 +99,7 @@ Value CommentsTable::CommentAccessor(const Value& row)
Value CommentsTable::IdAccessor(const Value& row) Value CommentsTable::IdAccessor(const Value& row)
{ {
Comment::Ptr comment = Service::GetCommentByID(row); Comment::Ptr comment = static_cast<Comment::Ptr>(row);
if (!comment) if (!comment)
return Empty; return Empty;
@ -107,7 +109,7 @@ Value CommentsTable::IdAccessor(const Value& row)
Value CommentsTable::EntryTimeAccessor(const Value& row) Value CommentsTable::EntryTimeAccessor(const Value& row)
{ {
Comment::Ptr comment = Service::GetCommentByID(row); Comment::Ptr comment = static_cast<Comment::Ptr>(row);
if (!comment) if (!comment)
return Empty; return Empty;
@ -137,7 +139,7 @@ Value CommentsTable::IsServiceAccessor(const Value& row)
Value CommentsTable::EntryTypeAccessor(const Value& row) Value CommentsTable::EntryTypeAccessor(const Value& row)
{ {
Comment::Ptr comment = Service::GetCommentByID(row); Comment::Ptr comment = static_cast<Comment::Ptr>(row);
if (!comment) if (!comment)
return Empty; return Empty;
@ -147,7 +149,7 @@ Value CommentsTable::EntryTypeAccessor(const Value& row)
Value CommentsTable::ExpiresAccessor(const Value& row) Value CommentsTable::ExpiresAccessor(const Value& row)
{ {
Comment::Ptr comment = Service::GetCommentByID(row); Comment::Ptr comment = static_cast<Comment::Ptr>(row);
if (!comment) if (!comment)
return Empty; return Empty;
@ -157,7 +159,7 @@ Value CommentsTable::ExpiresAccessor(const Value& row)
Value CommentsTable::ExpireTimeAccessor(const Value& row) Value CommentsTable::ExpireTimeAccessor(const Value& row)
{ {
Comment::Ptr comment = Service::GetCommentByID(row); Comment::Ptr comment = static_cast<Comment::Ptr>(row);
if (!comment) if (!comment)
return Empty; return Empty;

View File

@ -63,91 +63,94 @@ void DowntimesTable::FetchRows(const AddRowFunction& addRowFn)
ObjectLock olock(downtimes); ObjectLock olock(downtimes);
String id; String id;
BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), downtimes) { Downtime::Ptr downtime;
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
if (Service::GetOwnerByDowntimeID(id) == service) if (Service::GetOwnerByDowntimeID(id) == service)
addRowFn(id); addRowFn(downtime);
} }
} }
} }
Object::Ptr DowntimesTable::ServiceAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor) Object::Ptr DowntimesTable::ServiceAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor)
{ {
return Service::GetOwnerByDowntimeID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
return Service::GetOwnerByDowntimeID(downtime->GetId());
} }
Value DowntimesTable::AuthorAccessor(const Value& row) Value DowntimesTable::AuthorAccessor(const Value& row)
{ {
Downtime::Ptr downtime = Service::GetDowntimeByID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
return downtime->GetAuthor(); return downtime->GetAuthor();
} }
Value DowntimesTable::CommentAccessor(const Value& row) Value DowntimesTable::CommentAccessor(const Value& row)
{ {
Downtime::Ptr downtime = Service::GetDowntimeByID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
return downtime->GetComment(); return downtime->GetComment();
} }
Value DowntimesTable::IdAccessor(const Value& row) Value DowntimesTable::IdAccessor(const Value& row)
{ {
Downtime::Ptr downtime = Service::GetDowntimeByID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
return downtime->GetLegacyId(); return downtime->GetLegacyId();
} }
Value DowntimesTable::EntryTimeAccessor(const Value& row) Value DowntimesTable::EntryTimeAccessor(const Value& row)
{ {
Downtime::Ptr downtime = Service::GetDowntimeByID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
return static_cast<int>(downtime->GetEntryTime()); return static_cast<int>(downtime->GetEntryTime());
} }
Value DowntimesTable::TypeAccessor(const Value& row) Value DowntimesTable::TypeAccessor(const Value& row)
{ {
Downtime::Ptr downtime = Service::GetDowntimeByID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
// 1 .. active, 0 .. pending // 1 .. active, 0 .. pending
return (downtime->IsActive() ? 1 : 0); return (downtime->IsActive() ? 1 : 0);
} }
Value DowntimesTable::IsServiceAccessor(const Value& row) Value DowntimesTable::IsServiceAccessor(const Value& row)
{ {
Service::Ptr svc = Service::GetOwnerByDowntimeID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
Service::Ptr svc = Service::GetOwnerByDowntimeID(downtime->GetId());
return (svc->IsHostCheck() ? 0 : 1); return (svc->IsHostCheck() ? 0 : 1);
} }
Value DowntimesTable::StartTimeAccessor(const Value& row) Value DowntimesTable::StartTimeAccessor(const Value& row)
{ {
Downtime::Ptr downtime = Service::GetDowntimeByID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
return static_cast<int>(downtime->GetStartTime()); return static_cast<int>(downtime->GetStartTime());
} }
Value DowntimesTable::EndTimeAccessor(const Value& row) Value DowntimesTable::EndTimeAccessor(const Value& row)
{ {
Downtime::Ptr downtime = Service::GetDowntimeByID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
return static_cast<int>(downtime->GetEndTime()); return static_cast<int>(downtime->GetEndTime());
} }
Value DowntimesTable::FixedAccessor(const Value& row) Value DowntimesTable::FixedAccessor(const Value& row)
{ {
Downtime::Ptr downtime = Service::GetDowntimeByID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
return downtime->GetFixed(); return downtime->GetFixed();
} }
Value DowntimesTable::DurationAccessor(const Value& row) Value DowntimesTable::DurationAccessor(const Value& row)
{ {
Downtime::Ptr downtime = Service::GetDowntimeByID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
return downtime->GetDuration(); return downtime->GetDuration();
} }
Value DowntimesTable::TriggeredByAccessor(const Value& row) Value DowntimesTable::TriggeredByAccessor(const Value& row)
{ {
Downtime::Ptr downtime = Service::GetDowntimeByID(row); Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
return downtime->GetTriggeredBy(); return downtime->GetTriggeredBy();
} }