77package org .elasticsearch .upgrades ;
88
99import org .apache .http .util .EntityUtils ;
10+ import org .elasticsearch .Build ;
11+ import org .elasticsearch .Version ;
1012import org .elasticsearch .client .Request ;
1113import org .elasticsearch .client .Response ;
1214import org .elasticsearch .cluster .metadata .DataStream ;
@@ -174,7 +176,7 @@ public void testDataStreamValidationDoesNotBreakUpgrade() throws Exception {
174176
175177 public void testUpgradeDataStream () throws Exception {
176178 String dataStreamName = "reindex_test_data_stream" ;
177- int numRollovers = 5 ;
179+ int numRollovers = randomIntBetween ( 0 , 5 ) ;
178180 if (CLUSTER_TYPE == ClusterType .OLD ) {
179181 createAndRolloverDataStream (dataStreamName , numRollovers );
180182 } else if (CLUSTER_TYPE == ClusterType .UPGRADED ) {
@@ -274,10 +276,17 @@ private void upgradeDataStream(String dataStreamName, int numRollovers) throws E
274276 );
275277 assertOK (statusResponse );
276278 assertThat (statusResponseMap .get ("complete" ), equalTo (true ));
277- if (isOriginalClusterCurrent ()) {
279+ /*
280+ * total_indices_in_data_stream is determined at the beginning of the reindex, and does not take into account the write
281+ * index being rolled over
282+ */
283+ assertThat (statusResponseMap .get ("total_indices_in_data_stream" ), equalTo (numRollovers + 1 ));
284+ if (isOriginalClusterSameMajorVersionAsCurrent ()) {
278285 // If the original cluster was the same as this one, we don't want any indices reindexed:
286+ assertThat (statusResponseMap .get ("total_indices_requiring_upgrade" ), equalTo (0 ));
279287 assertThat (statusResponseMap .get ("successes" ), equalTo (0 ));
280288 } else {
289+ assertThat (statusResponseMap .get ("total_indices_requiring_upgrade" ), equalTo (numRollovers + 1 ));
281290 assertThat (statusResponseMap .get ("successes" ), equalTo (numRollovers + 1 ));
282291 }
283292 }, 60 , TimeUnit .SECONDS );
@@ -286,6 +295,18 @@ private void upgradeDataStream(String dataStreamName, int numRollovers) throws E
286295 assertOK (cancelResponse );
287296 }
288297
298+ /*
299+ * Similar to isOriginalClusterCurrent, but returns true if the major versions of the clusters are the same. So true
300+ * for 8.6 and 8.17, but false for 7.17 and 8.18.
301+ */
302+ private boolean isOriginalClusterSameMajorVersionAsCurrent () {
303+ /*
304+ * Since data stream reindex is specifically about upgrading a data stream from one major version to the next, it's ok to use the
305+ * deprecated Version.fromString here
306+ */
307+ return Version .fromString (UPGRADE_FROM_VERSION ).major == Version .fromString (Build .current ().version ()).major ;
308+ }
309+
289310 private static void bulkLoadData (String dataStreamName ) throws IOException {
290311 final String bulk = """
291312 {"create": {}}
0 commit comments