mirror of https://github.com/Icinga/icinga2.git
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:
commit
6fa44c8e4e
|
@ -68,30 +68,39 @@ 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);
|
||||
m_StatsTimer->OnTimerExpired.connect([this](const Timer * const&) { PublishStatsTimerHandler(); });
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue