|
16 | 16 | import org.apache.logging.log4j.message.ParameterizedMessage; |
17 | 17 | import org.elasticsearch.Version; |
18 | 18 | import org.elasticsearch.action.ActionListener; |
19 | | -import org.elasticsearch.action.StepListener; |
20 | 19 | import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; |
21 | 20 | import org.elasticsearch.action.support.IndicesOptions; |
| 21 | +import org.elasticsearch.action.support.ThreadedActionListener; |
22 | 22 | import org.elasticsearch.cluster.ClusterChangedEvent; |
23 | 23 | import org.elasticsearch.cluster.ClusterState; |
24 | 24 | import org.elasticsearch.cluster.ClusterStateApplier; |
|
66 | 66 | import org.elasticsearch.repositories.RepositoriesService; |
67 | 67 | import org.elasticsearch.repositories.Repository; |
68 | 68 | import org.elasticsearch.repositories.RepositoryData; |
| 69 | +import org.elasticsearch.threadpool.ThreadPool; |
69 | 70 |
|
70 | 71 | import java.util.ArrayList; |
71 | 72 | import java.util.Arrays; |
@@ -152,8 +153,7 @@ public class RestoreService implements ClusterStateApplier { |
152 | 153 |
|
153 | 154 | public RestoreService(ClusterService clusterService, RepositoriesService repositoriesService, |
154 | 155 | AllocationService allocationService, MetadataCreateIndexService createIndexService, |
155 | | - IndexMetadataVerifier indexMetadataVerifier, ClusterSettings clusterSettings, |
156 | | - ShardLimitValidator shardLimitValidator) { |
| 156 | + IndexMetadataVerifier indexMetadataVerifier, ShardLimitValidator shardLimitValidator) { |
157 | 157 | this.clusterService = clusterService; |
158 | 158 | this.repositoriesService = repositoriesService; |
159 | 159 | this.allocationService = allocationService; |
@@ -191,9 +191,7 @@ public void restoreSnapshot(final RestoreSnapshotRequest request, |
191 | 191 | // Read snapshot info and metadata from the repository |
192 | 192 | final String repositoryName = request.repository(); |
193 | 193 | Repository repository = repositoriesService.repository(repositoryName); |
194 | | - final StepListener<RepositoryData> repositoryDataListener = new StepListener<>(); |
195 | | - repository.getRepositoryData(repositoryDataListener); |
196 | | - repositoryDataListener.whenComplete(repositoryData -> { |
| 194 | + ActionListener<RepositoryData> repoDataListener = ActionListener.wrap(repositoryData -> { |
197 | 195 | final String snapshotName = request.snapshot(); |
198 | 196 | final Optional<SnapshotId> matchingSnapshotId = repositoryData.getSnapshotIds().stream() |
199 | 197 | .filter(s -> snapshotName.equals(s.getName())).findFirst(); |
@@ -515,7 +513,7 @@ private boolean checkPartial(String index) { |
515 | 513 | } |
516 | 514 |
|
517 | 515 | private void validateExistingIndex(IndexMetadata currentIndexMetadata, IndexMetadata snapshotIndexMetadata, |
518 | | - String renamedIndex, boolean partial) { |
| 516 | + String renamedIndex, boolean partial) { |
519 | 517 | // Index exist - checking that it's closed |
520 | 518 | if (currentIndexMetadata.getState() != IndexMetadata.State.CLOSE) { |
521 | 519 | // TODO: Enable restore for open indices |
@@ -610,6 +608,10 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS |
610 | 608 | } |
611 | 609 | }); |
612 | 610 | }, listener::onFailure); |
| 611 | + // fork handling the above listener to the generic pool since it loads various pieces of metadata from the repository over a |
| 612 | + // longer period of time |
| 613 | + repository.getRepositoryData(new ThreadedActionListener<>(logger, clusterService.getClusterApplierService().threadPool(), |
| 614 | + ThreadPool.Names.GENERIC, repoDataListener, false)); |
613 | 615 | } catch (Exception e) { |
614 | 616 | logger.warn(() -> new ParameterizedMessage("[{}] failed to restore snapshot", |
615 | 617 | request.repository() + ":" + request.snapshot()), e); |
|
0 commit comments