|
50 | 50 | import org.elasticsearch.indices.recovery.RecoveryState;
|
51 | 51 | import org.elasticsearch.repositories.IndexId;
|
52 | 52 | import org.elasticsearch.repositories.Repository;
|
53 |
| -import org.elasticsearch.repositories.RepositoryData; |
54 | 53 |
|
55 | 54 | import java.io.IOException;
|
56 | 55 | import java.util.Arrays;
|
@@ -475,33 +474,24 @@ private void restore(IndexShard indexShard, Repository repository, SnapshotRecov
|
475 | 474 | translogState.totalOperationsOnStart(0);
|
476 | 475 | indexShard.prepareForIndexRecovery();
|
477 | 476 | 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())) { |
480 | 479 | snapshotShardId = shardId;
|
481 | 480 | } 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()); |
483 | 482 | }
|
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)) { |
500 | 486 | // 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()))); |
502 | 489 | } else {
|
503 |
| - repositoryDataListener.onResponse(null); |
| 490 | + indexIdListener.onResponse(indexId); |
504 | 491 | }
|
| 492 | + assert indexShard.getEngineOrNull() == null; |
| 493 | + indexIdListener.whenComplete(idx -> repository.restoreShard(indexShard.store(), restoreSource.snapshot().getSnapshotId(), |
| 494 | + idx, snapshotShardId, indexShard.recoveryState(), restoreListener), restoreListener::onFailure); |
505 | 495 | } catch (Exception e) {
|
506 | 496 | restoreListener.onFailure(e);
|
507 | 497 | }
|
|
0 commit comments