mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 22:24:44 +02:00
Cluster Sync: Ensure that files are synced everytime
This commit is contained in:
parent
35f53c0dc1
commit
87d4575af8
@ -441,10 +441,6 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D
|
|||||||
* */
|
* */
|
||||||
relativePaths.push_back(zoneName + "/" + kv.first);
|
relativePaths.push_back(zoneName + "/" + kv.first);
|
||||||
|
|
||||||
// Ignore same config content. This is an expensive comparison.
|
|
||||||
if (productionConfig->Get(kv.first) == kv.second)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
String path = stageConfigZoneDir + "/" + kv.first;
|
String path = stageConfigZoneDir + "/" + kv.first;
|
||||||
|
|
||||||
if (Utility::Match("*.conf", path)) {
|
if (Utility::Match("*.conf", path)) {
|
||||||
@ -667,35 +663,81 @@ bool ApiListener::CheckConfigChange(const ConfigDirInformation& oldConfig, const
|
|||||||
<< "' vs. new (" << newChecksums->GetLength() << "): '"
|
<< "' vs. new (" << newChecksums->GetLength() << "): '"
|
||||||
<< JsonEncode(newChecksums) << "'.";
|
<< JsonEncode(newChecksums) << "'.";
|
||||||
|
|
||||||
// Don't check for different length, this may be influenced from internal files
|
|
||||||
ObjectLock olock(oldChecksums);
|
|
||||||
|
|
||||||
for (const Dictionary::Pair& kv : oldChecksums) {
|
/* Since internal files are synced here too, we can not depend on length.
|
||||||
String path = kv.first;
|
* So we need to go through both checksum sets to cover the cases"everything is new" and "everything was deleted".
|
||||||
String oldChecksum = kv.second;
|
*/
|
||||||
|
{
|
||||||
|
ObjectLock olock(oldChecksums);
|
||||||
|
for (const Dictionary::Pair& kv : oldChecksums) {
|
||||||
|
String path = kv.first;
|
||||||
|
String oldChecksum = kv.second;
|
||||||
|
|
||||||
// TODO: Figure out if config changes only apply to '.conf'. Leaving this open for other config files.
|
// TODO: Figure out if config changes only apply to '.conf'. Leaving this open for other config files.
|
||||||
//if (!Utility::Match("*.conf", path))
|
//if (!Utility::Match("*.conf", path))
|
||||||
// continue;
|
// continue;
|
||||||
|
|
||||||
/* Ignore internal files, especially .timestamp and .checksums.
|
/* Ignore internal files, especially .timestamp and .checksums.
|
||||||
*
|
*
|
||||||
* If we don't, this results in "always change" restart loops.
|
* If we don't, this results in "always change" restart loops.
|
||||||
*/
|
*/
|
||||||
if (Utility::Match("/.*", path))
|
if (Utility::Match("/.*", path)) {
|
||||||
continue;
|
Log(LogDebug, "ApiListener")
|
||||||
|
<< "Ignoring internal file '" << path << "'";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Log(LogDebug, "ApiListener")
|
|
||||||
<< "Checking " << path << " for checksum: " << oldChecksum;
|
|
||||||
|
|
||||||
// Check whether our key exists in the new checksums, and they have an equal value.
|
|
||||||
String newChecksum = newChecksums->Get(path);
|
|
||||||
|
|
||||||
if (newChecksums->Get(path) != kv.second) {
|
|
||||||
Log(LogDebug, "ApiListener")
|
Log(LogDebug, "ApiListener")
|
||||||
<< "Path '" << path << "' doesn't match old checksum '"
|
<< "Checking " << path << " for old checksum: " << oldChecksum;
|
||||||
<< newChecksum << "' with new checksum '" << oldChecksum << "'.";
|
|
||||||
return true;
|
// Check if key exists first for more verbose logging.
|
||||||
|
// TODO: Don't do this later on.
|
||||||
|
if (!newChecksums->Contains(path)) {
|
||||||
|
Log(LogDebug, "ApiListener")
|
||||||
|
<< "File '" << path << "' was deleted by remote.";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String newChecksum = newChecksums->Get(path);
|
||||||
|
if (newChecksum != kv.second) {
|
||||||
|
Log(LogDebug, "ApiListener")
|
||||||
|
<< "Path '" << path << "' doesn't match old checksum '"
|
||||||
|
<< oldChecksum << "' with new checksum '" << newChecksum << "'.";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ObjectLock olock(newChecksums);
|
||||||
|
for (const Dictionary::Pair& kv : newChecksums) {
|
||||||
|
String path = kv.first;
|
||||||
|
String newChecksum = kv.second;
|
||||||
|
|
||||||
|
// TODO: Figure out if config changes only apply to '.conf'. Leaving this open for other config files.
|
||||||
|
//if (!Utility::Match("*.conf", path))
|
||||||
|
// continue;
|
||||||
|
|
||||||
|
/* Ignore internal files, especially .timestamp and .checksums.
|
||||||
|
*
|
||||||
|
* If we don't, this results in "always change" restart loops.
|
||||||
|
*/
|
||||||
|
if (Utility::Match("/.*", path)) {
|
||||||
|
Log(LogDebug, "ApiListener")
|
||||||
|
<< "Ignoring internal file '" << path << "'";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log(LogDebug, "ApiListener")
|
||||||
|
<< "Checking " << path << " for new checksum: " << newChecksum;
|
||||||
|
|
||||||
|
// Here we only need to check if the checksum exists, checksums in both sets have already been compared
|
||||||
|
// TODO: Don't do this later on.
|
||||||
|
if (!oldChecksums->Contains(path)) {
|
||||||
|
Log(LogDebug, "ApiListener")
|
||||||
|
<< "File '" << path << "' was added by remote.";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user