Skip to content

Commit 3a07ec8

Browse files
committed
clean up
Signed-off-by: Jackie Han <jkhanjob@gmail.com>
1 parent 864de68 commit 3a07ec8

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

src/main/java/org/opensearch/timeseries/indices/IndexManagement.java

+12-20
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ public void onClusterManager() {
10821082

10831083
// schedule the next rollover for approx MAX_AGE later
10841084
scheduledRollover = threadPool
1085-
.scheduleWithFixedDelay(() -> rolloverAndDeleteHistoryIndex(), TimeValue.timeValueMinutes(1), executorName());
1085+
.scheduleWithFixedDelay(() -> rolloverAndDeleteHistoryIndex(), historyRolloverPeriod, executorName());
10861086
} catch (Exception e) {
10871087
// This should be run on cluster startup
10881088
logger.error("Error rollover result indices. " + "Can't rollover result until clusterManager node is restarted.", e);
@@ -1240,36 +1240,28 @@ protected void rolloverAndDeleteHistoryIndex(
12401240
String rolloverIndexPattern,
12411241
IndexType resultIndex
12421242
) {
1243-
// build rollover request for default result index
1244-
RolloverRequest defaultResultIndexRolloverRequest = buildRolloverRequest(resultIndexAlias, rolloverIndexPattern);
1245-
defaultResultIndexRolloverRequest.addMaxIndexDocsCondition(historyMaxDocs * getNumberOfPrimaryShards());
1246-
1247-
// get config files that have custom result index alias to perform rollover on
1248-
getConfigsWithCustomResultIndexAlias(ActionListener.wrap(candidateResultAliases -> {
1249-
if (candidateResultAliases == null || candidateResultAliases.isEmpty()) {
1250-
// no custom result index alias found
1251-
if (!doesDefaultResultIndexExist()) {
1252-
// no default result index found either
1253-
return;
1254-
}
1255-
// perform rollover and delete on default result index
1256-
proceedWithDefaultRolloverAndDelete(
1243+
// rollover and delete default result index
1244+
if (doesDefaultResultIndexExist()) {
1245+
RolloverRequest defaultResultIndexRolloverRequest = buildRolloverRequest(resultIndexAlias, rolloverIndexPattern);
1246+
defaultResultIndexRolloverRequest.addMaxIndexDocsCondition(historyMaxDocs * getNumberOfPrimaryShards());
1247+
proceedWithDefaultRolloverAndDelete(
12571248
resultIndexAlias,
12581249
defaultResultIndexRolloverRequest,
12591250
allResultIndicesPattern,
12601251
resultIndex
1261-
);
1252+
);
1253+
}
1254+
1255+
// rollover and delete custom result index
1256+
getConfigsWithCustomResultIndexAlias(ActionListener.wrap(candidateResultAliases -> {
1257+
if (candidateResultAliases == null || candidateResultAliases.isEmpty()) {
12621258
logger.info("Candidate custom result indices are empty.");
12631259
return;
12641260
}
12651261

1266-
// perform rollover and delete on found custom result index alias
12671262
candidateResultAliases.forEach(config -> handleCustomResultIndex(config, resultIndex));
1268-
12691263
}, e -> {
12701264
logger.error("Failed to get configs with custom result index alias.", e);
1271-
// perform rollover and delete on default result index if getting error on getting custom result index alias
1272-
proceedWithDefaultRolloverAndDelete(resultIndexAlias, defaultResultIndexRolloverRequest, allResultIndicesPattern, resultIndex);
12731265
}));
12741266
}
12751267

src/test/java/org/opensearch/ad/indices/RolloverTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ public void testRetryingDelete() {
273273
}
274274

275275
public void testNoCustomResultIndexFound_RolloverDefaultResultIndex_shouldSucceed() {
276-
setUpGetConfigs_withNoCustomResultIndexAlias();
277276
setUpRolloverSuccess();
277+
setUpGetConfigs_withNoCustomResultIndexAlias();
278278

279279
adIndices.rolloverAndDeleteHistoryIndex();
280280
verify(indicesClient, times(1)).rolloverIndex(any(), any());

0 commit comments

Comments
 (0)