Skip to content

Commit cc19fbd

Browse files
committed
commenting, improving readability
1 parent 83ea386 commit cc19fbd

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataDataStreamsService.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,8 @@ public Tuple<ClusterState, ClusterStateAckListener> executeTask(
155155
ProjectMetadata.Builder projectMetadataBuilder = ProjectMetadata.builder(projectMetadata);
156156
projectMetadataBuilder.removeDataStream(updateSettingsTask.dataStreamName);
157157
projectMetadataBuilder.put(dataStream);
158-
return new Tuple<>(
159-
ClusterState.builder(clusterState).putProjectMetadata(projectMetadataBuilder).build(),
160-
updateSettingsTask
161-
);
158+
ClusterState updatedClusterState = ClusterState.builder(clusterState).putProjectMetadata(projectMetadataBuilder).build();
159+
return new Tuple<>(updatedClusterState, updateSettingsTask);
162160
}
163161
};
164162
this.updateSettingsTaskQueue = clusterService.createTaskQueue(
@@ -413,6 +411,10 @@ public void updateSettings(
413411
ActionListener<DataStream> listener
414412
) {
415413
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+
*/
416418
try {
417419
DataStream updatedDataStream = createDataStreamForUpdatedDataStreamSettings(
418420
projectId,
@@ -437,6 +439,10 @@ public void updateSettings(
437439
}
438440
}
439441

442+
/*
443+
* This method validates that the settings won't cause any validation problems with existing templates. If successful, a copy of the
444+
* data stream is returned with the new settings applied.
445+
*/
440446
private DataStream createDataStreamForUpdatedDataStreamSettings(
441447
ProjectId projectId,
442448
String dataStreamName,
@@ -722,21 +728,13 @@ static class UpdateSettingsTask extends AckedBatchedClusterStateUpdateTask {
722728
TimeValue ackTimeout,
723729
ActionListener<DataStream> listener
724730
) {
725-
super(ackTimeout, new ActionListener<>() {
726-
@Override
727-
public void onResponse(AcknowledgedResponse response) {
728-
if (response.isAcknowledged()) {
729-
listener.onResponse(clusterService.state().projectState(projectId).metadata().dataStreams().get(dataStreamName));
730-
} else {
731-
listener.onFailure(new ElasticsearchException("Updating settings not accepted for unknown reasons"));
732-
}
733-
}
734-
735-
@Override
736-
public void onFailure(Exception e) {
737-
listener.onFailure(e);
731+
super(ackTimeout, listener.safeMap(response -> {
732+
if (response.isAcknowledged()) {
733+
return clusterService.state().projectState(projectId).metadata().dataStreams().get(dataStreamName);
734+
} else {
735+
throw new ElasticsearchException("Updating settings not accepted for unknown reasons");
738736
}
739-
});
737+
}));
740738
this.projectId = projectId;
741739
this.dataStreamName = dataStreamName;
742740
this.settingsOverrides = settingsOverrides;

0 commit comments

Comments
 (0)