Skip to content

Commit 0ef2344

Browse files
committed
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
1 parent 3295149 commit 0ef2344

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
package org.elasticsearch.xpack.ilm;
99

10+
import org.apache.lucene.util.SetOnce;
1011
import org.elasticsearch.client.Request;
1112
import org.elasticsearch.client.Response;
1213
import org.elasticsearch.client.WarningFailureException;
13-
import org.elasticsearch.cluster.metadata.DataStream;
1414
import org.elasticsearch.cluster.metadata.IndexMetadata;
1515
import org.elasticsearch.cluster.metadata.Template;
1616
import org.elasticsearch.common.xcontent.XContentHelper;
@@ -81,20 +81,13 @@ public void testRolloverAction() throws Exception {
8181

8282
indexDocument(client(), dataStream, true);
8383

84-
assertBusy(() -> assertTrue(indexExists(DataStream.getDefaultBackingIndexName(dataStream, 2))));
85-
assertBusy(
86-
() -> assertTrue(
87-
Boolean.parseBoolean(
88-
(String) getIndexSettingsAsMap(DataStream.getDefaultBackingIndexName(dataStream, 2)).get("index.hidden")
89-
)
90-
)
91-
);
92-
assertBusy(
93-
() -> assertThat(
94-
getStepKeyForIndex(client(), DataStream.getDefaultBackingIndexName(dataStream, 1)),
95-
equalTo(PhaseCompleteStep.finalStep("hot").getKey())
96-
)
97-
);
84+
assertBusy(() -> {
85+
final var backingIndices = getBackingIndices(client(), dataStream);
86+
assertEquals(2, backingIndices.size());
87+
final var writeIndex = backingIndices.getFirst();
88+
assertTrue(Boolean.parseBoolean((String) getIndexSettingsAsMap(writeIndex).get("index.hidden")));
89+
assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), writeIndex));
90+
});
9891
}
9992

10093
public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception {
@@ -104,20 +97,24 @@ public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception {
10497

10598
indexDocument(client(), dataStream, true);
10699

107-
String firstGenerationIndex = DataStream.getDefaultBackingIndexName(dataStream, 1);
108-
assertBusy(
109-
() -> assertThat(getStepKeyForIndex(client(), firstGenerationIndex).name(), equalTo(WaitForRolloverReadyStep.NAME)),
110-
30,
111-
TimeUnit.SECONDS
112-
);
100+
final var firstGenerationIndex = new SetOnce<String>();
101+
assertBusy(() -> {
102+
final var backingIndices = getBackingIndices(client(), dataStream);
103+
assertEquals(1, backingIndices.size());
104+
assertEquals(WaitForRolloverReadyStep.NAME, getStepKeyForIndex(client(), backingIndices.getFirst()).name());
105+
firstGenerationIndex.set(backingIndices.getFirst());
106+
}, 30, TimeUnit.SECONDS);
113107

114108
rolloverMaxOneDocCondition(client(), dataStream);
115-
assertBusy(() -> assertThat(indexExists(DataStream.getDefaultBackingIndexName(dataStream, 2)), is(true)), 30, TimeUnit.SECONDS);
109+
assertBusy(() -> {
110+
final var backingIndices = getBackingIndices(client(), dataStream);
111+
assertEquals(2, backingIndices.size());
112+
}, 30, TimeUnit.SECONDS);
116113

117114
// even though the first index doesn't have 2 documents to fulfill the rollover condition, it should complete the rollover action
118115
// because it's not the write index anymore
119116
assertBusy(
120-
() -> assertThat(getStepKeyForIndex(client(), firstGenerationIndex), equalTo(PhaseCompleteStep.finalStep("hot").getKey())),
117+
() -> assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), firstGenerationIndex.get())),
121118
30,
122119
TimeUnit.SECONDS
123120
);
@@ -129,7 +126,7 @@ public void testShrinkActionInPolicyWithoutHotPhase() throws Exception {
129126
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
130127
indexDocument(client(), dataStream, true);
131128

132-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
129+
String backingIndexName = getBackingIndices(client(), dataStream).getFirst();
133130
assertBusy(
134131
() -> assertThat(
135132
"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 {
143140
// Manual rollover the original index such that it's not the write index in the data stream anymore
144141
rolloverMaxOneDocCondition(client(), dataStream);
145142
// Wait for rollover to happen
146-
String rolloverIndex = DataStream.getDefaultBackingIndexName(dataStream, 2);
147-
assertBusy(() -> assertTrue("the rollover action created the rollover index", indexExists(rolloverIndex)), 30, TimeUnit.SECONDS);
143+
assertBusy(
144+
() -> assertEquals("the rollover action created the rollover index", 2, getBackingIndices(client(), dataStream).size()),
145+
30,
146+
TimeUnit.SECONDS
147+
);
148148

149149
String shrunkenIndex = waitAndGetShrinkIndexName(client(), backingIndexName);
150150
assertBusy(() -> assertTrue(indexExists(shrunkenIndex)), 30, TimeUnit.SECONDS);
@@ -160,7 +160,7 @@ public void testSearchableSnapshotAction() throws Exception {
160160
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
161161
indexDocument(client(), dataStream, true);
162162

163-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
163+
String backingIndexName = getBackingIndices(client(), dataStream).getFirst();
164164
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
165165

166166
assertBusy(
@@ -191,7 +191,7 @@ public void testReadOnlyAction() throws Exception {
191191
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
192192
indexDocument(client(), dataStream, true);
193193

194-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
194+
String backingIndexName = getBackingIndices(client(), dataStream).getFirst();
195195
assertBusy(
196196
() -> assertThat(
197197
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
@@ -226,7 +226,7 @@ public void testFreezeAction() throws Exception {
226226
indexDocument(client(), dataStream, true);
227227

228228
// The freeze action is a noop action with only noop steps and should pass through to complete the phase asap.
229-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
229+
String backingIndexName = getBackingIndices(client(), dataStream).getFirst();
230230
assertBusy(() -> {
231231
try {
232232
assertThat(explainIndex(client(), backingIndexName).get("step"), is(PhaseCompleteStep.NAME));
@@ -248,7 +248,7 @@ public void checkForceMergeAction(String codec) throws Exception {
248248
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
249249
indexDocument(client(), dataStream, true);
250250

251-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
251+
String backingIndexName = getBackingIndices(client(), dataStream).getFirst();
252252
assertBusy(
253253
() -> assertThat(
254254
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",

0 commit comments

Comments
 (0)