Use RedisConnection::Quer* type aliases instead of (the equivalent std::vector)

This expresses what kind of vector it is and allows to easily change those types in the future.
This commit is contained in:
Alexander A. Klimov 2025-03-25 17:01:08 +01:00
parent 9abf482708
commit 7958048a72
3 changed files with 29 additions and 29 deletions

View File

@ -271,12 +271,12 @@ void IcingaDB::UpdateAllConfigObjects()
String configObject = m_PrefixConfigObject + lcType;
// Skimmed away attributes and checksums HMSETs' keys and values by Redis key.
std::map<String, std::vector<std::vector<String>>> ourContentRaw {{configCheckSum, {}}, {configObject, {}}};
std::map<String, RedisConnection::Queries> ourContentRaw {{configCheckSum, {}}, {configObject, {}}};
std::mutex ourContentMutex;
upqObjectType.ParallelFor(objectChunks, [&](decltype(objectChunks)::const_reference chunk) {
std::map<String, std::vector<String>> hMSets;
std::vector<String> hostZAdds = {"ZADD", "icinga:nextupdate:host"}, serviceZAdds = {"ZADD", "icinga:nextupdate:service"};
std::map<String, RedisConnection::Query> hMSets;
RedisConnection::Query hostZAdds = {"ZADD", "icinga:nextupdate:host"}, serviceZAdds = {"ZADD", "icinga:nextupdate:service"};
auto skimObjects ([&]() {
std::lock_guard<std::mutex> l (ourContentMutex);
@ -342,7 +342,7 @@ void IcingaDB::UpdateAllConfigObjects()
zAdds->emplace_back(GetObjectIdentifier(checkable));
if (zAdds->size() >= 102u) {
std::vector<String> header (zAdds->begin(), zAdds->begin() + 2u);
RedisConnection::Query header (zAdds->begin(), zAdds->begin() + 2u);
rcon->FireAndForgetQuery(std::move(*zAdds), Prio::CheckResult);
@ -398,7 +398,7 @@ void IcingaDB::UpdateAllConfigObjects()
auto& ourCheckSums (ourContent[configCheckSum]);
auto& ourObjects (ourContent[configObject]);
std::vector<String> setChecksum, setObject, delChecksum, delObject;
RedisConnection::Query setChecksum, setObject, delChecksum, delObject;
auto redisCurrent (redisCheckSums.begin());
auto redisEnd (redisCheckSums.end());
@ -411,12 +411,12 @@ void IcingaDB::UpdateAllConfigObjects()
setChecksum.insert(setChecksum.begin(), {"HMSET", configCheckSum});
setObject.insert(setObject.begin(), {"HMSET", configObject});
std::vector<std::vector<String>> transaction;
RedisConnection::Queries transaction;
transaction.emplace_back(std::vector<String>{"MULTI"});
transaction.emplace_back(RedisConnection::Query{"MULTI"});
transaction.emplace_back(std::move(setChecksum));
transaction.emplace_back(std::move(setObject));
transaction.emplace_back(std::vector<String>{"EXEC"});
transaction.emplace_back(RedisConnection::Query{"EXEC"});
setChecksum.clear();
setObject.clear();
@ -430,12 +430,12 @@ void IcingaDB::UpdateAllConfigObjects()
delChecksum.insert(delChecksum.begin(), {"HDEL", configCheckSum});
delObject.insert(delObject.begin(), {"HDEL", configObject});
std::vector<std::vector<String>> transaction;
RedisConnection::Queries transaction;
transaction.emplace_back(std::vector<String>{"MULTI"});
transaction.emplace_back(RedisConnection::Query{"MULTI"});
transaction.emplace_back(std::move(delChecksum));
transaction.emplace_back(std::move(delObject));
transaction.emplace_back(std::vector<String>{"EXEC"});
transaction.emplace_back(RedisConnection::Query{"EXEC"});
delChecksum.clear();
delObject.clear();
@ -563,7 +563,7 @@ std::vector<std::vector<intrusive_ptr<ConfigObject>>> IcingaDB::ChunkObjects(std
}
void IcingaDB::DeleteKeys(const RedisConnection::Ptr& conn, const std::vector<String>& keys, RedisConnection::QueryPriority priority) {
std::vector<String> query = {"DEL"};
RedisConnection::Query query = {"DEL"};
for (auto& key : keys) {
query.emplace_back(key);
}
@ -635,7 +635,7 @@ static ConfigObject::Ptr GetObjectByName(const String& name)
return ConfigObject::GetObject<ConfigType>(name);
}
void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const String typeName, std::map<String, std::vector<String>>& hMSets,
void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const String typeName, std::map<String, RedisConnection::Query>& hMSets,
std::vector<Dictionary::Ptr>& runtimeUpdates, bool runtimeUpdate)
{
String objectKey = GetObjectIdentifier(object);
@ -1333,7 +1333,7 @@ void IcingaDB::UpdateState(const Checkable::Ptr& checkable, StateUpdate mode)
if (mode & StateUpdate::RuntimeOnly) {
ObjectLock olock(stateAttrs);
std::vector<String> streamadd({
RedisConnection::Query streamadd({
"XADD", "icinga:runtime:state", "MAXLEN", "~", "1000000", "*",
"runtime_type", "upsert",
"redis_key", redisStateKey,
@ -1466,7 +1466,7 @@ void IcingaDB::SendConfigUpdate(const ConfigObject::Ptr& object, bool runtimeUpd
String typeName = GetLowerCaseTypeNameDB(object);
std::map<String, std::vector<String>> hMSets;
std::map<String, RedisConnection::Query> hMSets;
std::vector<Dictionary::Ptr> runtimeUpdates;
CreateConfigUpdate(object, typeName, hMSets, runtimeUpdates, runtimeUpdate);
@ -1806,7 +1806,7 @@ bool IcingaDB::PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& a
* icinga:config:object:downtime) need to be prepended. There is nothing to indicate success or failure.
*/
void
IcingaDB::CreateConfigUpdate(const ConfigObject::Ptr& object, const String typeName, std::map<String, std::vector<String>>& hMSets,
IcingaDB::CreateConfigUpdate(const ConfigObject::Ptr& object, const String typeName, std::map<String, RedisConnection::Query>& hMSets,
std::vector<Dictionary::Ptr>& runtimeUpdates, bool runtimeUpdate)
{
/* TODO: This isn't essentially correct as we don't keep track of config objects ourselves. This would avoid duplicated config updates at startup.
@ -1969,7 +1969,7 @@ void IcingaDB::SendStateChange(const ConfigObject::Ptr& object, const CheckResul
Array::Ptr rawId = new Array({m_EnvironmentId, object->GetName()});
rawId->Add(eventTs);
std::vector<String> xAdd ({
RedisConnection::Query xAdd ({
"XADD", "icinga:history:stream:state", "*",
"id", HashValue(rawId),
"environment_id", m_EnvironmentId,
@ -2053,7 +2053,7 @@ void IcingaDB::SendSentNotification(
auto notificationHistoryId (HashValue(rawId));
std::vector<String> xAdd ({
RedisConnection::Query xAdd ({
"XADD", "icinga:history:stream:notification", "*",
"id", notificationHistoryId,
"environment_id", m_EnvironmentId,
@ -2117,7 +2117,7 @@ void IcingaDB::SendStartedDowntime(const Downtime::Ptr& downtime)
/* Update checkable state as in_downtime may have changed. */
UpdateState(checkable, StateUpdate::Full);
std::vector<String> xAdd ({
RedisConnection::Query xAdd ({
"XADD", "icinga:history:stream:downtime", "*",
"downtime_id", GetObjectIdentifier(downtime),
"environment_id", m_EnvironmentId,
@ -2207,7 +2207,7 @@ void IcingaDB::SendRemovedDowntime(const Downtime::Ptr& downtime)
/* Update checkable state as in_downtime may have changed. */
UpdateState(checkable, StateUpdate::Full);
std::vector<String> xAdd ({
RedisConnection::Query xAdd ({
"XADD", "icinga:history:stream:downtime", "*",
"downtime_id", GetObjectIdentifier(downtime),
"environment_id", m_EnvironmentId,
@ -2289,7 +2289,7 @@ void IcingaDB::SendAddedComment(const Comment::Ptr& comment)
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
std::vector<String> xAdd ({
RedisConnection::Query xAdd ({
"XADD", "icinga:history:stream:comment", "*",
"comment_id", GetObjectIdentifier(comment),
"environment_id", m_EnvironmentId,
@ -2361,7 +2361,7 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
std::vector<String> xAdd ({
RedisConnection::Query xAdd ({
"XADD", "icinga:history:stream:comment", "*",
"comment_id", GetObjectIdentifier(comment),
"environment_id", m_EnvironmentId,
@ -2424,7 +2424,7 @@ void IcingaDB::SendFlappingChange(const Checkable::Ptr& checkable, double change
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
std::vector<String> xAdd ({
RedisConnection::Query xAdd ({
"XADD", "icinga:history:stream:flapping", "*",
"environment_id", m_EnvironmentId,
"host_id", GetObjectIdentifier(host),
@ -2519,7 +2519,7 @@ void IcingaDB::SendAcknowledgementSet(const Checkable::Ptr& checkable, const Str
/* Update checkable state as is_acknowledged may have changed. */
UpdateState(checkable, StateUpdate::Full);
std::vector<String> xAdd ({
RedisConnection::Query xAdd ({
"XADD", "icinga:history:stream:acknowledgement", "*",
"environment_id", m_EnvironmentId,
"host_id", GetObjectIdentifier(host),
@ -2577,7 +2577,7 @@ void IcingaDB::SendAcknowledgementCleared(const Checkable::Ptr& checkable, const
/* Update checkable state as is_acknowledged may have changed. */
UpdateState(checkable, StateUpdate::Full);
std::vector<String> xAdd ({
RedisConnection::Query xAdd ({
"XADD", "icinga:history:stream:acknowledgement", "*",
"environment_id", m_EnvironmentId,
"host_id", GetObjectIdentifier(host),
@ -3327,7 +3327,7 @@ void IcingaDB::DeleteRelationship(const String& id, const String& redisKeyWithou
String redisKey = m_PrefixConfigObject + redisKeyWithoutPrefix;
std::vector<std::vector<String>> queries;
RedisConnection::Queries queries;
if (hasChecksum) {
queries.push_back({"HDEL", m_PrefixConfigCheckSum + redisKeyWithoutPrefix, id});

View File

@ -175,7 +175,7 @@ void IcingaDB::PublishStats()
status->Set("timestamp", TimestampToMilliseconds(Utility::GetTime()));
status->Set("icingadb_environment", m_EnvironmentId);
std::vector<String> query {"XADD", "icinga:stats", "MAXLEN", "1", "*"};
RedisConnection::Query query {"XADD", "icinga:stats", "MAXLEN", "1", "*"};
{
ObjectLock statusLock (status);

View File

@ -112,13 +112,13 @@ private:
std::vector<String> GetTypeDumpSignalKeys(const Type::Ptr& type);
void InsertCheckableDependencies(const Checkable::Ptr& checkable, std::map<String, RedisConnection::Query>& hMSets,
std::vector<Dictionary::Ptr>* runtimeUpdates, const DependencyGroup::Ptr& onlyDependencyGroup = nullptr);
void InsertObjectDependencies(const ConfigObject::Ptr& object, const String typeName, std::map<String, std::vector<String>>& hMSets,
void InsertObjectDependencies(const ConfigObject::Ptr& object, const String typeName, std::map<String, RedisConnection::Query>& hMSets,
std::vector<Dictionary::Ptr>& runtimeUpdates, bool runtimeUpdate);
void UpdateDependenciesState(const Checkable::Ptr& checkable, const DependencyGroup::Ptr& onlyDependencyGroup = nullptr,
std::set<DependencyGroup*>* seenGroups = nullptr) const;
void UpdateState(const Checkable::Ptr& checkable, StateUpdate mode);
void SendConfigUpdate(const ConfigObject::Ptr& object, bool runtimeUpdate);
void CreateConfigUpdate(const ConfigObject::Ptr& object, const String type, std::map<String, std::vector<String>>& hMSets,
void CreateConfigUpdate(const ConfigObject::Ptr& object, const String type, std::map<String, RedisConnection::Query>& hMSets,
std::vector<Dictionary::Ptr>& runtimeUpdates, bool runtimeUpdate);
void SendConfigDelete(const ConfigObject::Ptr& object);
void SendStateChange(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type);