/** * Restores shard from {@link RestoreSource} associated with this shard in routing table * * @param recoveryState recovery state */ public void restore(final RecoveryState recoveryState) { RestoreSource restoreSource = indexShard.routingEntry().restoreSource(); if (restoreSource == null) { throw new IndexShardRestoreFailedException(shardId, "empty restore source"); } if (logger.isTraceEnabled()) { logger.trace("[{}] restoring shard [{}]", restoreSource.snapshotId(), shardId); } try { recoveryState.getTranslog().totalOperations(0); recoveryState.getTranslog().totalOperationsOnStart(0); indexShard.prepareForIndexRecovery(); IndexShardRepository indexShardRepository = repositoriesService.indexShardRepository(restoreSource.snapshotId().getRepository()); ShardId snapshotShardId = shardId; if (!shardId.getIndex().equals(restoreSource.index())) { snapshotShardId = new ShardId(restoreSource.index(), shardId.id()); } indexShardRepository.restore( restoreSource.snapshotId(), shardId, snapshotShardId, recoveryState); indexShard.prepareForTranslogRecovery(); indexShard.finalizeRecovery(); indexShard.postRecovery("restore done"); restoreService.indexShardRestoreCompleted(restoreSource.snapshotId(), shardId); } catch (Throwable t) { if (Lucene.isCorruptionException(t)) { restoreService.failRestore(restoreSource.snapshotId(), shardId()); } throw new IndexShardRestoreFailedException(shardId, "restore failed", t); } }