From 85767fcde1e64bda6cf9dcd0ed405b8eed13f478 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 19 Dec 2024 14:14:04 -0600 Subject: [PATCH 1/3] making number of data stream rollovers random --- .../java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java index 58556dd420ca6..40076b5174ccf 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java @@ -174,7 +174,7 @@ public void testDataStreamValidationDoesNotBreakUpgrade() throws Exception { public void testUpgradeDataStream() throws Exception { String dataStreamName = "reindex_test_data_stream"; - int numRollovers = 5; + int numRollovers = randomIntBetween(0, 5); if (CLUSTER_TYPE == ClusterType.OLD) { createAndRolloverDataStream(dataStreamName, numRollovers); } else if (CLUSTER_TYPE == ClusterType.UPGRADED) { From 634c3638ff22599208598e2a1a619cb54a348890 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 19 Dec 2024 14:16:56 -0600 Subject: [PATCH 2/3] adding additional assertons --- .../org/elasticsearch/upgrades/DataStreamsUpgradeIT.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java index 40076b5174ccf..f156fc55aa2d5 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java @@ -274,10 +274,17 @@ private void upgradeDataStream(String dataStreamName, int numRollovers) throws E ); assertOK(statusResponse); assertThat(statusResponseMap.get("complete"), equalTo(true)); + /* + * total_indices_in_data_stream is determined at the beginning of the reindex, and does not take into account the write + * index being rolled over + */ + assertThat(statusResponseMap.get("total_indices_in_data_stream"), equalTo(numRollovers + 1)); if (isOriginalClusterCurrent()) { // If the original cluster was the same as this one, we don't want any indices reindexed: + assertThat(statusResponseMap.get("total_indices_requiring_upgrade"), equalTo(0)); assertThat(statusResponseMap.get("successes"), equalTo(0)); } else { + assertThat(statusResponseMap.get("total_indices_requiring_upgrade"), equalTo(numRollovers + 1)); assertThat(statusResponseMap.get("successes"), equalTo(numRollovers + 1)); } }, 60, TimeUnit.SECONDS); From 34755e3633c1b857144e3a196df558b67ea8424d Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 19 Dec 2024 14:20:39 -0600 Subject: [PATCH 3/3] no data stream upgrade expected from same major version --- .../upgrades/DataStreamsUpgradeIT.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java index f156fc55aa2d5..3ce92ea29ec19 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/DataStreamsUpgradeIT.java @@ -7,6 +7,8 @@ package org.elasticsearch.upgrades; import org.apache.http.util.EntityUtils; +import org.elasticsearch.Build; +import org.elasticsearch.Version; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; import org.elasticsearch.cluster.metadata.DataStream; @@ -279,7 +281,7 @@ private void upgradeDataStream(String dataStreamName, int numRollovers) throws E * index being rolled over */ assertThat(statusResponseMap.get("total_indices_in_data_stream"), equalTo(numRollovers + 1)); - if (isOriginalClusterCurrent()) { + if (isOriginalClusterSameMajorVersionAsCurrent()) { // If the original cluster was the same as this one, we don't want any indices reindexed: assertThat(statusResponseMap.get("total_indices_requiring_upgrade"), equalTo(0)); assertThat(statusResponseMap.get("successes"), equalTo(0)); @@ -293,6 +295,18 @@ private void upgradeDataStream(String dataStreamName, int numRollovers) throws E assertOK(cancelResponse); } + /* + * Similar to isOriginalClusterCurrent, but returns true if the major versions of the clusters are the same. So true + * for 8.6 and 8.17, but false for 7.17 and 8.18. + */ + private boolean isOriginalClusterSameMajorVersionAsCurrent() { + /* + * Since data stream reindex is specifically about upgrading a data stream from one major version to the next, it's ok to use the + * deprecated Version.fromString here + */ + return Version.fromString(UPGRADE_FROM_VERSION).major == Version.fromString(Build.current().version()).major; + } + private static void bulkLoadData(String dataStreamName) throws IOException { final String bulk = """ {"create": {}}