From 9ea9daae14253b56cba48ae5d7fb687d5eb51b01 Mon Sep 17 00:00:00 2001 From: Chase Engelbrecht Date: Mon, 12 Feb 2024 18:48:09 -0800 Subject: [PATCH] Only update mappings if they have not already been updated Signed-off-by: Chase Engelbrecht --- .../kotlin/org/opensearch/alerting/alerts/AlertIndices.kt | 4 +++- .../main/kotlin/org/opensearch/alerting/util/IndexUtils.kt | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt b/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt index 66fb262a9..6b79bf292 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt @@ -292,6 +292,7 @@ class AlertIndices( dataSources.alertsHistoryIndex ) } else { + // TODO - why do we need explicit mappings? updateIndexMapping( dataSources.alertsHistoryIndex ?: ALERT_HISTORY_WRITE_INDEX, alertMapping(), @@ -380,7 +381,7 @@ class AlertIndices( } // TODO call getMapping and compare actual mappings here instead of this - if (targetIndex == IndexUtils.lastUpdatedAlertHistoryIndex || targetIndex == IndexUtils.lastUpdatedFindingHistoryIndex) { + if (IndexUtils.initializedIndices.contains(targetIndex)) { return } @@ -396,6 +397,7 @@ class AlertIndices( } private fun setIndexUpdateFlag(index: String, targetIndex: String) { + IndexUtils.initializedIndices.add(targetIndex) when (index) { ALERT_INDEX -> IndexUtils.alertIndexUpdated() ALERT_HISTORY_WRITE_INDEX -> IndexUtils.lastUpdatedAlertHistoryIndex = targetIndex diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/util/IndexUtils.kt b/alerting/src/main/kotlin/org/opensearch/alerting/util/IndexUtils.kt index 387f5cb22..c021d1291 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/util/IndexUtils.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/util/IndexUtils.kt @@ -47,6 +47,8 @@ class IndexUtils { var lastUpdatedAlertHistoryIndex: String? = null var lastUpdatedFindingHistoryIndex: String? = null + var initializedIndices: MutableSet = mutableSetOf() + init { scheduledJobIndexSchemaVersion = getSchemaVersion(ScheduledJobIndices.scheduledJobMappings()) alertIndexSchemaVersion = getSchemaVersion(AlertIndices.alertMapping())