Procházet zdrojové kódy

Accept `ProjectMetadata` in `RestoreSnapshotStateTask.updater` (#134369)

As preparation for refactoring `Metadata.Builder` to hold a map of
_built_ `ProjectMetadata` objects instead of their builders, we need to
refactor this `updater` consumer to accept a project builder. This
avoids us having to build an intermediate project, add it to the
metadata builder, then convert the project back to a builder and build
it again.
Niels Bauman před 1 měsícem
rodič
revize
5051a5b068

+ 8 - 8
server/src/main/java/org/elasticsearch/snapshots/RestoreService.java

@@ -267,14 +267,14 @@ public final class RestoreService implements ClusterStateApplier {
      * @param projectId project for the restore
      * @param request  restore request
      * @param listener restore listener
-     * @param updater  handler that allows callers to make modifications to {@link Metadata}
+     * @param updater  handler that allows callers to make modifications to {@link ProjectMetadata}
      *                 in the same cluster state update as the restore operation
      */
     public void restoreSnapshot(
         final ProjectId projectId,
         final RestoreSnapshotRequest request,
         final ActionListener<RestoreCompletionResponse> listener,
-        final BiConsumer<ClusterState, Metadata.Builder> updater
+        final BiConsumer<ClusterState, ProjectMetadata.Builder> updater
     ) {
         assert Repository.assertSnapshotMetaThread();
 
@@ -368,8 +368,8 @@ public final class RestoreService implements ClusterStateApplier {
      * @param repository     the repository to restore from
      * @param request        restore request
      * @param repositoryData current repository data for the repository to restore from
-     * @param updater        handler that allows callers to make modifications to {@link Metadata} in the same cluster state update as the
-     *                       restore operation
+     * @param updater        handler that allows callers to make modifications to {@link ProjectMetadata} in the same cluster state update
+     *                       as the restore operation
      * @param listener       listener to resolve once restore has been started
      * @throws IOException   on failure to load metadata from the repository
      */
@@ -378,7 +378,7 @@ public final class RestoreService implements ClusterStateApplier {
         Repository repository,
         RestoreSnapshotRequest request,
         RepositoryData repositoryData,
-        BiConsumer<ClusterState, Metadata.Builder> updater,
+        BiConsumer<ClusterState, ProjectMetadata.Builder> updater,
         ActionListener<RestoreCompletionResponse> listener
     ) throws IOException {
         assert Repository.assertSnapshotMetaThread();
@@ -1371,7 +1371,7 @@ public final class RestoreService implements ClusterStateApplier {
 
         private final Collection<DataStream> dataStreamsToRestore;
 
-        private final BiConsumer<ClusterState, Metadata.Builder> updater;
+        private final BiConsumer<ClusterState, ProjectMetadata.Builder> updater;
 
         private final AllocationActionListener<RestoreCompletionResponse> listener;
         private final Settings settings;
@@ -1387,7 +1387,7 @@ public final class RestoreService implements ClusterStateApplier {
             SnapshotInfo snapshotInfo,
             Metadata metadata,
             Collection<DataStream> dataStreamsToRestore,
-            BiConsumer<ClusterState, Metadata.Builder> updater,
+            BiConsumer<ClusterState, ProjectMetadata.Builder> updater,
             Settings settings,
             ActionListener<RestoreCompletionResponse> listener
         ) {
@@ -1586,7 +1586,7 @@ public final class RestoreService implements ClusterStateApplier {
                 );
             }
 
-            updater.accept(currentState, mdBuilder);
+            updater.accept(currentState, mdBuilder.getProject(projectId));
             final ClusterState updatedClusterState = builder.metadata(mdBuilder)
                 .blocks(blocks)
                 .putRoutingTable(projectId, rtBuilder.build())

+ 3 - 4
x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java

@@ -212,16 +212,16 @@ public final class TransportPutFollowAction extends TransportMasterNodeAction<Pu
             description = "CCR may not be in scope for multi-project though we haven't made the decision explicitly yet. See also ES-12139"
         )
         final ProjectId projectId = ProjectId.DEFAULT;
-        final BiConsumer<ClusterState, Metadata.Builder> updater;
+        final BiConsumer<ClusterState, ProjectMetadata.Builder> updater;
         if (remoteDataStream == null) {
             // If the index we're following is not part of a data stream, start the
             // restoration of the index normally.
-            updater = (clusterState, mdBuilder) -> {};
+            updater = (clusterState, projectBuilder) -> {};
         } else {
             String followerIndexName = request.getFollowerIndex();
             // This method is used to update the metadata in the same cluster state
             // update as the snapshot is restored.
-            updater = (currentState, mdBuilder) -> {
+            updater = (currentState, projectBuilder) -> {
                 final String localDataStreamName;
 
                 // If we have been given a data stream name, use that name for the local
@@ -234,7 +234,6 @@ public final class TransportPutFollowAction extends TransportMasterNodeAction<Pu
                     // There was no specified name, use the original data stream name.
                     localDataStreamName = remoteDataStream.getName();
                 }
-                final ProjectMetadata.Builder projectBuilder = mdBuilder.getProject(projectId);
                 final DataStream localDataStream = projectBuilder.dataStream(localDataStreamName);
                 final Index followerIndex = projectBuilder.get(followerIndexName).getIndex();
                 assert followerIndex != null : "expected followerIndex " + followerIndexName + " to exist in the state, but it did not";