Skip to content

Commit

Permalink
Fork after calling getRepositoryData from StoreRecovery (#87254)
Browse files Browse the repository at this point in the history
`Repository#getRepositoryData` will occasionally complete its listener
on a blocking-free thread (a transport worker or the cluster applier
thread) so it's not valid to call `Repository#restoreShard` directly.
This commit fixes this by using a forking listener.

Closes #87237
  • Loading branch information
DaveCTurner committed May 31, 2022
1 parent 4a929f8 commit 0f98490
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/87254.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 87254
summary: Fork after calling `getRepositoryData` from `StoreRecovery`
area: Snapshot/Restore
type: bug
issues:
- 87237
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.StepListener;
import org.elasticsearch.action.support.ThreadedActionListener;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.MappingMetadata;
import org.elasticsearch.cluster.routing.RecoverySource;
Expand All @@ -42,6 +43,7 @@
import org.elasticsearch.indices.recovery.RecoveryState;
import org.elasticsearch.repositories.IndexId;
import org.elasticsearch.repositories.Repository;
import org.elasticsearch.threadpool.ThreadPool;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -537,22 +539,31 @@ private void restore(
// If the index UUID was not found in the recovery source we will have to load RepositoryData and resolve it by index name
if (indexId.getId().equals(IndexMetadata.INDEX_UUID_NA_VALUE)) {
// BwC path, running against an old version master that did not add the IndexId to the recovery source
repository.getRepositoryData(indexIdListener.map(repositoryData -> repositoryData.resolveIndexId(indexId.getName())));
repository.getRepositoryData(
new ThreadedActionListener<>(
logger,
indexShard.getThreadPool(),
ThreadPool.Names.GENERIC,
indexIdListener.map(repositoryData -> repositoryData.resolveIndexId(indexId.getName())),
false
)
);
} else {
indexIdListener.onResponse(indexId);
}
assert indexShard.getEngineOrNull() == null;
indexIdListener.whenComplete(
idx -> repository.restoreShard(
indexIdListener.whenComplete(idx -> {
assert Thread.currentThread().getName().contains('[' + ThreadPool.Names.GENERIC + ']')
|| Thread.currentThread().getName().startsWith("TEST-") : Thread.currentThread().getName();
repository.restoreShard(
indexShard.store(),
restoreSource.snapshot().getSnapshotId(),
idx,
snapshotShardId,
indexShard.recoveryState(),
restoreListener
),
restoreListener::onFailure
);
);
}, restoreListener::onFailure);
} catch (Exception e) {
restoreListener.onFailure(e);
}
Expand Down

0 comments on commit 0f98490

Please sign in to comment.