Search in sources :

Example 1 with IndexShardRestoreFailedException

use of org.elasticsearch.index.snapshots.IndexShardRestoreFailedException in project elasticsearch by elastic.

the class StoreRecovery method restore.

/**
     * Restores shard from {@link SnapshotRecoverySource} associated with this shard in routing table
     */
private void restore(final IndexShard indexShard, final Repository repository, final SnapshotRecoverySource restoreSource) {
    final RecoveryState.Translog translogState = indexShard.recoveryState().getTranslog();
    if (restoreSource == null) {
        throw new IndexShardRestoreFailedException(shardId, "empty restore source");
    }
    if (logger.isTraceEnabled()) {
        logger.trace("[{}] restoring shard [{}]", restoreSource.snapshot(), shardId);
    }
    try {
        translogState.totalOperations(0);
        translogState.totalOperationsOnStart(0);
        indexShard.prepareForIndexRecovery();
        ShardId snapshotShardId = shardId;
        final String indexName = restoreSource.index();
        if (!shardId.getIndexName().equals(indexName)) {
            snapshotShardId = new ShardId(indexName, IndexMetaData.INDEX_UUID_NA_VALUE, shardId.id());
        }
        final IndexId indexId = repository.getRepositoryData().resolveIndexId(indexName);
        repository.restoreShard(indexShard, restoreSource.snapshot().getSnapshotId(), restoreSource.version(), indexId, snapshotShardId, indexShard.recoveryState());
        indexShard.skipTranslogRecovery(IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP);
        indexShard.finalizeRecovery();
        indexShard.postRecovery("restore done");
    } catch (Exception e) {
        throw new IndexShardRestoreFailedException(shardId, "restore failed", e);
    }
}
Also used : IndexId(org.elasticsearch.repositories.IndexId) IndexShardRestoreFailedException(org.elasticsearch.index.snapshots.IndexShardRestoreFailedException) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) IndexShardRestoreFailedException(org.elasticsearch.index.snapshots.IndexShardRestoreFailedException) EngineException(org.elasticsearch.index.engine.EngineException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 EngineException (org.elasticsearch.index.engine.EngineException)1 IndexShardRestoreFailedException (org.elasticsearch.index.snapshots.IndexShardRestoreFailedException)1 RecoveryState (org.elasticsearch.indices.recovery.RecoveryState)1 IndexId (org.elasticsearch.repositories.IndexId)1