Skip to content

Commit

Permalink
Merge pull request #8915 from Icinga/bugfix/icingadb-prio-state
Browse files Browse the repository at this point in the history
Icinga DB: priorize state > config
  • Loading branch information
Al2Klimov authored Jul 27, 2021
2 parents dcb5fcc + ae9b371 commit 2d75bbd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
16 changes: 8 additions & 8 deletions lib/icingadb/icingadb-objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ void IcingaDB::UpdateAllConfigObjects()
std::vector<Type::Ptr> types = GetTypes();

m_Rcon->SuppressQueryKind(Prio::CheckResult);
m_Rcon->SuppressQueryKind(Prio::State);
m_Rcon->SuppressQueryKind(Prio::RuntimeStateSync);

Defer unSuppress ([this]() {
m_Rcon->UnsuppressQueryKind(Prio::State);
m_Rcon->UnsuppressQueryKind(Prio::RuntimeStateSync);
m_Rcon->UnsuppressQueryKind(Prio::CheckResult);
});

Expand Down Expand Up @@ -1078,8 +1078,8 @@ void IcingaDB::UpdateState(const Checkable::Ptr& checkable)

Dictionary::Ptr stateAttrs = SerializeState(checkable);

m_Rcon->FireAndForgetQuery({"HSET", m_PrefixConfigObject + objectType + ":state", objectKey, JsonEncode(stateAttrs)}, Prio::State);
m_Rcon->FireAndForgetQuery({"HSET", m_PrefixConfigCheckSum + objectType + ":state", objectKey, JsonEncode(new Dictionary({{"checksum", HashValue(stateAttrs)}}))}, Prio::State);
m_Rcon->FireAndForgetQuery({"HSET", m_PrefixConfigObject + objectType + ":state", objectKey, JsonEncode(stateAttrs)}, Prio::RuntimeStateSync);
m_Rcon->FireAndForgetQuery({"HSET", m_PrefixConfigCheckSum + objectType + ":state", objectKey, JsonEncode(new Dictionary({{"checksum", HashValue(stateAttrs)}}))}, Prio::RuntimeStateSync);

}

Expand All @@ -1101,8 +1101,8 @@ void IcingaDB::SendConfigUpdate(const ConfigObject::Ptr& object, bool runtimeUpd
Dictionary::Ptr state = SerializeState(checkable);
String checksum = HashValue(state);

m_Rcon->FireAndForgetQuery({"HSET", m_PrefixConfigObject + typeName + ":state", objectKey, JsonEncode(state)}, Prio::State);
m_Rcon->FireAndForgetQuery({"HSET", m_PrefixConfigCheckSum + typeName + ":state", objectKey, JsonEncode(new Dictionary({{"checksum", checksum}}))}, Prio::State);
m_Rcon->FireAndForgetQuery({"HSET", m_PrefixConfigObject + typeName + ":state", objectKey, JsonEncode(state)}, Prio::RuntimeStateSync);
m_Rcon->FireAndForgetQuery({"HSET", m_PrefixConfigCheckSum + typeName + ":state", objectKey, JsonEncode(new Dictionary({{"checksum", checksum}}))}, Prio::RuntimeStateSync);

if (runtimeUpdate) {
state->Set("checksum", checksum);
Expand Down Expand Up @@ -1538,14 +1538,14 @@ void IcingaDB::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResu
objectAttrs->Set("runtime_type", "upsert");
objectAttrs->Set("checksum", HashValue(objectAttrs));

std::vector<String> streamadd({"XADD", "icinga:runtime", "MAXLEN", "~", "1000000", "*"});
std::vector<String> streamadd({"XADD", "icinga:runtime:state", "MAXLEN", "~", "1000000", "*"});
ObjectLock olock(objectAttrs);
for (const Dictionary::Pair& kv : objectAttrs) {
streamadd.emplace_back(kv.first);
streamadd.emplace_back(IcingaToStreamValue(kv.second));
}

m_Rcon->FireAndForgetQuery(std::move(streamadd), Prio::State);
m_Rcon->FireAndForgetQuery(std::move(streamadd), Prio::RuntimeStateStream);

int hard_state;
if (!cr) {
Expand Down
2 changes: 1 addition & 1 deletion lib/icingadb/icingadb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void IcingaDB::Start(bool runtimeCreated)
m_WorkQueue.SetName("IcingaDB");

m_Rcon->SuppressQueryKind(Prio::CheckResult);
m_Rcon->SuppressQueryKind(Prio::State);
m_Rcon->SuppressQueryKind(Prio::RuntimeStateSync);
}

void IcingaDB::ExceptionHandler(boost::exception_ptr exp)
Expand Down
5 changes: 3 additions & 2 deletions lib/icingadb/redisconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ namespace icinga
enum class QueryPriority : unsigned char
{
Heartbeat,
Config,
State,
RuntimeStateStream, // runtime state updates, doesn't affect initially synced states
Config, // includes initially synced states
RuntimeStateSync, // updates initially synced states at runtime, in parallel to config dump, therefore must be < Config
History,
CheckResult,
SyncConnection = 255
Expand Down

0 comments on commit 2d75bbd

Please sign in to comment.