|
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(); |
@@ -499,7 +497,7 @@ private boolean checkPartial(String index) { |
499 | 497 | } |
500 | 498 |
|
501 | 499 | private void validateExistingIndex(IndexMetadata currentIndexMetadata, IndexMetadata snapshotIndexMetadata, |
502 | | - String renamedIndex, boolean partial) { |
| 500 | + String renamedIndex, boolean partial) { |
503 | 501 | // Index exist - checking that it's closed |
504 | 502 | if (currentIndexMetadata.getState() != IndexMetadata.State.CLOSE) { |
505 | 503 | // TODO: Enable restore for open indices |
@@ -594,6 +592,10 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS |
594 | 592 | } |
595 | 593 | }); |
596 | 594 | }, listener::onFailure); |
| 595 | + // fork handling the above listener to the generic pool since it loads various pieces of metadata from the repository over a |
| 596 | + // longer period of time |
| 597 | + repository.getRepositoryData(new ThreadedActionListener<>(logger, clusterService.getClusterApplierService().threadPool(), |
| 598 | + ThreadPool.Names.GENERIC, repoDataListener, false)); |
597 | 599 | } catch (Exception e) { |
598 | 600 | logger.warn(() -> new ParameterizedMessage("[{}] failed to restore snapshot", |
599 | 601 | request.repository() + ":" + request.snapshot()), e); |
|
0 commit comments