@@ -357,7 +357,8 @@ public void testMergePolicyNotExecutedForTSIndicesWithinTimeBounds() {
357357 clusterState = ClusterState .builder (clusterState ).putProjectMetadata (builder ).build ();
358358
359359 dataStreamLifecycleService .run (clusterState );
360- // There should be two client requests: one rollover, and one to update the merge policy settings. N.B. The merge policy settings
360+ // There should be two client requests: one rollover, and one to update the merge policy settings. One of the non-write indices is
361+ // still within the time bounds to be written to, so it is not force merged. N.B. The merge policy settings
361362 // will always be updated before the force merge is done, see testMergePolicySettingsAreConfiguredBeforeForcemerge.
362363 assertThat (clientSeenRequests .size (), is (2 ));
363364 assertThat (clientSeenRequests .get (0 ), instanceOf (RolloverRequest .class ));
@@ -961,7 +962,13 @@ public void onFailure(Exception e) {
961962 final var projectId = randomProjectIdOrDefault ();
962963 String targetIndex = randomAlphaOfLength (20 );
963964 DataStreamLifecycleService .UpdateDataStreamLifecycleCustomMetadataTask task =
964- new DataStreamLifecycleService .UpdateDataStreamLifecycleCustomMetadataTask (listener , projectId , targetIndex , threadPool );
965+ new DataStreamLifecycleService .UpdateDataStreamLifecycleCustomMetadataTask (
966+ listener ,
967+ projectId ,
968+ targetIndex ,
969+ FORCE_MERGE_COMPLETED_TIMESTAMP_METADATA_KEY ,
970+ Long .toString (threadPool .absoluteTimeInMillis ())
971+ );
965972 {
966973 Exception exception = new RuntimeException ("task failed" );
967974 task .onFailure (exception );
@@ -1441,14 +1448,19 @@ public void testTimeSeriesIndicesStillWithinTimeBounds() {
14411448 );
14421449 final ProjectState project = clusterState .projectState (projectId );
14431450 DataStream dataStream = project .metadata ().dataStreams ().get (dataStreamName );
1451+ dataStream = dataStream .copy ()
1452+ .setName (dataStreamName )
1453+ .setGeneration (dataStream .getGeneration () + 1 )
1454+ .setLifecycle (DataStreamLifecycle .dataLifecycleBuilder ().dataRetention (TimeValue .ZERO ).build ())
1455+ .build ();
14441456 {
1445- // test for an index for which `now` is outside its time bounds
1446- Index firstGenIndex = dataStream .getIndices ().get (0 );
1457+ // test for an index for which `now` is outside its time bounds by excluding the two that are not
14471458 Set <Index > indices = DataStreamLifecycleService .timeSeriesIndicesStillWithinTimeBounds (
14481459 // the end_time for the first generation has lapsed
14491460 project ,
14501461 dataStream ,
1451- Set .of ()
1462+ Set .of (dataStream .getIndices ().get (1 ), dataStream .getIndices ().get (2 )),
1463+ currentTime ::toEpochMilli
14521464 );
14531465 assertThat (indices .size (), is (0 ));
14541466 }
@@ -1458,21 +1470,43 @@ public void testTimeSeriesIndicesStillWithinTimeBounds() {
14581470 // the end_time for the first generation has lapsed, but the other 2 generations are still within bounds
14591471 project ,
14601472 dataStream ,
1461- Set .of ()
1473+ Set .of (),
1474+ currentTime ::toEpochMilli
14621475 );
14631476 assertThat (indices .size (), is (2 ));
14641477 assertThat (indices , containsInAnyOrder (dataStream .getIndices ().get (1 ), dataStream .getIndices ().get (2 )));
14651478 }
14661479
14671480 {
1481+ ProjectMetadata .Builder projectMetadataBuilder = ProjectMetadata .builder (project .metadata ());
14681482 // non time_series indices are not within time bounds (they don't have any)
1469- IndexMetadata indexMeta = IndexMetadata .builder (randomAlphaOfLengthBetween (10 , 30 ))
1470- .settings (indexSettings (1 , 1 ).put (IndexMetadata .SETTING_INDEX_VERSION_CREATED .getKey (), IndexVersion .current ()))
1471- .build ();
1472-
1473- ProjectState newProject = project .updateProject (ProjectMetadata .builder (project .metadata ()).put (indexMeta , true ).build ());
1483+ for (Index index : dataStream .getIndices ()) {
1484+ IndexMetadata indexMeta = IndexMetadata .builder (index .getName ())
1485+ .settings (
1486+ indexSettings (1 , 1 ).put (IndexMetadata .SETTING_INDEX_VERSION_CREATED .getKey (), IndexVersion .current ())
1487+ .put (IndexSettings .MODE .getKey (), IndexMode .STANDARD )
1488+ )
1489+ .build ();
1490+ projectMetadataBuilder .put (indexMeta , true );
1491+ }
14741492
1475- Set <Index > indices = DataStreamLifecycleService .timeSeriesIndicesStillWithinTimeBounds (newProject , dataStream , Set .of ());
1493+ List <Index > standardIndices = dataStream .getIndices ()
1494+ .stream ()
1495+ .map (index -> new Index (index .getName (), index .getUUID ()))
1496+ .toList ();
1497+ ProjectState newProject = project .updateProject (projectMetadataBuilder .build ());
1498+ dataStream = dataStream .copy ()
1499+ .setName (dataStreamName )
1500+ .setGeneration (dataStream .getGeneration () + 1 )
1501+ .setBackingIndices (DataStream .DataStreamIndices .backingIndicesBuilder (standardIndices ).build ())
1502+ .setIndexMode (IndexMode .STANDARD )
1503+ .build ();
1504+ Set <Index > indices = DataStreamLifecycleService .timeSeriesIndicesStillWithinTimeBounds (
1505+ newProject ,
1506+ dataStream ,
1507+ Set .of (),
1508+ currentTime ::toEpochMilli
1509+ );
14761510 assertThat (indices .size (), is (0 ));
14771511 }
14781512 }
0 commit comments