diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index fa406014d..8a97c8143 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -4,6 +4,7 @@ #include "icingadb/redisconnection.hpp" #include "base/configtype.hpp" #include "base/configobject.hpp" +#include "base/defer.hpp" #include "base/json.hpp" #include "base/logger.hpp" #include "base/serializer.hpp" @@ -130,6 +131,14 @@ void IcingaDB::UpdateAllConfigObjects() types.emplace_back(ctype, lcType); } + m_Rcon->SuppressQueryKind(Prio::CheckResult); + m_Rcon->SuppressQueryKind(Prio::State); + + Defer unSuppress ([this]() { + m_Rcon->UnsuppressQueryKind(Prio::State); + m_Rcon->UnsuppressQueryKind(Prio::CheckResult); + }); + m_Rcon->FireAndForgetQuery({"EVAL", l_LuaResetDump, "1", "icinga:dump"}, Prio::Config); const std::vector globalKeys = { diff --git a/lib/icingadb/icingadb.cpp b/lib/icingadb/icingadb.cpp index 25170b772..96ddcb3fb 100644 --- a/lib/icingadb/icingadb.cpp +++ b/lib/icingadb/icingadb.cpp @@ -84,6 +84,8 @@ void IcingaDB::Start(bool runtimeCreated) boost::thread thread(&IcingaDB::HandleEvents, this); thread.detach(); + m_Rcon->SuppressQueryKind(Prio::CheckResult); + m_Rcon->SuppressQueryKind(Prio::State); } void IcingaDB::ExceptionHandler(boost::exception_ptr exp) diff --git a/lib/icingadb/redisconnection.cpp b/lib/icingadb/redisconnection.cpp index c51e891a8..6f9604b82 100644 --- a/lib/icingadb/redisconnection.cpp +++ b/lib/icingadb/redisconnection.cpp @@ -179,6 +179,29 @@ RedisConnection::Replies RedisConnection::GetResultsOfQueries(RedisConnection::Q return future.get(); } +/** + * Mark kind as kind of queries not to actually send yet + * + * @param kind Query kind + */ +void RedisConnection::SuppressQueryKind(RedisConnection::QueryPriority kind) +{ + asio::post(m_Strand, [this, kind]() { m_SuppressedQueryKinds.emplace(kind); }); +} + +/** + * Unmark kind as kind of queries not to actually send yet + * + * @param kind Query kind + */ +void RedisConnection::UnsuppressQueryKind(RedisConnection::QueryPriority kind) +{ + asio::post(m_Strand, [this, kind]() { + m_SuppressedQueryKinds.erase(kind); + m_QueuedWrites.Set(); + }); +} + /** * Try to connect to Redis */ @@ -317,7 +340,7 @@ void RedisConnection::WriteLoop(asio::yield_context& yc) WriteFirstOfHighestPrio: for (auto& queue : m_Queues.Writes) { - if (queue.second.empty()) { + if (m_SuppressedQueryKinds.find(queue.first) != m_SuppressedQueryKinds.end() || queue.second.empty()) { continue; } diff --git a/lib/icingadb/redisconnection.hpp b/lib/icingadb/redisconnection.hpp index 3cb5956cf..8f8e5b10c 100644 --- a/lib/icingadb/redisconnection.hpp +++ b/lib/icingadb/redisconnection.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -79,6 +80,9 @@ namespace icinga Reply GetResultOfQuery(Query query, QueryPriority priority); Replies GetResultsOfQueries(Queries queries, QueryPriority priority); + void SuppressQueryKind(QueryPriority kind); + void UnsuppressQueryKind(QueryPriority kind); + private: /** * What to do with the responses to Redis queries. @@ -171,6 +175,9 @@ namespace icinga std::queue FutureResponseActions; } m_Queues; + // Kinds of queries not to actually send yet + std::set m_SuppressedQueryKinds; + // Indicate that there's something to send/receive AsioConditionVariable m_QueuedWrites, m_QueuedReads; };