Skip to content

Commit

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

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

Signed-off-by: Ashish Agrawal <[email protected]>
  • Loading branch information
lezzago authored Dec 20, 2022
1 parent 9d9f588 commit 41265f8
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 41265f8

Please sign in to comment.