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) (opensearch-project#710)

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
(cherry picked from commit 41265f8)

Co-authored-by: Ashish Agrawal <ashisagr@amazon.com>
  • Loading branch information
opensearch-trigger-bot[bot] and lezzago committed Dec 21, 2022
1 parent ecba617 commit 6018a4f
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,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 @@ -184,7 +186,8 @@ class AlertIndices(
}

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

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

0 comments on commit 6018a4f

Please sign in to comment.