mirror of https://github.com/Icinga/icinga2.git
Merge pull request #7721 from Icinga/bugfix/icingadb-pending
IcingaDB: suppress state sync until config sync finished
This commit is contained in:
commit
6575ce920e
|
@ -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<String> globalKeys = {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <map>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
@ -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<FutureResponseAction> FutureResponseActions;
|
||||
} m_Queues;
|
||||
|
||||
// Kinds of queries not to actually send yet
|
||||
std::set<QueryPriority> m_SuppressedQueryKinds;
|
||||
|
||||
// Indicate that there's something to send/receive
|
||||
AsioConditionVariable m_QueuedWrites, m_QueuedReads;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue