From 3a07ec81d6a0bc9afeb32106313909e9e913f682 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Sun, 9 Jun 2024 17:49:28 -0700 Subject: [PATCH] clean up Signed-off-by: Jackie Han --- .../timeseries/indices/IndexManagement.java | 32 +++++++------------ .../opensearch/ad/indices/RolloverTests.java | 2 +- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/opensearch/timeseries/indices/IndexManagement.java b/src/main/java/org/opensearch/timeseries/indices/IndexManagement.java index aea919b28..c6357cf24 100644 --- a/src/main/java/org/opensearch/timeseries/indices/IndexManagement.java +++ b/src/main/java/org/opensearch/timeseries/indices/IndexManagement.java @@ -1082,7 +1082,7 @@ public void onClusterManager() { // schedule the next rollover for approx MAX_AGE later scheduledRollover = threadPool - .scheduleWithFixedDelay(() -> rolloverAndDeleteHistoryIndex(), TimeValue.timeValueMinutes(1), executorName()); + .scheduleWithFixedDelay(() -> rolloverAndDeleteHistoryIndex(), historyRolloverPeriod, executorName()); } catch (Exception e) { // This should be run on cluster startup logger.error("Error rollover result indices. " + "Can't rollover result until clusterManager node is restarted.", e); @@ -1240,36 +1240,28 @@ protected void rolloverAndDeleteHistoryIndex( String rolloverIndexPattern, IndexType resultIndex ) { - // build rollover request for default result index - RolloverRequest defaultResultIndexRolloverRequest = buildRolloverRequest(resultIndexAlias, rolloverIndexPattern); - defaultResultIndexRolloverRequest.addMaxIndexDocsCondition(historyMaxDocs * getNumberOfPrimaryShards()); - - // get config files that have custom result index alias to perform rollover on - getConfigsWithCustomResultIndexAlias(ActionListener.wrap(candidateResultAliases -> { - if (candidateResultAliases == null || candidateResultAliases.isEmpty()) { - // no custom result index alias found - if (!doesDefaultResultIndexExist()) { - // no default result index found either - return; - } - // perform rollover and delete on default result index - proceedWithDefaultRolloverAndDelete( + // rollover and delete default result index + if (doesDefaultResultIndexExist()) { + RolloverRequest defaultResultIndexRolloverRequest = buildRolloverRequest(resultIndexAlias, rolloverIndexPattern); + defaultResultIndexRolloverRequest.addMaxIndexDocsCondition(historyMaxDocs * getNumberOfPrimaryShards()); + proceedWithDefaultRolloverAndDelete( resultIndexAlias, defaultResultIndexRolloverRequest, allResultIndicesPattern, resultIndex - ); + ); + } + + // rollover and delete custom result index + getConfigsWithCustomResultIndexAlias(ActionListener.wrap(candidateResultAliases -> { + if (candidateResultAliases == null || candidateResultAliases.isEmpty()) { logger.info("Candidate custom result indices are empty."); return; } - // perform rollover and delete on found custom result index alias candidateResultAliases.forEach(config -> handleCustomResultIndex(config, resultIndex)); - }, e -> { logger.error("Failed to get configs with custom result index alias.", e); - // perform rollover and delete on default result index if getting error on getting custom result index alias - proceedWithDefaultRolloverAndDelete(resultIndexAlias, defaultResultIndexRolloverRequest, allResultIndicesPattern, resultIndex); })); } diff --git a/src/test/java/org/opensearch/ad/indices/RolloverTests.java b/src/test/java/org/opensearch/ad/indices/RolloverTests.java index bdffd918d..561170c74 100644 --- a/src/test/java/org/opensearch/ad/indices/RolloverTests.java +++ b/src/test/java/org/opensearch/ad/indices/RolloverTests.java @@ -273,8 +273,8 @@ public void testRetryingDelete() { } public void testNoCustomResultIndexFound_RolloverDefaultResultIndex_shouldSucceed() { - setUpGetConfigs_withNoCustomResultIndexAlias(); setUpRolloverSuccess(); + setUpGetConfigs_withNoCustomResultIndexAlias(); adIndices.rolloverAndDeleteHistoryIndex(); verify(indicesClient, times(1)).rolloverIndex(any(), any());