From eee4f7cf550fd59326c2b36d68403aa82661182a Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 12 Jul 2021 23:43:04 +0200 Subject: [PATCH] IcingaConfig: store config file relations in a... ...transaction: all or nothing fixes #2351 --- doc/82-Changelog.md | 3 ++ .../Director/IcingaConfig/IcingaConfig.php | 30 +++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index c319fc70..0a104e91 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -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) diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php index 78776bea..4d88ed0b 100644 --- a/library/Director/IcingaConfig/IcingaConfig.php +++ b/library/Director/IcingaConfig/IcingaConfig.php @@ -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;