mirror of https://github.com/Icinga/icinga2.git
Merge pull request #8605 from Icinga/bugfix/icingadb-initial-sync-log
IcingaDB: wait for queries to be executed in inital sync
This commit is contained in:
commit
5e810f30a7
|
@ -309,6 +309,11 @@ void IcingaDB::UpdateAllConfigObjects()
|
|||
|
||||
m_Rcon->FireAndForgetQuery({"XADD", "icinga:dump", "*", "type", "*", "state", "done"}, Prio::Config);
|
||||
|
||||
// enqueue a callback that will notify us once all previous queries were executed and wait for this event
|
||||
std::promise<void> p;
|
||||
m_Rcon->EnqueueCallback([&p](boost::asio::yield_context& yc) { p.set_value(); }, Prio::Config);
|
||||
p.get_future().wait();
|
||||
|
||||
Log(LogInformation, "IcingaDB")
|
||||
<< "Initial config/status dump finished in " << Utility::GetTime() - startTime << " seconds.";
|
||||
}
|
||||
|
|
|
@ -179,6 +179,14 @@ RedisConnection::Replies RedisConnection::GetResultsOfQueries(RedisConnection::Q
|
|||
return future.get();
|
||||
}
|
||||
|
||||
void RedisConnection::EnqueueCallback(const std::function<void(boost::asio::yield_context&)>& callback, RedisConnection::QueryPriority priority)
|
||||
{
|
||||
asio::post(m_Strand, [this, callback, priority]() {
|
||||
m_Queues.Writes[priority].emplace(WriteQueueItem{nullptr, nullptr, nullptr, nullptr, callback});
|
||||
m_QueuedWrites.Set();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark kind as kind of queries not to actually send yet
|
||||
*
|
||||
|
@ -471,6 +479,10 @@ void RedisConnection::WriteItem(boost::asio::yield_context& yc, RedisConnection:
|
|||
|
||||
m_QueuedReads.Set();
|
||||
}
|
||||
|
||||
if (next.Callback) {
|
||||
next.Callback(yc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,6 +79,8 @@ namespace icinga
|
|||
Reply GetResultOfQuery(Query query, QueryPriority priority);
|
||||
Replies GetResultsOfQueries(Queries queries, QueryPriority priority);
|
||||
|
||||
void EnqueueCallback(const std::function<void(boost::asio::yield_context&)>& callback, QueryPriority priority);
|
||||
|
||||
void SuppressQueryKind(QueryPriority kind);
|
||||
void UnsuppressQueryKind(QueryPriority kind);
|
||||
|
||||
|
@ -117,6 +119,7 @@ namespace icinga
|
|||
Shared<Queries>::Ptr FireAndForgetQueries;
|
||||
Shared<std::pair<Query, std::promise<Reply>>>::Ptr GetResultOfQuery;
|
||||
Shared<std::pair<Queries, std::promise<Replies>>>::Ptr GetResultsOfQueries;
|
||||
std::function<void(boost::asio::yield_context&)> Callback;
|
||||
};
|
||||
|
||||
typedef boost::asio::ip::tcp Tcp;
|
||||
|
|
Loading…
Reference in New Issue