From 0ef2344b59d83cf49a2f4d7c1d73857718f91a87 Mon Sep 17 00:00:00 2001 From: Niels Bauman Date: Tue, 25 Feb 2025 15:05:39 +0100 Subject: [PATCH 1/4] Fix failing test(s) in `TimeSeriesDataStreamsIT` When these tests were run around midnight, the use of `DataStream#getDefaultBackingIndexName` could result in a potential mismatch in the generated index name and the one that the cluster actually created. Instead, we need to obtain the backing index and extract the desired index name from there. Fixes #123086 Relates #123376 --- .../xpack/ilm/TimeSeriesDataStreamsIT.java | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java index 91afa4da560b5..477149cf4e9dc 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java @@ -7,10 +7,10 @@ package org.elasticsearch.xpack.ilm; +import org.apache.lucene.util.SetOnce; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; import org.elasticsearch.client.WarningFailureException; -import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Template; import org.elasticsearch.common.xcontent.XContentHelper; @@ -81,20 +81,13 @@ public void testRolloverAction() throws Exception { indexDocument(client(), dataStream, true); - assertBusy(() -> assertTrue(indexExists(DataStream.getDefaultBackingIndexName(dataStream, 2)))); - assertBusy( - () -> assertTrue( - Boolean.parseBoolean( - (String) getIndexSettingsAsMap(DataStream.getDefaultBackingIndexName(dataStream, 2)).get("index.hidden") - ) - ) - ); - assertBusy( - () -> assertThat( - getStepKeyForIndex(client(), DataStream.getDefaultBackingIndexName(dataStream, 1)), - equalTo(PhaseCompleteStep.finalStep("hot").getKey()) - ) - ); + assertBusy(() -> { + final var backingIndices = getBackingIndices(client(), dataStream); + assertEquals(2, backingIndices.size()); + final var writeIndex = backingIndices.getFirst(); + assertTrue(Boolean.parseBoolean((String) getIndexSettingsAsMap(writeIndex).get("index.hidden"))); + assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), writeIndex)); + }); } public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception { @@ -104,20 +97,24 @@ public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception { indexDocument(client(), dataStream, true); - String firstGenerationIndex = DataStream.getDefaultBackingIndexName(dataStream, 1); - assertBusy( - () -> assertThat(getStepKeyForIndex(client(), firstGenerationIndex).name(), equalTo(WaitForRolloverReadyStep.NAME)), - 30, - TimeUnit.SECONDS - ); + final var firstGenerationIndex = new SetOnce(); + assertBusy(() -> { + final var backingIndices = getBackingIndices(client(), dataStream); + assertEquals(1, backingIndices.size()); + assertEquals(WaitForRolloverReadyStep.NAME, getStepKeyForIndex(client(), backingIndices.getFirst()).name()); + firstGenerationIndex.set(backingIndices.getFirst()); + }, 30, TimeUnit.SECONDS); rolloverMaxOneDocCondition(client(), dataStream); - assertBusy(() -> assertThat(indexExists(DataStream.getDefaultBackingIndexName(dataStream, 2)), is(true)), 30, TimeUnit.SECONDS); + assertBusy(() -> { + final var backingIndices = getBackingIndices(client(), dataStream); + assertEquals(2, backingIndices.size()); + }, 30, TimeUnit.SECONDS); // even though the first index doesn't have 2 documents to fulfill the rollover condition, it should complete the rollover action // because it's not the write index anymore assertBusy( - () -> assertThat(getStepKeyForIndex(client(), firstGenerationIndex), equalTo(PhaseCompleteStep.finalStep("hot").getKey())), + () -> assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), firstGenerationIndex.get())), 30, TimeUnit.SECONDS ); @@ -129,7 +126,7 @@ public void testShrinkActionInPolicyWithoutHotPhase() throws Exception { createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName)); indexDocument(client(), dataStream, true); - String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1); + String backingIndexName = getBackingIndices(client(), dataStream).getFirst(); assertBusy( () -> assertThat( "original index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore", @@ -143,8 +140,11 @@ public void testShrinkActionInPolicyWithoutHotPhase() throws Exception { // Manual rollover the original index such that it's not the write index in the data stream anymore rolloverMaxOneDocCondition(client(), dataStream); // Wait for rollover to happen - String rolloverIndex = DataStream.getDefaultBackingIndexName(dataStream, 2); - assertBusy(() -> assertTrue("the rollover action created the rollover index", indexExists(rolloverIndex)), 30, TimeUnit.SECONDS); + assertBusy( + () -> assertEquals("the rollover action created the rollover index", 2, getBackingIndices(client(), dataStream).size()), + 30, + TimeUnit.SECONDS + ); String shrunkenIndex = waitAndGetShrinkIndexName(client(), backingIndexName); assertBusy(() -> assertTrue(indexExists(shrunkenIndex)), 30, TimeUnit.SECONDS); @@ -160,7 +160,7 @@ public void testSearchableSnapshotAction() throws Exception { createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName)); indexDocument(client(), dataStream, true); - String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1); + String backingIndexName = getBackingIndices(client(), dataStream).getFirst(); String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName; assertBusy( @@ -191,7 +191,7 @@ public void testReadOnlyAction() throws Exception { createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName)); indexDocument(client(), dataStream, true); - String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1); + String backingIndexName = getBackingIndices(client(), dataStream).getFirst(); assertBusy( () -> assertThat( "index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore", @@ -226,7 +226,7 @@ public void testFreezeAction() throws Exception { indexDocument(client(), dataStream, true); // The freeze action is a noop action with only noop steps and should pass through to complete the phase asap. - String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1); + String backingIndexName = getBackingIndices(client(), dataStream).getFirst(); assertBusy(() -> { try { assertThat(explainIndex(client(), backingIndexName).get("step"), is(PhaseCompleteStep.NAME)); @@ -248,7 +248,7 @@ public void checkForceMergeAction(String codec) throws Exception { createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName)); indexDocument(client(), dataStream, true); - String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1); + String backingIndexName = getBackingIndices(client(), dataStream).getFirst(); assertBusy( () -> assertThat( "index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore", From b338cbcd1fdbecdf0f72df5b0ea443b2c1b0d020 Mon Sep 17 00:00:00 2001 From: Niels Bauman Date: Tue, 25 Feb 2025 16:59:37 +0100 Subject: [PATCH 2/4] Don't use `SetOnce` On second thought, we can just get the backing index directly here as well --- .../xpack/ilm/TimeSeriesDataStreamsIT.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java index 477149cf4e9dc..0085369d9822e 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.ilm; -import org.apache.lucene.util.SetOnce; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; import org.elasticsearch.client.WarningFailureException; @@ -97,14 +96,12 @@ public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception { indexDocument(client(), dataStream, true); - final var firstGenerationIndex = new SetOnce(); - assertBusy(() -> { - final var backingIndices = getBackingIndices(client(), dataStream); - assertEquals(1, backingIndices.size()); - assertEquals(WaitForRolloverReadyStep.NAME, getStepKeyForIndex(client(), backingIndices.getFirst()).name()); - firstGenerationIndex.set(backingIndices.getFirst()); - }, 30, TimeUnit.SECONDS); - + String firstGenerationIndex = getBackingIndices(client(), dataStream).getFirst(); + assertBusy( + () -> assertThat(getStepKeyForIndex(client(), firstGenerationIndex).name(), equalTo(WaitForRolloverReadyStep.NAME)), + 30, + TimeUnit.SECONDS + ); rolloverMaxOneDocCondition(client(), dataStream); assertBusy(() -> { final var backingIndices = getBackingIndices(client(), dataStream); @@ -114,7 +111,7 @@ public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception { // even though the first index doesn't have 2 documents to fulfill the rollover condition, it should complete the rollover action // because it's not the write index anymore assertBusy( - () -> assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), firstGenerationIndex.get())), + () -> assertThat(getStepKeyForIndex(client(), firstGenerationIndex), equalTo(PhaseCompleteStep.finalStep("hot").getKey())), 30, TimeUnit.SECONDS ); From d294e37ab550cee0bc096823cd7ff41f6c0e19a0 Mon Sep 17 00:00:00 2001 From: Niels Bauman Date: Tue, 25 Feb 2025 17:10:38 +0100 Subject: [PATCH 3/4] Fix test --- .../org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java index 0085369d9822e..9c998503dfdbb 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java @@ -83,9 +83,8 @@ public void testRolloverAction() throws Exception { assertBusy(() -> { final var backingIndices = getBackingIndices(client(), dataStream); assertEquals(2, backingIndices.size()); - final var writeIndex = backingIndices.getFirst(); - assertTrue(Boolean.parseBoolean((String) getIndexSettingsAsMap(writeIndex).get("index.hidden"))); - assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), writeIndex)); + assertTrue(Boolean.parseBoolean((String) getIndexSettingsAsMap(backingIndices.getFirst()).get("index.hidden"))); + assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), backingIndices.getLast())); }); } From b08157c6858d55f492f60b1557c0367236b2cf5b Mon Sep 17 00:00:00 2001 From: Niels Bauman Date: Wed, 26 Feb 2025 09:46:30 +0100 Subject: [PATCH 4/4] Fix test for real --- .../elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java index 9c998503dfdbb..cf55fc0e0ac5a 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java @@ -83,8 +83,11 @@ public void testRolloverAction() throws Exception { assertBusy(() -> { final var backingIndices = getBackingIndices(client(), dataStream); assertEquals(2, backingIndices.size()); - assertTrue(Boolean.parseBoolean((String) getIndexSettingsAsMap(backingIndices.getFirst()).get("index.hidden"))); - assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), backingIndices.getLast())); + assertTrue(Boolean.parseBoolean((String) getIndexSettingsAsMap(backingIndices.getLast()).get("index.hidden"))); + }); + assertBusy(() -> { + final var backingIndices = getBackingIndices(client(), dataStream); + assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), backingIndices.getFirst())); }); } @@ -101,6 +104,7 @@ public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception { 30, TimeUnit.SECONDS ); + rolloverMaxOneDocCondition(client(), dataStream); assertBusy(() -> { final var backingIndices = getBackingIndices(client(), dataStream);