From 6018a4f53680c1ad81732271080dec6b08845496 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 21 Dec 2022 09:48:27 -0800 Subject: [PATCH] Seperate variables for alert and finding scheduled rollovers (#705) (#710) Signed-off-by: Ashish Agrawal Signed-off-by: Ashish Agrawal (cherry picked from commit 41265f86c371a1bea697376b51816ab495bdbe96) Co-authored-by: Ashish Agrawal --- .../alerting/alerts/AlertIndices.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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 b72f6e437..5e10b03e3 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/alerts/AlertIndices.kt @@ -161,7 +161,9 @@ class AlertIndices( private var alertIndexInitialized: Boolean = false - private var scheduledRollover: Cancellable? = null + private var scheduledAlertRollover: Cancellable? = null + + private var scheduledFindingRollover: Cancellable? = null fun onMaster() { try { @@ -169,9 +171,9 @@ class AlertIndices( rolloverAlertHistoryIndex() rolloverFindingHistoryIndex() // schedule the next rollover for approx MAX_AGE later - scheduledRollover = threadPool + scheduledAlertRollover = threadPool .scheduleWithFixedDelay({ rolloverAndDeleteAlertHistoryIndices() }, alertHistoryRolloverPeriod, executorName()) - scheduledRollover = threadPool + scheduledFindingRollover = threadPool .scheduleWithFixedDelay({ rolloverAndDeleteFindingHistoryIndices() }, findingHistoryRolloverPeriod, executorName()) } catch (e: Exception) { // This should be run on cluster startup @@ -184,7 +186,8 @@ class AlertIndices( } fun offMaster() { - scheduledRollover?.cancel() + scheduledAlertRollover?.cancel() + scheduledFindingRollover?.cancel() } private fun executorName(): String { @@ -212,16 +215,16 @@ class AlertIndices( private fun rescheduleAlertRollover() { if (clusterService.state().nodes.isLocalNodeElectedMaster) { - scheduledRollover?.cancel() - scheduledRollover = threadPool + scheduledAlertRollover?.cancel() + scheduledAlertRollover = threadPool .scheduleWithFixedDelay({ rolloverAndDeleteAlertHistoryIndices() }, alertHistoryRolloverPeriod, executorName()) } } private fun rescheduleFindingRollover() { if (clusterService.state().nodes.isLocalNodeElectedMaster) { - scheduledRollover?.cancel() - scheduledRollover = threadPool + scheduledFindingRollover?.cancel() + scheduledFindingRollover = threadPool .scheduleWithFixedDelay({ rolloverAndDeleteFindingHistoryIndices() }, findingHistoryRolloverPeriod, executorName()) } }