From 622483bf0da6545376a1440acf1aadbf05cb2f83 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Fri, 31 Mar 2023 09:47:50 +0200 Subject: [PATCH] fix(gorgone): mbi unable to rebuild partial data with new scripts (#1190) --- .../modules/centreon/mbi/etl/event/main.pm | 19 ++++++++++++++----- .../modules/centreon/mbi/etl/perfdata/main.pm | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/gorgone/gorgone/modules/centreon/mbi/etl/event/main.pm b/gorgone/gorgone/modules/centreon/mbi/etl/event/main.pm index bc59ac696b7..6ccbcc447f5 100644 --- a/gorgone/gorgone/modules/centreon/mbi/etl/event/main.pm +++ b/gorgone/gorgone/modules/centreon/mbi/etl/event/main.pm @@ -83,13 +83,22 @@ sub deleteEntriesForRebuild { "DELETE FROM $options{name} WHERE time_id >= " . $utils->getDateEpoch($options{start}) . " AND time_id < " . $utils->getDateEpoch($options{end}) ]; } else { + my $structure = $biTables->dumpTableStructure($options{name}); my $partitionsPerf = $utils->getRangePartitionDate($options{start}, $options{end}); foreach (@$partitionsPerf) { - push @$sql, - [ - "[PURGE] Truncate partition $_->{name} on table [$options{name}]", - "ALTER TABLE $options{name} TRUNCATE PARTITION p$_->{name}" - ]; + if ($structure =~ /p$_->{name}/m) { + push @$sql, + [ + "[PURGE] Truncate partition $_->{name} on table [$options{name}]", + "ALTER TABLE $options{name} TRUNCATE PARTITION p$_->{name}" + ]; + } else { + push @$sql, + [ + '[PARTITIONS] Add partition [p' . $_->{name} . '] on table [' . $options{name} . ']', + "ALTER TABLE `$options{name}` ADD PARTITION (PARTITION `p$_->{name}` VALUES LESS THAN(" . $_->{epoch} . "))" + ]; + } } } diff --git a/gorgone/gorgone/modules/centreon/mbi/etl/perfdata/main.pm b/gorgone/gorgone/modules/centreon/mbi/etl/perfdata/main.pm index c5fbd0ab3a8..170903907c0 100644 --- a/gorgone/gorgone/modules/centreon/mbi/etl/perfdata/main.pm +++ b/gorgone/gorgone/modules/centreon/mbi/etl/perfdata/main.pm @@ -83,13 +83,22 @@ sub deleteEntriesForRebuild { "DELETE FROM $options{name} WHERE time_id >= " . $utils->getDateEpoch($options{start}) . " AND time_id < " . $utils->getDateEpoch($options{end}) ]; } else { + my $structure = $biTables->dumpTableStructure($options{name}); my $partitionsPerf = $utils->getRangePartitionDate($options{start}, $options{end}); foreach (@$partitionsPerf) { - push @$sql, - [ - "[PURGE] Truncate partition $_->{name} on table [$options{name}]", - "ALTER TABLE $options{name} TRUNCATE PARTITION p$_->{name}" - ]; + if ($structure =~ /p$_->{name}/m) { + push @$sql, + [ + "[PURGE] Truncate partition $_->{name} on table [$options{name}]", + "ALTER TABLE $options{name} TRUNCATE PARTITION p$_->{name}" + ]; + } else { + push @$sql, + [ + '[PARTITIONS] Add partition [p' . $_->{name} . '] on table [' . $options{name} . ']', + "ALTER TABLE `$options{name}` ADD PARTITION (PARTITION `p$_->{name}` VALUES LESS THAN(" . $_->{epoch} . "))" + ]; + } } }