From 30be02bcae01546ac20c52f489bef6bc531ecfa5 Mon Sep 17 00:00:00 2001 From: Jean Flach Date: Wed, 9 Aug 2017 17:41:43 +0200 Subject: [PATCH] Alter DowntimeRemoval behaviour This adds an additional index to the downtimehistory and updates the dbevents in a way that it uses that index --- lib/db_ido/dbconnection.hpp | 2 +- lib/db_ido/dbevents.cpp | 1 + lib/db_ido_mysql/schema/mysql.sql | 11 ++++++++--- lib/db_ido_mysql/schema/upgrade/2.8.0.sql | 22 ++++++++++++++++++++++ lib/db_ido_pgsql/schema/pgsql.sql | 8 ++++++-- lib/db_ido_pgsql/schema/upgrade/2.8.0.sql | 21 +++++++++++++++++++++ 6 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 lib/db_ido_mysql/schema/upgrade/2.8.0.sql create mode 100644 lib/db_ido_pgsql/schema/upgrade/2.8.0.sql diff --git a/lib/db_ido/dbconnection.hpp b/lib/db_ido/dbconnection.hpp index dc677d075..f26735f3a 100644 --- a/lib/db_ido/dbconnection.hpp +++ b/lib/db_ido/dbconnection.hpp @@ -29,7 +29,7 @@ #include #include -#define IDO_CURRENT_SCHEMA_VERSION "1.14.2" +#define IDO_CURRENT_SCHEMA_VERSION "1.14.3" #define IDO_COMPAT_SCHEMA_VERSION "1.14.2" namespace icinga diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index 706e3ddd3..557a0e65d 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -586,6 +586,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt query1.Type = DbQueryDelete; query1.Category = DbCatDowntime; query1.WhereCriteria = new Dictionary(); + query1.WhereCriteria->Set("object_id", checkable); query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime())); query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ diff --git a/lib/db_ido_mysql/schema/mysql.sql b/lib/db_ido_mysql/schema/mysql.sql index 77f022b05..8f7238a97 100644 --- a/lib/db_ido_mysql/schema/mysql.sql +++ b/lib/db_ido_mysql/schema/mysql.sql @@ -2,7 +2,7 @@ -- mysql.sql -- DB definition for IDO MySQL -- --- Copyright (c) 2009-2016 Icinga Development Team (https://www.icinga.com/) +-- Copyright (c) 2009-2017 Icinga Development Team (https://www.icinga.com/) -- -- -- -------------------------------------------------------- @@ -1681,10 +1681,15 @@ CREATE INDEX idx_hostdependencies_dependent_host_object_id on icinga_hostdepende CREATE INDEX idx_service_contacts_service_id on icinga_service_contacts(service_id); CREATE INDEX idx_host_contacts_host_id on icinga_host_contacts(host_id); +-- #5458 +CREATE INDEX idx_downtimehistory_remove ON icinga_downtimehistory (object_id, entry_time, scheduled_start_time, scheduled_end_time); +CREATE INDEX idx_scheduleddowntime_remove ON icinga_scheduleddowntime (object_id, entry_time, scheduled_start_time, scheduled_end_time); + + -- ----------------------------------------- -- set dbversion -- ----------------------------------------- -INSERT INTO icinga_dbversion (name, version, create_time, modify_time) VALUES ('idoutils', '1.14.2', NOW(), NOW()) -ON DUPLICATE KEY UPDATE version='1.14.2', modify_time=NOW(); +INSERT INTO icinga_dbversion (name, version, create_time, modify_time) VALUES ('idoutils', '1.14.3', NOW(), NOW()) +ON DUPLICATE KEY UPDATE version='1.14.3', modify_time=NOW(); diff --git a/lib/db_ido_mysql/schema/upgrade/2.8.0.sql b/lib/db_ido_mysql/schema/upgrade/2.8.0.sql new file mode 100644 index 000000000..5e0facf9f --- /dev/null +++ b/lib/db_ido_mysql/schema/upgrade/2.8.0.sql @@ -0,0 +1,22 @@ +-- ----------------------------------------- +-- upgrade path for Icinga 2.8.0 +-- +-- ----------------------------------------- +-- Copyright (c) 2017 Icinga Development Team (https://www.icinga.com) +-- +-- Please check https://docs.icinga.com for upgrading information! +-- ----------------------------------------- + +SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; + +-- ----------------------------------------- +-- #5458 IDO: Improve downtime removal/cancel +-- ----------------------------------------- + +CREATE INDEX idx_downtimehistory_remove ON icinga_downtimehistory (object_id, entry_time, scheduled_start_time, scheduled_end_time); +CREATE INDEX idx_scheduleddowntime_remove ON icinga_scheduleddowntime (object_id, entry_time, scheduled_start_time, scheduled_end_time); + +-- ----------------------------------------- +-- set dbversion +-- ----------------------------------------- +INSERT INTO icinga_dbversion (name, version, create_time, modify_time) VALUES ('idoutils', '1.14.3', NOW(), NOW()) ON DUPLICATE KEY UPDATE version='1.14.3', modify_time=NOW(); diff --git a/lib/db_ido_pgsql/schema/pgsql.sql b/lib/db_ido_pgsql/schema/pgsql.sql index fda5ea591..bbd54b4be 100644 --- a/lib/db_ido_pgsql/schema/pgsql.sql +++ b/lib/db_ido_pgsql/schema/pgsql.sql @@ -2,7 +2,7 @@ -- pgsql.sql -- DB definition for IDO Postgresql -- --- Copyright (c) 2009-2016 Icinga Development Team (https://www.icinga.com/) +-- Copyright (c) 2009-2017 Icinga Development Team (https://www.icinga.com/) -- -- -------------------------------------------------------- @@ -1721,9 +1721,13 @@ CREATE INDEX idx_hostdependencies_dependent_host_object_id on icinga_hostdepende CREATE INDEX idx_service_contacts_service_id on icinga_service_contacts(service_id); CREATE INDEX idx_host_contacts_host_id on icinga_host_contacts(host_id); +-- #5458 +CREATE INDEX idx_downtimehistory_remove ON icinga_downtimehistory (object_id, entry_time, scheduled_start_time, scheduled_end_time); +CREATE INDEX idx_scheduleddowntime_remove ON icinga_scheduleddowntime (object_id, entry_time, scheduled_start_time, scheduled_end_time); + -- ----------------------------------------- -- set dbversion -- ----------------------------------------- -SELECT updatedbversion('1.14.2'); +SELECT updatedbversion('1.14.3'); diff --git a/lib/db_ido_pgsql/schema/upgrade/2.8.0.sql b/lib/db_ido_pgsql/schema/upgrade/2.8.0.sql new file mode 100644 index 000000000..620486748 --- /dev/null +++ b/lib/db_ido_pgsql/schema/upgrade/2.8.0.sql @@ -0,0 +1,21 @@ +-- ----------------------------------------- +-- upgrade path for Icinga 2.8.0 +-- +-- ----------------------------------------- +-- Copyright (c) 2017 Icinga Development Team (https://www.icinga.com) +-- +-- Please check https://docs.icinga.com for upgrading information! +-- ----------------------------------------- + +-- ----------------------------------------- +-- #5458 IDO: Improve downtime removal/cancel +-- ----------------------------------------- + +CREATE INDEX idx_downtimehistory_remove ON icinga_downtimehistory (object_id, entry_time, scheduled_start_time, scheduled_end_time); +CREATE INDEX idx_scheduleddowntime_remove ON icinga_scheduleddowntime (object_id, entry_time, scheduled_start_time, scheduled_end_time); + +-- ----------------------------------------- +-- set dbversion +-- ----------------------------------------- + +SELECT updatedbversion('1.14.3');