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:
Alexander Aleksandrovič Klimov 2021-01-20 10:47:46 +01:00 committed by GitHub
commit 5e810f30a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -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.";
}

View File

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

View File

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