Skip to content

Commit

Permalink
[8.x] Fix failing test(s) in TimeSeriesDataStreamsIT (#123378) (#12…
Browse files Browse the repository at this point in the history
…3472)

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
  • Loading branch information
nielsbauman authored Feb 26, 2025
1 parent 78c53db commit 294478a
Showing 1 changed file with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Template;
import org.elasticsearch.common.xcontent.XContentHelper;
Expand Down Expand Up @@ -80,20 +79,15 @@ 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());
assertTrue(Boolean.parseBoolean((String) getIndexSettingsAsMap(backingIndices.get(1)).get("index.hidden")));
});
assertBusy(() -> {
final var backingIndices = getBackingIndices(client(), dataStream);
assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), backingIndices.get(0)));
});
}

public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception {
Expand All @@ -103,15 +97,18 @@ public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception {

indexDocument(client(), dataStream, true);

String firstGenerationIndex = DataStream.getDefaultBackingIndexName(dataStream, 1);
String firstGenerationIndex = getBackingIndices(client(), dataStream).get(0);
assertBusy(
() -> assertThat(getStepKeyForIndex(client(), firstGenerationIndex).name(), equalTo(WaitForRolloverReadyStep.NAME)),
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
Expand All @@ -128,7 +125,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).get(0);
assertBusy(
() -> assertThat(
"original index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
Expand All @@ -142,8 +139,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);
Expand All @@ -159,7 +159,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).get(0);
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;

assertBusy(
Expand Down Expand Up @@ -190,7 +190,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).get(0);
assertBusy(
() -> assertThat(
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
Expand Down Expand Up @@ -220,7 +220,7 @@ public void testFreezeAction() throws Exception {
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
indexDocument(client(), dataStream, true);

String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
assertBusy(
() -> assertThat(
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
Expand Down Expand Up @@ -249,7 +249,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).get(0);
assertBusy(
() -> assertThat(
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
Expand Down

0 comments on commit 294478a

Please sign in to comment.