Optimize IDO queries.

Refs #5124
This commit is contained in:
Gunnar Beutner 2013-11-22 10:32:53 +01:00
parent b915494157
commit 7a3a8de83c
4 changed files with 48 additions and 50 deletions

View File

@ -51,13 +51,19 @@ void WorkQueue::Enqueue(const WorkCallback& item)
ASSERT(!m_Stopped);
if (boost::this_thread::get_id() != GetThreadId()) {
bool wq_thread = (boost::this_thread::get_id() == GetThreadId());
if (!wq_thread) {
while (m_Items.size() >= m_MaxItems)
m_CV.wait(lock);
}
m_Items.push_back(item);
m_CV.notify_all();
if (wq_thread)
ProcessItems(lock);
else
m_CV.notify_all();
}
void WorkQueue::Join(void)
@ -87,21 +93,9 @@ void WorkQueue::DefaultExceptionCallback(boost::exception_ptr exp)
throw;
}
void WorkQueue::WorkerThreadProc(void)
void WorkQueue::ProcessItems(boost::mutex::scoped_lock& lock)
{
boost::mutex::scoped_lock lock(m_Mutex);
std::ostringstream idbuf;
idbuf << "WQ #" << m_ID;
Utility::SetThreadName(idbuf.str());
for (;;) {
while (m_Items.empty() && !m_Joined)
m_CV.wait(lock);
if (m_Joined)
break;
while (!m_Items.empty()) {
try {
WorkCallback wi = m_Items.front();
m_Items.pop_front();
@ -121,6 +115,25 @@ void WorkQueue::WorkerThreadProc(void)
lock.lock();
}
}
void WorkQueue::WorkerThreadProc(void)
{
boost::mutex::scoped_lock lock(m_Mutex);
std::ostringstream idbuf;
idbuf << "WQ #" << m_ID;
Utility::SetThreadName(idbuf.str());
for (;;) {
while (m_Items.empty() && !m_Joined)
m_CV.wait(lock);
if (m_Joined)
break;
ProcessItems(lock);
}
m_Stopped = true;
m_CV.notify_all();

View File

@ -65,6 +65,7 @@ private:
std::deque<WorkCallback> m_Items;
ExceptionCallback m_ExceptionCallback;
void ProcessItems(boost::mutex::scoped_lock& lock);
void WorkerThreadProc(void);
static void DefaultExceptionCallback(boost::exception_ptr exp);

View File

@ -52,23 +52,15 @@ void HostGroupDbObject::OnConfigUpdate(void)
{
HostGroup::Ptr group = static_pointer_cast<HostGroup>(GetObject());
DbQuery query1;
query1.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
query1.Type = DbQueryDelete;
query1.Category = DbCatConfig;
query1.WhereCriteria = make_shared<Dictionary>();
query1.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
OnQuery(query1);
BOOST_FOREACH(const Host::Ptr& host, group->GetMembers()) {
DbQuery query2;
query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
query2.Type = DbQueryInsert;
query2.Category = DbCatConfig;
query2.Fields = make_shared<Dictionary>();
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
query2.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
query2.Fields->Set("host_object_id", host);
OnQuery(query2);
DbQuery query1;
query1.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
query1.Type = DbQueryInsert;
query1.Category = DbCatConfig;
query1.Fields = make_shared<Dictionary>();
query1.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
query1.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
query1.Fields->Set("host_object_id", host);
OnQuery(query1);
}
}

View File

@ -51,23 +51,15 @@ void ServiceGroupDbObject::OnConfigUpdate(void)
{
ServiceGroup::Ptr group = static_pointer_cast<ServiceGroup>(GetObject());
DbQuery query1;
query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
query1.Type = DbQueryDelete;
query1.Category = DbCatConfig;
query1.WhereCriteria = make_shared<Dictionary>();
query1.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
OnQuery(query1);
BOOST_FOREACH(const Service::Ptr& service, group->GetMembers()) {
DbQuery query2;
query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
query2.Type = DbQueryInsert;
query2.Category = DbCatConfig;
query2.Fields = make_shared<Dictionary>();
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
query2.Fields->Set("service_object_id", service);
OnQuery(query2);
DbQuery query1;
query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
query1.Type = DbQueryInsert;
query1.Category = DbCatConfig;
query1.Fields = make_shared<Dictionary>();
query1.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
query1.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
query1.Fields->Set("service_object_id", service);
OnQuery(query1);
}
}