diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index c541a7552..4a73eb521 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -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 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."; } diff --git a/lib/icingadb/redisconnection.cpp b/lib/icingadb/redisconnection.cpp index 94db408d5..d48804350 100644 --- a/lib/icingadb/redisconnection.cpp +++ b/lib/icingadb/redisconnection.cpp @@ -179,6 +179,14 @@ RedisConnection::Replies RedisConnection::GetResultsOfQueries(RedisConnection::Q return future.get(); } +void RedisConnection::EnqueueCallback(const std::function& 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); + } } /** diff --git a/lib/icingadb/redisconnection.hpp b/lib/icingadb/redisconnection.hpp index 222e99cb3..77e7eac34 100644 --- a/lib/icingadb/redisconnection.hpp +++ b/lib/icingadb/redisconnection.hpp @@ -79,6 +79,8 @@ namespace icinga Reply GetResultOfQuery(Query query, QueryPriority priority); Replies GetResultsOfQueries(Queries queries, QueryPriority priority); + void EnqueueCallback(const std::function& callback, QueryPriority priority); + void SuppressQueryKind(QueryPriority kind); void UnsuppressQueryKind(QueryPriority kind); @@ -117,6 +119,7 @@ namespace icinga Shared::Ptr FireAndForgetQueries; Shared>>::Ptr GetResultOfQuery; Shared>>::Ptr GetResultsOfQueries; + std::function Callback; }; typedef boost::asio::ip::tcp Tcp;