@@ -151,11 +151,16 @@ public Tuple<ClusterState, ClusterStateAckListener> executeTask(
151151 updateSettingsTask .settingsOverrides ,
152152 clusterState
153153 );
154- ProjectMetadata projectMetadata = clusterState .metadata ().getProject (updateSettingsTask .projectId );
155- ProjectMetadata .Builder projectMetadataBuilder = ProjectMetadata .builder (projectMetadata );
156- projectMetadataBuilder .removeDataStream (updateSettingsTask .dataStreamName );
157- projectMetadataBuilder .put (dataStream );
158- ClusterState updatedClusterState = ClusterState .builder (clusterState ).putProjectMetadata (projectMetadataBuilder ).build ();
154+ final ClusterState updatedClusterState ;
155+ if (updateSettingsTask .dryRun ) {
156+ updatedClusterState = clusterState ;
157+ } else {
158+ ProjectMetadata projectMetadata = clusterState .metadata ().getProject (updateSettingsTask .projectId );
159+ ProjectMetadata .Builder projectMetadataBuilder = ProjectMetadata .builder (projectMetadata );
160+ projectMetadataBuilder .removeDataStream (updateSettingsTask .dataStreamName );
161+ projectMetadataBuilder .put (dataStream );
162+ updatedClusterState = ClusterState .builder (clusterState ).putProjectMetadata (projectMetadataBuilder ).build ();
163+ }
159164 return new Tuple <>(updatedClusterState , updateSettingsTask );
160165 }
161166 };
@@ -410,33 +415,16 @@ public void updateSettings(
410415 boolean dryRun ,
411416 ActionListener <DataStream > listener
412417 ) {
413- if (dryRun ) {
414- /*
415- * If this is a dry run, we'll do the settings validation and apply the changes to the data stream locally, but we won't run
416- * the task that actually updates the cluster state.
417- */
418- try {
419- DataStream updatedDataStream = createDataStreamForUpdatedDataStreamSettings (
420- projectId ,
421- dataStreamName ,
422- settingsOverrides ,
423- clusterService .state ()
424- );
425- listener .onResponse (updatedDataStream );
426- } catch (Exception e ) {
427- listener .onFailure (e );
428- }
429- } else {
430- UpdateSettingsTask updateSettingsTask = new UpdateSettingsTask (
431- projectId ,
432- dataStreamName ,
433- settingsOverrides ,
434- clusterService ,
435- ackTimeout ,
436- listener
437- );
438- updateSettingsTaskQueue .submitTask ("updating settings on data stream" , updateSettingsTask , masterNodeTimeout );
439- }
418+ UpdateSettingsTask updateSettingsTask = new UpdateSettingsTask (
419+ projectId ,
420+ dataStreamName ,
421+ settingsOverrides ,
422+ dryRun ,
423+ clusterService ,
424+ ackTimeout ,
425+ listener
426+ );
427+ updateSettingsTaskQueue .submitTask ("updating settings on data stream" , updateSettingsTask , masterNodeTimeout );
440428 }
441429
442430 /*
@@ -562,8 +550,8 @@ private static IndexAbstraction validateIndex(ProjectMetadata project, String in
562550 * Removes the given data stream and their backing indices from the Project State.
563551 *
564552 * @param projectState The project state
565- * @param dataStreams The data streams to remove
566- * @param settings The settings
553+ * @param dataStreams The data streams to remove
554+ * @param settings The settings
567555 * @return The updated Project State
568556 */
569557 public static ClusterState deleteDataStreams (ProjectState projectState , Set <DataStream > dataStreams , Settings settings ) {
@@ -719,11 +707,13 @@ static class UpdateSettingsTask extends AckedBatchedClusterStateUpdateTask {
719707 final ProjectId projectId ;
720708 private final String dataStreamName ;
721709 private final Settings settingsOverrides ;
710+ private final boolean dryRun ;
722711
723712 UpdateSettingsTask (
724713 ProjectId projectId ,
725714 String dataStreamName ,
726715 Settings settingsOverrides ,
716+ boolean dryRun ,
727717 ClusterService clusterService ,
728718 TimeValue ackTimeout ,
729719 ActionListener <DataStream > listener
@@ -738,6 +728,7 @@ static class UpdateSettingsTask extends AckedBatchedClusterStateUpdateTask {
738728 this .projectId = projectId ;
739729 this .dataStreamName = dataStreamName ;
740730 this .settingsOverrides = settingsOverrides ;
731+ this .dryRun = dryRun ;
741732 }
742733 }
743734}
0 commit comments