Ver código fonte

Resolve repo earlier in `TransportGetSnapshotsAction` (#110863)

While it is _technically_ true that we only need to look up the
`Repository` instance in order to load `SnapshotInfo` blobs for
snapshots that aren't currently running, in practice the repository
should exist on all paths anyway, the lookup is cheap, and it simplifies
some future work to resolve it sooner.
David Turner 1 ano atrás
pai
commit
787b9336cd

+ 4 - 10
server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java

@@ -280,10 +280,11 @@ public class TransportGetSnapshotsAction extends TransportMasterNodeAction<GetSn
             assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.MANAGEMENT);
 
             cancellableTask.ensureNotCancelled();
+            final var repository = repositoriesService.repository(repositoryName);
             ensureRequiredNamesPresent(repositoryName, repositoryData);
 
             if (verbose) {
-                loadSnapshotInfos(repositoryName, getSnapshotIdIterator(repositoryName, repositoryData), listener);
+                loadSnapshotInfos(repository, getSnapshotIdIterator(repositoryName, repositoryData), listener);
             } else {
                 assert fromSortValuePredicates.isMatchAll() : "filtering is not supported in non-verbose mode";
                 assert slmPolicyPredicate == SlmPolicyPredicate.MATCH_ALL_POLICIES : "filtering is not supported in non-verbose mode";
@@ -362,10 +363,11 @@ public class TransportGetSnapshotsAction extends TransportMasterNodeAction<GetSn
             );
         }
 
-        private void loadSnapshotInfos(String repositoryName, Iterator<SnapshotId> snapshotIdIterator, ActionListener<Void> listener) {
+        private void loadSnapshotInfos(Repository repository, Iterator<SnapshotId> snapshotIdIterator, ActionListener<Void> listener) {
             if (cancellableTask.notifyIfCancelled(listener)) {
                 return;
             }
+            final var repositoryName = repository.getMetadata().name();
             final AtomicInteger repositoryTotalCount = new AtomicInteger();
             final Set<SnapshotId> snapshotIdsToIterate = new HashSet<>();
             snapshotIdIterator.forEachRemaining(snapshotIdsToIterate::add);
@@ -397,14 +399,6 @@ public class TransportGetSnapshotsAction extends TransportMasterNodeAction<GetSn
                             return;
                         }
 
-                        final Repository repository;
-                        try {
-                            repository = repositoriesService.repository(repositoryName);
-                        } catch (RepositoryMissingException e) {
-                            listeners.acquire().onFailure(e);
-                            return;
-                        }
-
                         // only need to synchronize accesses related to reading SnapshotInfo from the repo
                         final List<SnapshotInfo> syncSnapshots = Collections.synchronizedList(snapshots);