Skip to content

Commit 11f84fe

Browse files
nicer
1 parent 274a7e5 commit 11f84fe

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

server/src/main/java/org/elasticsearch/index/shard/StoreRecovery.java

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.elasticsearch.indices.recovery.RecoveryState;
5151
import org.elasticsearch.repositories.IndexId;
5252
import org.elasticsearch.repositories.Repository;
53-
import org.elasticsearch.repositories.RepositoryData;
5453

5554
import java.io.IOException;
5655
import java.util.Arrays;
@@ -475,33 +474,24 @@ private void restore(IndexShard indexShard, Repository repository, SnapshotRecov
475474
translogState.totalOperationsOnStart(0);
476475
indexShard.prepareForIndexRecovery();
477476
final ShardId snapshotShardId;
478-
final IndexId indexIdFromCS = restoreSource.index();
479-
if (shardId.getIndexName().equals(indexIdFromCS.getName())) {
477+
final IndexId indexId = restoreSource.index();
478+
if (shardId.getIndexName().equals(indexId.getName())) {
480479
snapshotShardId = shardId;
481480
} else {
482-
snapshotShardId = new ShardId(indexIdFromCS.getName(), IndexMetaData.INDEX_UUID_NA_VALUE, shardId.id());
481+
snapshotShardId = new ShardId(indexId.getName(), IndexMetaData.INDEX_UUID_NA_VALUE, shardId.id());
483482
}
484-
// If the index UUID was not found in the recovery source we will have to load RepositoryData and resolve it buy index name
485-
final boolean indexUUIDUnavailable = indexIdFromCS.getId().equals(IndexMetaData.INDEX_UUID_NA_VALUE);
486-
final StepListener<RepositoryData> repositoryDataListener = new StepListener<>();
487-
repositoryDataListener.whenComplete(repositoryData -> {
488-
final IndexId indexId;
489-
if (indexUUIDUnavailable) {
490-
indexId = repositoryData.resolveIndexId(indexIdFromCS.getName());
491-
} else {
492-
assert repositoryData == null: "Shouldn't have loaded RepositoryData but saw [" + repositoryData + "]";
493-
indexId = indexIdFromCS;
494-
}
495-
assert indexShard.getEngineOrNull() == null;
496-
repository.restoreShard(indexShard.store(), restoreSource.snapshot().getSnapshotId(), indexId, snapshotShardId,
497-
indexShard.recoveryState(), restoreListener);
498-
}, restoreListener::onFailure);
499-
if (indexUUIDUnavailable) {
483+
final StepListener<IndexId> indexIdListener = new StepListener<>();
484+
// If the index UUID was not found in the recovery source we will have to load RepositoryData and resolve it by index name
485+
if (indexId.getId().equals(IndexMetaData.INDEX_UUID_NA_VALUE)) {
500486
// BwC path, running against an old version master that did not add the IndexId to the recovery source
501-
repository.getRepositoryData(repositoryDataListener);
487+
repository.getRepositoryData(ActionListener.map(
488+
indexIdListener, repositoryData -> repositoryData.resolveIndexId(indexId.getName())));
502489
} else {
503-
repositoryDataListener.onResponse(null);
490+
indexIdListener.onResponse(indexId);
504491
}
492+
assert indexShard.getEngineOrNull() == null;
493+
indexIdListener.whenComplete(idx -> repository.restoreShard(indexShard.store(), restoreSource.snapshot().getSnapshotId(),
494+
idx, snapshotShardId, indexShard.recoveryState(), restoreListener), restoreListener::onFailure);
505495
} catch (Exception e) {
506496
restoreListener.onFailure(e);
507497
}

0 commit comments

Comments
 (0)