IcingaConfig: store config file relations in a...

...transaction: all or nothing

fixes #2351
This commit is contained in:
Thomas Gelf 2021-07-12 23:43:04 +02:00
parent fed74eb33d
commit eee4f7cf55
2 changed files with 21 additions and 12 deletions

View File

@ -48,6 +48,9 @@ next patch release (will be 1.8.1)
* FIX: don't fail when showing a Host overriding multiple inherited groups (#2253)
* FIX: deal with inherited values which are invalid for a select box (#2288)
### Icinga Configuration
* FIX: rare race condition, where generated config might miss some files (#2351)
### Import and Sync
* FIX: Purge didn't remove more than 1000 services at once (#2339)

View File

@ -411,25 +411,31 @@ class IcingaConfig
}
$activity = $this->dbBin($this->getLastActivityChecksum());
$this->db->insert(
self::$table,
array(
$this->db->beginTransaction();
try {
$this->db->insert(self::$table, [
'duration' => $this->generationTime,
'first_activity_checksum' => $activity,
'last_activity_checksum' => $activity,
'checksum' => $this->dbBin($this->getChecksum()),
)
);
/** @var IcingaConfigFile $file */
foreach ($this->files as $name => $file) {
$this->db->insert(
'director_generated_config_file',
array(
]);
/** @var IcingaConfigFile $file */
foreach ($this->files as $name => $file) {
$this->db->insert('director_generated_config_file', [
'config_checksum' => $this->dbBin($this->getChecksum()),
'file_checksum' => $this->dbBin($file->getChecksum()),
'file_path' => $name,
)
);
]);
}
$this->db->commit();
} catch (\Exception $e) {
try {
$this->db->rollBack();
} catch (\Exception $ignored) {
// Well...
}
throw $e;
}
return $this;