|
@@ -16,9 +16,9 @@ import org.apache.logging.log4j.Logger;
|
|
|
import org.apache.logging.log4j.message.ParameterizedMessage;
|
|
|
import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.ActionListener;
|
|
|
-import org.elasticsearch.action.StepListener;
|
|
|
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
|
|
|
import org.elasticsearch.action.support.IndicesOptions;
|
|
|
+import org.elasticsearch.action.support.ThreadedActionListener;
|
|
|
import org.elasticsearch.cluster.ClusterChangedEvent;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
import org.elasticsearch.cluster.ClusterStateApplier;
|
|
@@ -66,6 +66,7 @@ import org.elasticsearch.repositories.IndexId;
|
|
|
import org.elasticsearch.repositories.RepositoriesService;
|
|
|
import org.elasticsearch.repositories.Repository;
|
|
|
import org.elasticsearch.repositories.RepositoryData;
|
|
|
+import org.elasticsearch.threadpool.ThreadPool;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
@@ -152,8 +153,7 @@ public class RestoreService implements ClusterStateApplier {
|
|
|
|
|
|
public RestoreService(ClusterService clusterService, RepositoriesService repositoriesService,
|
|
|
AllocationService allocationService, MetadataCreateIndexService createIndexService,
|
|
|
- IndexMetadataVerifier indexMetadataVerifier, ClusterSettings clusterSettings,
|
|
|
- ShardLimitValidator shardLimitValidator) {
|
|
|
+ IndexMetadataVerifier indexMetadataVerifier, ShardLimitValidator shardLimitValidator) {
|
|
|
this.clusterService = clusterService;
|
|
|
this.repositoriesService = repositoriesService;
|
|
|
this.allocationService = allocationService;
|
|
@@ -191,9 +191,7 @@ public class RestoreService implements ClusterStateApplier {
|
|
|
// Read snapshot info and metadata from the repository
|
|
|
final String repositoryName = request.repository();
|
|
|
Repository repository = repositoriesService.repository(repositoryName);
|
|
|
- final StepListener<RepositoryData> repositoryDataListener = new StepListener<>();
|
|
|
- repository.getRepositoryData(repositoryDataListener);
|
|
|
- repositoryDataListener.whenComplete(repositoryData -> {
|
|
|
+ ActionListener<RepositoryData> repoDataListener = ActionListener.wrap(repositoryData -> {
|
|
|
final String snapshotName = request.snapshot();
|
|
|
final Optional<SnapshotId> matchingSnapshotId = repositoryData.getSnapshotIds().stream()
|
|
|
.filter(s -> snapshotName.equals(s.getName())).findFirst();
|
|
@@ -499,7 +497,7 @@ public class RestoreService implements ClusterStateApplier {
|
|
|
}
|
|
|
|
|
|
private void validateExistingIndex(IndexMetadata currentIndexMetadata, IndexMetadata snapshotIndexMetadata,
|
|
|
- String renamedIndex, boolean partial) {
|
|
|
+ String renamedIndex, boolean partial) {
|
|
|
// Index exist - checking that it's closed
|
|
|
if (currentIndexMetadata.getState() != IndexMetadata.State.CLOSE) {
|
|
|
// TODO: Enable restore for open indices
|
|
@@ -594,6 +592,10 @@ public class RestoreService implements ClusterStateApplier {
|
|
|
}
|
|
|
});
|
|
|
}, listener::onFailure);
|
|
|
+ // fork handling the above listener to the generic pool since it loads various pieces of metadata from the repository over a
|
|
|
+ // longer period of time
|
|
|
+ repository.getRepositoryData(new ThreadedActionListener<>(logger, clusterService.getClusterApplierService().threadPool(),
|
|
|
+ ThreadPool.Names.GENERIC, repoDataListener, false));
|
|
|
} catch (Exception e) {
|
|
|
logger.warn(() -> new ParameterizedMessage("[{}] failed to restore snapshot",
|
|
|
request.repository() + ":" + request.snapshot()), e);
|