Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Edge-Case Threading Bug in TransportMountSearchableSnapshotAction #73196

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.elasticsearch.ElasticsearchException;
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.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
import org.elasticsearch.action.support.ActionFilters;
Expand All @@ -26,6 +25,7 @@
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ListenableFuture;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.indices.ShardLimitValidator;
import org.elasticsearch.indices.SystemIndices;
Expand Down Expand Up @@ -103,9 +103,8 @@ public TransportMountSearchableSnapshotAction(
MountSearchableSnapshotRequest::new,
indexNameExpressionResolver,
RestoreSnapshotResponse::new,
// Avoid SNAPSHOT since snapshot threads may all be busy with long-running tasks which would block this action from responding
// with an error. Avoid SAME since getting the repository metadata may block on IO.
ThreadPool.Names.GENERIC
// Use SNAPSHOT_META pool since we are slow due to loading repository metadata in this action
ThreadPool.Names.SNAPSHOT_META
);
this.client = client;
this.repositoriesService = repositoriesService;
Expand Down Expand Up @@ -185,9 +184,9 @@ protected void masterOperation(
final Repository repository = repositoriesService.repository(repoName);
SearchableSnapshots.getSearchableRepository(repository); // just check it's valid

final StepListener<RepositoryData> repositoryDataListener = new StepListener<>();
final ListenableFuture<RepositoryData> repositoryDataListener = new ListenableFuture<>();
repository.getRepositoryData(repositoryDataListener);
repositoryDataListener.whenComplete(repoData -> {
repositoryDataListener.addListener(ActionListener.wrap(repoData -> {
final Map<String, IndexId> indexIds = repoData.getIndices();
if (indexIds.containsKey(indexName) == false) {
throw new IndexNotFoundException("index [" + indexName + "] not found in repository [" + repoName + "]");
Expand Down Expand Up @@ -280,6 +279,6 @@ protected void masterOperation(
.snapshotUuid(snapshotId.getUUID()),
listener
);
}, listener::onFailure);
}, listener::onFailure), threadPool.executor(ThreadPool.Names.SNAPSHOT_META), null);
}
}