From 91ca8065e3bd4854d71fbdc042401116d01d53e6 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 7 Oct 2022 12:22:19 +0200 Subject: [PATCH] Sync: fix purge and invalid sync history fixes #2632 fixes #2627 --- doc/82-Changelog.md | 5 +++++ library/Director/Import/Sync.php | 10 ++++++++-- schema/mysql-migrations/upgrade_182.sql | 12 ++++++++++++ schema/mysql.sql | 2 +- schema/pgsql-migrations/upgrade_182.sql | 14 ++++++++++++++ schema/pgsql.sql | 2 +- 6 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 schema/mysql-migrations/upgrade_182.sql create mode 100644 schema/pgsql-migrations/upgrade_182.sql diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index 1edbb781..97b8535b 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -16,6 +16,9 @@ Please note that a long-standing issue for our Sync Rules has been fixed: with now been fixed. If in doubt, please **preview** your Sync Rules to make sure, that they behave as expected. +This release brings a small schema migration, cleaning up invalid Sync history +entries. If in doubt, please create a [database backup](05-Upgrading.md#backup-first) first. + ### Fixed issues * You can find issues and feature requests related to this release on our [roadmap](https://github.com/Icinga/icingaweb2-module-director/milestone/30?closed=1) @@ -24,6 +27,8 @@ that they behave as expected. * FIX: sync lower-cased all object names since v1.10 (#2608) * FIX: sync for Datalist entries has been fixed (#2618) * FIX: Sync now applied NULL values with merge policy (#2623) +* FIX: Sync created Sync History entries for every preview (#2632) +* FIX: "Purge" stopped working for Sync (#2627) ### UI * FIX: "Modify" Services via the monitoring module (#2615, #2619) diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index a6e902ac..45211cf0 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -882,7 +882,10 @@ class Sync )); } - $this->run->setProperties($runProperties)->store(); + $this->run->setProperties($runProperties); + if (!$this->store->getBranch()->isBranch()) { + $this->run->store(); + } $this->notifyResolvers(); if (! $this->store) { $dba->commit(); @@ -891,7 +894,10 @@ class Sync // Store duration after commit, as the commit might take some time $this->run->set('duration_ms', (int) round( (microtime(true) - $this->runStartTime) * 1000 - ))->store(); + )); + if (!$this->store->getBranch()->isBranch()) { + $this->run->store(); + } Benchmark::measure('Done applying objects'); } catch (Exception $e) { diff --git a/schema/mysql-migrations/upgrade_182.sql b/schema/mysql-migrations/upgrade_182.sql new file mode 100644 index 00000000..bb91fdae --- /dev/null +++ b/schema/mysql-migrations/upgrade_182.sql @@ -0,0 +1,12 @@ +DELETE sr.* + FROM sync_run sr + JOIN sync_rule s ON s.id = sr.rule_id + WHERE sr.last_former_activity = sr.last_related_activity + AND s.object_type != 'datalistEntry' AND sr.start_time > '2022-09-21 00:00:00'; + +DELETE FROM sync_run + WHERE (objects_created + objects_deleted + objects_modified) = 0; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (182, NOW()); diff --git a/schema/mysql.sql b/schema/mysql.sql index 0403bcbf..02ac5d9f 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -2439,4 +2439,4 @@ CREATE TABLE branched_icinga_dependency ( INSERT INTO director_schema_migration (schema_version, migration_time) - VALUES (180, NOW()); + VALUES (182, NOW()); diff --git a/schema/pgsql-migrations/upgrade_182.sql b/schema/pgsql-migrations/upgrade_182.sql new file mode 100644 index 00000000..634d0483 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_182.sql @@ -0,0 +1,14 @@ +DELETE FROM sync_run AS sr + WHERE EXISTS ( + SELECT 1 FROM sync_rule AS s + WHERE s.id = sr.rule_id + AND s.object_type != 'datalistEntry' + AND sr.start_time > '2022-09-21 00:00:00' + ) AND sr.last_former_activity = sr.last_related_activity; + +DELETE FROM sync_run + WHERE (objects_created + objects_deleted + objects_modified) = 0; + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (182, NOW()); diff --git a/schema/pgsql.sql b/schema/pgsql.sql index 2e3a979c..b9b2cf8a 100644 --- a/schema/pgsql.sql +++ b/schema/pgsql.sql @@ -2778,4 +2778,4 @@ CREATE INDEX branched_dependency_search_object_name ON branched_icinga_dependenc INSERT INTO director_schema_migration (schema_version, migration_time) - VALUES (181, NOW()); + VALUES (182, NOW());