Skip to content

Commit

Permalink
Seperate variables for alert and finding scheduled rollovers (#705) (#…
Browse files Browse the repository at this point in the history
…711)

Signed-off-by: Ashish Agrawal <[email protected]>

Signed-off-by: Ashish Agrawal <[email protected]>
(cherry picked from commit 41265f8)

Co-authored-by: Ashish Agrawal <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and lezzago authored Dec 21, 2022
1 parent 3ba0929 commit 33f449e
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,19 @@ 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 {
// try to rollover immediately as we might be restarting the cluster
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
Expand All @@ -185,7 +187,8 @@ class AlertIndices(
}

fun offMaster() {
scheduledRollover?.cancel()
scheduledAlertRollover?.cancel()
scheduledFindingRollover?.cancel()
}

private fun executorName(): String {
Expand Down Expand Up @@ -213,16 +216,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())
}
}
Expand Down

0 comments on commit 33f449e

Please sign in to comment.