Increment /var/lib/icinga2/api/zones/*/.timestamp only on config change

refs #8210
This commit is contained in:
Alexander A. Klimov 2020-09-07 16:41:52 +02:00
parent 71e19c4d01
commit ac1371a6f4

View File

@ -13,6 +13,7 @@
#include "base/exception.hpp"
#include "base/shared.hpp"
#include "base/utility.hpp"
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <thread>
@ -61,11 +62,14 @@ void ApiListener::SyncLocalZoneDir(const Zone::Ptr& zone) const
String zoneName = zone->GetName();
Dictionary::Ptr contents = new Dictionary();
double ts = 0;
// Load registered zone paths, e.g. '_etc', '_api' and user packages.
for (const ZoneFragment& zf : ConfigCompiler::GetZoneDirs(zoneName)) {
ConfigDirInformation newConfigPart = LoadConfigDir(zf.Path, contents);
Utility::GlobRecursive(zf.Path, "*", [&ts](const String& path) { ts = std::max(ts, Utility::GetModTime(path)); }, GlobFile | GlobDirectory);
// Config files '*.conf'.
{
ObjectLock olock(newConfigPart.UpdateV1);
@ -89,6 +93,11 @@ void ApiListener::SyncLocalZoneDir(const Zone::Ptr& zone) const
}
}
if (ts == 0) {
// Syncing an empty zone every time hurts less than not syncing it at all.
ts = Utility::GetTime();
}
size_t sumUpdates = newConfigInfo.UpdateV1->GetLength() + newConfigInfo.UpdateV2->GetLength();
// Return early if there are no updates.
@ -144,7 +153,7 @@ void ApiListener::SyncLocalZoneDir(const Zone::Ptr& zone) const
if (!Utility::PathExists(tsPath)) {
std::ofstream fp(tsPath.CStr(), std::ofstream::out | std::ostream::trunc);
fp << std::fixed << Utility::GetTime();
fp << std::fixed << ts;
fp.close();
}