Skip to content

Commit 1a9d584

Browse files
authored
Fix #90558 by resolving the backing index name earlier in the process (#90563) (#90587)
1 parent 994c3c6 commit 1a9d584

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

x-pack/plugin/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ public void testSnapshotAndRestoreInPlace() {
271271
RolloverRequest rolloverRequest = new RolloverRequest("ds", null);
272272
RolloverResponse rolloverResponse = client.admin().indices().rolloverIndex(rolloverRequest).actionGet();
273273
assertThat(rolloverResponse.isRolledOver(), is(true));
274-
assertThat(rolloverResponse.getNewIndex(), equalTo(DataStream.getDefaultBackingIndexName("ds", 2)));
274+
String backingIndexAfterSnapshot = DataStream.getDefaultBackingIndexName("ds", 2);
275+
assertThat(rolloverResponse.getNewIndex(), equalTo(backingIndexAfterSnapshot));
275276

276277
// Close all backing indices of ds data stream:
277278
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(".ds-ds-*");
@@ -302,7 +303,7 @@ public void testSnapshotAndRestoreInPlace() {
302303
assertThat(backingIndices.stream().map(Index::getName).collect(Collectors.toList()), contains(equalTo(dsBackingIndexName)));
303304

304305
// The backing index created as part of rollover should still exist (but just not part of the data stream)
305-
assertThat(indexExists(DataStream.getDefaultBackingIndexName("ds", 2)), is(true));
306+
assertThat(indexExists(backingIndexAfterSnapshot), is(true));
306307
// An additional rollover should create a new backing index (3th generation) and leave .ds-ds-...-2 index as is:
307308
rolloverRequest = new RolloverRequest("ds", null);
308309
rolloverResponse = client.admin().indices().rolloverIndex(rolloverRequest).actionGet();
@@ -883,6 +884,11 @@ public void testDeleteDataStreamDuringSnapshot() throws Exception {
883884
}
884885
refresh();
885886
assertDocCount(dataStream, 100L);
887+
// Resolve backing index name after the data stream has been created because it has a date component,
888+
// and running around midnight could lead to test failures otherwise
889+
GetDataStreamAction.Request getDataStreamRequest = new GetDataStreamAction.Request(new String[] { dataStream });
890+
GetDataStreamAction.Response getDataStreamResponse = client.execute(GetDataStreamAction.INSTANCE, getDataStreamRequest).actionGet();
891+
String backingIndexName = getDataStreamResponse.getDataStreams().get(0).getDataStream().getIndices().get(0).getName();
886892

887893
logger.info("--> snapshot");
888894
ActionFuture<CreateSnapshotResponse> future = client1.admin()
@@ -913,7 +919,7 @@ public void testDeleteDataStreamDuringSnapshot() throws Exception {
913919
SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo();
914920
assertThat(snapshotInfo.state(), equalTo((SnapshotState.SUCCESS)));
915921
assertThat(snapshotInfo.dataStreams(), contains(dataStream));
916-
assertThat(snapshotInfo.indices(), contains(DataStream.getDefaultBackingIndexName(dataStream, 1)));
922+
assertThat(snapshotInfo.indices(), contains(backingIndexName));
917923
}
918924

919925
public void testCloneSnapshotThatIncludesDataStream() throws Exception {

0 commit comments

Comments
 (0)