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: 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) * 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 ### Import and Sync
* FIX: Purge didn't remove more than 1000 services at once (#2339) * 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()); $activity = $this->dbBin($this->getLastActivityChecksum());
$this->db->insert( $this->db->beginTransaction();
self::$table, try {
array( $this->db->insert(self::$table, [
'duration' => $this->generationTime, 'duration' => $this->generationTime,
'first_activity_checksum' => $activity, 'first_activity_checksum' => $activity,
'last_activity_checksum' => $activity, 'last_activity_checksum' => $activity,
'checksum' => $this->dbBin($this->getChecksum()), 'checksum' => $this->dbBin($this->getChecksum()),
) ]);
); /** @var IcingaConfigFile $file */
/** @var IcingaConfigFile $file */ foreach ($this->files as $name => $file) {
foreach ($this->files as $name => $file) { $this->db->insert('director_generated_config_file', [
$this->db->insert(
'director_generated_config_file',
array(
'config_checksum' => $this->dbBin($this->getChecksum()), 'config_checksum' => $this->dbBin($this->getChecksum()),
'file_checksum' => $this->dbBin($file->getChecksum()), 'file_checksum' => $this->dbBin($file->getChecksum()),
'file_path' => $name, 'file_path' => $name,
) ]);
); }
$this->db->commit();
} catch (\Exception $e) {
try {
$this->db->rollBack();
} catch (\Exception $ignored) {
// Well...
}
throw $e;
} }
return $this; return $this;