Skip to content

Commit b7aba70

Browse files
authored
Merge branch 'main' into esql-MV_CONTAINS_ALL
2 parents 445e7bb + 640bf4e commit b7aba70

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,21 @@ public void testUpgradeDataStream() throws Exception {
208208
createDataStreamFromNonDataStreamIndices(dataStreamFromNonDataStreamIndices);
209209
} else if (CLUSTER_TYPE == ClusterType.UPGRADED) {
210210
Map<String, Map<String, Object>> oldIndicesMetadata = getIndicesMetadata(dataStreamName);
211+
String oldWriteIndex = getDataStreamBackingIndexNames(dataStreamName).getLast();
211212
upgradeDataStream(dataStreamName, numRollovers, numRollovers + 1, 0, ilmEnabled);
212213
cancelReindexTask(dataStreamName);
213214
upgradeDataStream(dataStreamFromNonDataStreamIndices, 0, 1, 0, ilmEnabled);
214215
cancelReindexTask(dataStreamFromNonDataStreamIndices);
215216
Map<String, Map<String, Object>> upgradedIndicesMetadata = getIndicesMetadata(dataStreamName);
217+
String newWriteIndex = getDataStreamBackingIndexNames(dataStreamName).getLast();
216218

217219
if (ilmEnabled) {
218-
checkILMPhase(dataStreamName, upgradedIndicesMetadata);
220+
checkILMPhase(dataStreamName, newWriteIndex);
219221
// Delete the data streams to avoid ILM continuously running cluster state tasks, see
220222
// https://github.com/elastic/elasticsearch/issues/129097#issuecomment-3016122739
221223
deleteDataStream(dataStreamName);
222224
} else {
223-
compareIndexMetadata(oldIndicesMetadata, upgradedIndicesMetadata);
225+
compareIndexMetadata(oldIndicesMetadata, oldWriteIndex, upgradedIndicesMetadata);
224226
}
225227
}
226228
}
@@ -262,9 +264,9 @@ private void cancelReindexTask(String dataStreamName) throws IOException {
262264

263265
private void compareIndexMetadata(
264266
Map<String, Map<String, Object>> oldIndicesMetadata,
267+
String oldWriteIndex,
265268
Map<String, Map<String, Object>> upgradedIndicesMetadata
266269
) {
267-
String oldWriteIndex = getWriteIndexFromDataStreamIndexMetadata(oldIndicesMetadata);
268270
for (Map.Entry<String, Map<String, Object>> upgradedIndexEntry : upgradedIndicesMetadata.entrySet()) {
269271
String upgradedIndexName = upgradedIndexEntry.getKey();
270272
if (upgradedIndexName.startsWith(".migrated-")) {
@@ -287,10 +289,8 @@ private void compareIndexMetadata(
287289
}
288290

289291
@SuppressWarnings("unchecked")
290-
private void checkILMPhase(String dataStreamName, Map<String, Map<String, Object>> upgradedIndicesMetadata) throws Exception {
291-
var writeIndex = getWriteIndexFromDataStreamIndexMetadata(upgradedIndicesMetadata);
292+
private void checkILMPhase(String dataStreamName, String writeIndex) throws Exception {
292293
assertBusy(() -> {
293-
294294
Request request = new Request("GET", dataStreamName + "/_ilm/explain");
295295
Response response = client().performRequest(request);
296296
Map<String, Object> responseMap = XContentHelper.convertToMap(
@@ -302,21 +302,12 @@ private void checkILMPhase(String dataStreamName, Map<String, Map<String, Object
302302
for (var index : indices.keySet()) {
303303
if (index.equals(writeIndex) == false) {
304304
Map<String, Object> ilmInfo = (Map<String, Object>) indices.get(index);
305-
assertThat("Index has not moved to cold ILM phase", ilmInfo.get("phase"), equalTo("cold"));
305+
assertThat("Index [" + index + "] has not moved to cold ILM phase, " + indices, ilmInfo.get("phase"), equalTo("cold"));
306306
}
307307
}
308308
}, 30, TimeUnit.SECONDS);
309309
}
310310

311-
private String getWriteIndexFromDataStreamIndexMetadata(Map<String, Map<String, Object>> indexMetadataForDataStream) {
312-
return indexMetadataForDataStream.entrySet()
313-
.stream()
314-
.sorted((o1, o2) -> Long.compare(getCreationDate(o2.getValue()), getCreationDate(o1.getValue())))
315-
.map(Map.Entry::getKey)
316-
.findFirst()
317-
.get();
318-
}
319-
320311
private void startILM() throws IOException {
321312
setILMInterval();
322313
var request = new Request("POST", "/_ilm/start");

0 commit comments

Comments
 (0)