Merge pull request #8941 from Icinga/bugfix/icingadb-init-all-connections-before-sync

Icinga DB: ensure all connections are ready on first use
This commit is contained in:
Julian Brost 2021-07-29 17:33:29 +02:00 committed by GitHub
commit 6fa44c8e4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 15 deletions

View File

@ -68,29 +68,38 @@ void IcingaDB::Start(bool runtimeCreated)
GetEnableTls(), GetInsecureNoverify(), GetCertPath(), GetKeyPath(), GetCaPath(), GetCrlPath(),
GetTlsProtocolmin(), GetCipherList(), GetConnectTimeout(), GetDebugInfo());
auto connectedCallback ([this](boost::asio::yield_context& yc) {
m_WorkQueue.Enqueue([this]() { OnConnectedHandler(); });
});
m_Rcon->SetConnectedCallback([this, connectedCallback](boost::asio::yield_context& yc) {
for (auto& kv : m_Rcons) {
kv.second->Start();
}
m_Rcon->SetConnectedCallback(connectedCallback);
connectedCallback(yc);
});
m_Rcon->Start();
for (const Type::Ptr& type : GetTypes()) {
auto ctype (dynamic_cast<ConfigType*>(type.get()));
if (!ctype)
continue;
m_Rcons[ctype] = new RedisConnection(GetHost(), GetPort(), GetPath(), GetPassword(), GetDbIndex(),
RedisConnection::Ptr con = new RedisConnection(GetHost(), GetPort(), GetPath(), GetPassword(), GetDbIndex(),
GetEnableTls(), GetInsecureNoverify(), GetCertPath(), GetKeyPath(), GetCaPath(), GetCrlPath(),
GetTlsProtocolmin(), GetCipherList(), GetConnectTimeout(), GetDebugInfo(), m_Rcon);
con->SetConnectedCallback([this, con](boost::asio::yield_context& yc) {
con->SetConnectedCallback(nullptr);
size_t pending = --m_PendingRcons;
Log(LogDebug, "IcingaDB") << pending << " pending child connections remaining";
if (pending == 0) {
m_WorkQueue.Enqueue([this]() { OnConnectedHandler(); });
}
});
m_Rcons[ctype] = std::move(con);
}
m_PendingRcons = m_Rcons.size();
m_Rcon->SetConnectedCallback([this](boost::asio::yield_context& yc) {
m_Rcon->SetConnectedCallback(nullptr);
for (auto& kv : m_Rcons) {
kv.second->Start();
}
});
m_Rcon->Start();
m_StatsTimer = new Timer();
m_StatsTimer->SetInterval(1);

View File

@ -13,6 +13,7 @@
#include "icinga/downtime.hpp"
#include "remote/messageorigin.hpp"
#include <boost/thread/once.hpp>
#include <atomic>
#include <memory>
#include <mutex>
#include <set>
@ -170,6 +171,7 @@ private:
RedisConnection::Ptr m_Rcon;
std::unordered_map<ConfigType*, RedisConnection::Ptr> m_Rcons;
std::atomic_size_t m_PendingRcons;
struct {
DumpedGlobals CustomVar, ActionUrl, NotesUrl, IconImage;