Skip to content

Commit 70ca88a

Browse files
committed
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.
1 parent 5e902fe commit 70ca88a

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

lib/icingadb/icingadb-objects.cpp

+31-31
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,17 @@ void IcingaDB::UpdateAllConfigObjects()
254254
String configObject = m_PrefixConfigObject + lcType;
255255

256256
// Skimmed away attributes and checksums HMSETs' keys and values by Redis key.
257-
std::map<String, std::vector<std::vector<String>>> ourContentRaw {{configCheckSum, {}}, {configObject, {}}};
257+
std::map<String, RedisConnection::Queries> ourContentRaw {{configCheckSum, {}}, {configObject, {}}};
258258
std::mutex ourContentMutex;
259259

260260
upqObjectType.ParallelFor(objectChunks, [&](decltype(objectChunks)::const_reference chunk) {
261-
std::map<String, std::vector<String>> hMSets;
261+
std::map<String, RedisConnection::Query> hMSets;
262262
// Two values are appended per object: Object ID (Hash encoded) and Object State (IcingaDB::SerializeState() -> JSON encoded)
263-
std::vector<String> states = {"HMSET", m_PrefixConfigObject + lcType + ":state"};
263+
RedisConnection::Query states = {"HMSET", m_PrefixConfigObject + lcType + ":state"};
264264
// Two values are appended per object: Object ID (Hash encoded) and State Checksum ({ "checksum": checksum } -> JSON encoded)
265-
std::vector<String> statesChksms = {"HMSET", m_PrefixConfigCheckSum + lcType + ":state"};
266-
std::vector<std::vector<String> > transaction = {{"MULTI"}};
267-
std::vector<String> hostZAdds = {"ZADD", "icinga:nextupdate:host"}, serviceZAdds = {"ZADD", "icinga:nextupdate:service"};
265+
RedisConnection::Query statesChksms = {"HMSET", m_PrefixConfigCheckSum + lcType + ":state"};
266+
RedisConnection::Queries transaction = {{"MULTI"}};
267+
RedisConnection::Query hostZAdds = {"ZADD", "icinga:nextupdate:host"}, serviceZAdds = {"ZADD", "icinga:nextupdate:service"};
268268

269269
auto skimObjects ([&]() {
270270
std::lock_guard<std::mutex> l (ourContentMutex);
@@ -346,7 +346,7 @@ void IcingaDB::UpdateAllConfigObjects()
346346
zAdds->emplace_back(GetObjectIdentifier(checkable));
347347

348348
if (zAdds->size() >= 102u) {
349-
std::vector<String> header (zAdds->begin(), zAdds->begin() + 2u);
349+
RedisConnection::Query header (zAdds->begin(), zAdds->begin() + 2u);
350350

351351
rcon->FireAndForgetQuery(std::move(*zAdds), Prio::CheckResult);
352352

@@ -417,7 +417,7 @@ void IcingaDB::UpdateAllConfigObjects()
417417

418418
auto& ourCheckSums (ourContent[configCheckSum]);
419419
auto& ourObjects (ourContent[configObject]);
420-
std::vector<String> setChecksum, setObject, delChecksum, delObject;
420+
RedisConnection::Query setChecksum, setObject, delChecksum, delObject;
421421

422422
auto redisCurrent (redisCheckSums.begin());
423423
auto redisEnd (redisCheckSums.end());
@@ -430,12 +430,12 @@ void IcingaDB::UpdateAllConfigObjects()
430430
setChecksum.insert(setChecksum.begin(), {"HMSET", configCheckSum});
431431
setObject.insert(setObject.begin(), {"HMSET", configObject});
432432

433-
std::vector<std::vector<String>> transaction;
433+
RedisConnection::Queries transaction;
434434

435-
transaction.emplace_back(std::vector<String>{"MULTI"});
435+
transaction.emplace_back(RedisConnection::Query{"MULTI"});
436436
transaction.emplace_back(std::move(setChecksum));
437437
transaction.emplace_back(std::move(setObject));
438-
transaction.emplace_back(std::vector<String>{"EXEC"});
438+
transaction.emplace_back(RedisConnection::Query{"EXEC"});
439439

440440
setChecksum.clear();
441441
setObject.clear();
@@ -449,12 +449,12 @@ void IcingaDB::UpdateAllConfigObjects()
449449
delChecksum.insert(delChecksum.begin(), {"HDEL", configCheckSum});
450450
delObject.insert(delObject.begin(), {"HDEL", configObject});
451451

452-
std::vector<std::vector<String>> transaction;
452+
RedisConnection::Queries transaction;
453453

454-
transaction.emplace_back(std::vector<String>{"MULTI"});
454+
transaction.emplace_back(RedisConnection::Query{"MULTI"});
455455
transaction.emplace_back(std::move(delChecksum));
456456
transaction.emplace_back(std::move(delObject));
457-
transaction.emplace_back(std::vector<String>{"EXEC"});
457+
transaction.emplace_back(RedisConnection::Query{"EXEC"});
458458

459459
delChecksum.clear();
460460
delObject.clear();
@@ -582,7 +582,7 @@ std::vector<std::vector<intrusive_ptr<ConfigObject>>> IcingaDB::ChunkObjects(std
582582
}
583583

584584
void IcingaDB::DeleteKeys(const RedisConnection::Ptr& conn, const std::vector<String>& keys, RedisConnection::QueryPriority priority) {
585-
std::vector<String> query = {"DEL"};
585+
RedisConnection::Query query = {"DEL"};
586586
for (auto& key : keys) {
587587
query.emplace_back(key);
588588
}
@@ -654,7 +654,7 @@ static ConfigObject::Ptr GetObjectByName(const String& name)
654654
return ConfigObject::GetObject<ConfigType>(name);
655655
}
656656

657-
void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const String typeName, std::map<String, std::vector<String>>& hMSets,
657+
void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const String typeName, std::map<String, RedisConnection::Query>& hMSets,
658658
std::vector<Dictionary::Ptr>& runtimeUpdates, bool runtimeUpdate)
659659
{
660660
String objectKey = GetObjectIdentifier(object);
@@ -1161,7 +1161,7 @@ void IcingaDB::UpdateState(const Checkable::Ptr& checkable, StateUpdate mode)
11611161
if (mode & StateUpdate::RuntimeOnly) {
11621162
ObjectLock olock(stateAttrs);
11631163

1164-
std::vector<String> streamadd({
1164+
RedisConnection::Query streamadd({
11651165
"XADD", "icinga:runtime:state", "MAXLEN", "~", "1000000", "*",
11661166
"runtime_type", "upsert",
11671167
"redis_key", redisStateKey,
@@ -1185,7 +1185,7 @@ void IcingaDB::SendConfigUpdate(const ConfigObject::Ptr& object, bool runtimeUpd
11851185

11861186
String typeName = GetLowerCaseTypeNameDB(object);
11871187

1188-
std::map<String, std::vector<String>> hMSets;
1188+
std::map<String, RedisConnection::Query> hMSets;
11891189
std::vector<Dictionary::Ptr> runtimeUpdates;
11901190

11911191
CreateConfigUpdate(object, typeName, hMSets, runtimeUpdates, runtimeUpdate);
@@ -1194,7 +1194,7 @@ void IcingaDB::SendConfigUpdate(const ConfigObject::Ptr& object, bool runtimeUpd
11941194
UpdateState(checkable, runtimeUpdate ? StateUpdate::Full : StateUpdate::Volatile);
11951195
}
11961196

1197-
std::vector<std::vector<String> > transaction = {{"MULTI"}};
1197+
RedisConnection::Queries transaction = {{"MULTI"}};
11981198

11991199
for (auto& kv : hMSets) {
12001200
if (!kv.second.empty()) {
@@ -1204,7 +1204,7 @@ void IcingaDB::SendConfigUpdate(const ConfigObject::Ptr& object, bool runtimeUpd
12041204
}
12051205

12061206
for (auto& objectAttributes : runtimeUpdates) {
1207-
std::vector<String> xAdd({"XADD", "icinga:runtime", "MAXLEN", "~", "1000000", "*"});
1207+
RedisConnection::Query xAdd ({"XADD", "icinga:runtime", "MAXLEN", "~", "1000000", "*"});
12081208
ObjectLock olock(objectAttributes);
12091209

12101210
for (const Dictionary::Pair& kv : objectAttributes) {
@@ -1547,7 +1547,7 @@ bool IcingaDB::PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& a
15471547
* icinga:config:object:downtime) need to be prepended. There is nothing to indicate success or failure.
15481548
*/
15491549
void
1550-
IcingaDB::CreateConfigUpdate(const ConfigObject::Ptr& object, const String typeName, std::map<String, std::vector<String>>& hMSets,
1550+
IcingaDB::CreateConfigUpdate(const ConfigObject::Ptr& object, const String typeName, std::map<String, RedisConnection::Query>& hMSets,
15511551
std::vector<Dictionary::Ptr>& runtimeUpdates, bool runtimeUpdate)
15521552
{
15531553
/* TODO: This isn't essentially correct as we don't keep track of config objects ourselves. This would avoid duplicated config updates at startup.
@@ -1710,7 +1710,7 @@ void IcingaDB::SendStateChange(const ConfigObject::Ptr& object, const CheckResul
17101710
Array::Ptr rawId = new Array({m_EnvironmentId, object->GetName()});
17111711
rawId->Add(eventTs);
17121712

1713-
std::vector<String> xAdd ({
1713+
RedisConnection::Query xAdd ({
17141714
"XADD", "icinga:history:stream:state", "*",
17151715
"id", HashValue(rawId),
17161716
"environment_id", m_EnvironmentId,
@@ -1794,7 +1794,7 @@ void IcingaDB::SendSentNotification(
17941794

17951795
auto notificationHistoryId (HashValue(rawId));
17961796

1797-
std::vector<String> xAdd ({
1797+
RedisConnection::Query xAdd ({
17981798
"XADD", "icinga:history:stream:notification", "*",
17991799
"id", notificationHistoryId,
18001800
"environment_id", m_EnvironmentId,
@@ -1858,7 +1858,7 @@ void IcingaDB::SendStartedDowntime(const Downtime::Ptr& downtime)
18581858
/* Update checkable state as in_downtime may have changed. */
18591859
UpdateState(checkable, StateUpdate::Full);
18601860

1861-
std::vector<String> xAdd ({
1861+
RedisConnection::Query xAdd ({
18621862
"XADD", "icinga:history:stream:downtime", "*",
18631863
"downtime_id", GetObjectIdentifier(downtime),
18641864
"environment_id", m_EnvironmentId,
@@ -1948,7 +1948,7 @@ void IcingaDB::SendRemovedDowntime(const Downtime::Ptr& downtime)
19481948
/* Update checkable state as in_downtime may have changed. */
19491949
UpdateState(checkable, StateUpdate::Full);
19501950

1951-
std::vector<String> xAdd ({
1951+
RedisConnection::Query xAdd ({
19521952
"XADD", "icinga:history:stream:downtime", "*",
19531953
"downtime_id", GetObjectIdentifier(downtime),
19541954
"environment_id", m_EnvironmentId,
@@ -2030,7 +2030,7 @@ void IcingaDB::SendAddedComment(const Comment::Ptr& comment)
20302030
Service::Ptr service;
20312031
tie(host, service) = GetHostService(checkable);
20322032

2033-
std::vector<String> xAdd ({
2033+
RedisConnection::Query xAdd ({
20342034
"XADD", "icinga:history:stream:comment", "*",
20352035
"comment_id", GetObjectIdentifier(comment),
20362036
"environment_id", m_EnvironmentId,
@@ -2102,7 +2102,7 @@ void IcingaDB::SendRemovedComment(const Comment::Ptr& comment)
21022102
Service::Ptr service;
21032103
tie(host, service) = GetHostService(checkable);
21042104

2105-
std::vector<String> xAdd ({
2105+
RedisConnection::Query xAdd ({
21062106
"XADD", "icinga:history:stream:comment", "*",
21072107
"comment_id", GetObjectIdentifier(comment),
21082108
"environment_id", m_EnvironmentId,
@@ -2165,7 +2165,7 @@ void IcingaDB::SendFlappingChange(const Checkable::Ptr& checkable, double change
21652165
Service::Ptr service;
21662166
tie(host, service) = GetHostService(checkable);
21672167

2168-
std::vector<String> xAdd ({
2168+
RedisConnection::Query xAdd ({
21692169
"XADD", "icinga:history:stream:flapping", "*",
21702170
"environment_id", m_EnvironmentId,
21712171
"host_id", GetObjectIdentifier(host),
@@ -2260,7 +2260,7 @@ void IcingaDB::SendAcknowledgementSet(const Checkable::Ptr& checkable, const Str
22602260
/* Update checkable state as is_acknowledged may have changed. */
22612261
UpdateState(checkable, StateUpdate::Full);
22622262

2263-
std::vector<String> xAdd ({
2263+
RedisConnection::Query xAdd ({
22642264
"XADD", "icinga:history:stream:acknowledgement", "*",
22652265
"environment_id", m_EnvironmentId,
22662266
"host_id", GetObjectIdentifier(host),
@@ -2318,7 +2318,7 @@ void IcingaDB::SendAcknowledgementCleared(const Checkable::Ptr& checkable, const
23182318
/* Update checkable state as is_acknowledged may have changed. */
23192319
UpdateState(checkable, StateUpdate::Full);
23202320

2321-
std::vector<String> xAdd ({
2321+
RedisConnection::Query xAdd ({
23222322
"XADD", "icinga:history:stream:acknowledgement", "*",
23232323
"environment_id", m_EnvironmentId,
23242324
"host_id", GetObjectIdentifier(host),
@@ -2959,7 +2959,7 @@ void IcingaDB::DeleteRelationship(const String& id, const String& redisKeyWithou
29592959

29602960
String redisKey = m_PrefixConfigObject + redisKeyWithoutPrefix;
29612961

2962-
std::vector<std::vector<String>> queries;
2962+
RedisConnection::Queries queries;
29632963

29642964
if (hasChecksum) {
29652965
queries.push_back({"HDEL", m_PrefixConfigCheckSum + redisKeyWithoutPrefix, id});

lib/icingadb/icingadb.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void IcingaDB::PublishStats()
175175
status->Set("timestamp", TimestampToMilliseconds(Utility::GetTime()));
176176
status->Set("icingadb_environment", m_EnvironmentId);
177177

178-
std::vector<String> query {"XADD", "icinga:stats", "MAXLEN", "1", "*"};
178+
RedisConnection::Query query {"XADD", "icinga:stats", "MAXLEN", "1", "*"};
179179

180180
{
181181
ObjectLock statusLock (status);

lib/icingadb/icingadb.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ class IcingaDB : public ObjectImpl<IcingaDB>
101101
void DeleteKeys(const RedisConnection::Ptr& conn, const std::vector<String>& keys, RedisConnection::QueryPriority priority);
102102
std::vector<String> GetTypeOverwriteKeys(const String& type);
103103
std::vector<String> GetTypeDumpSignalKeys(const Type::Ptr& type);
104-
void InsertObjectDependencies(const ConfigObject::Ptr& object, const String typeName, std::map<String, std::vector<String>>& hMSets,
104+
void InsertObjectDependencies(const ConfigObject::Ptr& object, const String typeName, std::map<String, RedisConnection::Query>& hMSets,
105105
std::vector<Dictionary::Ptr>& runtimeUpdates, bool runtimeUpdate);
106106
void UpdateState(const Checkable::Ptr& checkable, StateUpdate mode);
107107
void SendConfigUpdate(const ConfigObject::Ptr& object, bool runtimeUpdate);
108-
void CreateConfigUpdate(const ConfigObject::Ptr& object, const String type, std::map<String, std::vector<String>>& hMSets,
108+
void CreateConfigUpdate(const ConfigObject::Ptr& object, const String type, std::map<String, RedisConnection::Query>& hMSets,
109109
std::vector<Dictionary::Ptr>& runtimeUpdates, bool runtimeUpdate);
110110
void SendConfigDelete(const ConfigObject::Ptr& object);
111111
void SendStateChange(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type);

0 commit comments

Comments
 (0)