Search in sources :

Example 1 with SnapshotFailedEngineException

use of org.elasticsearch.index.engine.SnapshotFailedEngineException in project elasticsearch by elastic.

the class SnapshotShardsService method snapshot.

/**
     * Creates shard snapshot
     *
     * @param snapshot       snapshot
     * @param snapshotStatus snapshot status
     */
private void snapshot(final IndexShard indexShard, final Snapshot snapshot, final IndexId indexId, final IndexShardSnapshotStatus snapshotStatus) {
    Repository repository = snapshotsService.getRepositoriesService().repository(snapshot.getRepository());
    ShardId shardId = indexShard.shardId();
    if (!indexShard.routingEntry().primary()) {
        throw new IndexShardSnapshotFailedException(shardId, "snapshot should be performed only on primary");
    }
    if (indexShard.routingEntry().relocating()) {
        // do not snapshot when in the process of relocation of primaries so we won't get conflicts
        throw new IndexShardSnapshotFailedException(shardId, "cannot snapshot while relocating");
    }
    if (indexShard.state() == IndexShardState.CREATED || indexShard.state() == IndexShardState.RECOVERING) {
        // shard has just been created, or still recovering
        throw new IndexShardSnapshotFailedException(shardId, "shard didn't fully recover yet");
    }
    try {
        // we flush first to make sure we get the latest writes snapshotted
        IndexCommit snapshotIndexCommit = indexShard.acquireIndexCommit(true);
        try {
            repository.snapshotShard(indexShard, snapshot.getSnapshotId(), indexId, snapshotIndexCommit, snapshotStatus);
            if (logger.isDebugEnabled()) {
                StringBuilder sb = new StringBuilder();
                sb.append("    index    : version [").append(snapshotStatus.indexVersion()).append("], number_of_files [").append(snapshotStatus.numberOfFiles()).append("] with total_size [").append(new ByteSizeValue(snapshotStatus.totalSize())).append("]\n");
                logger.debug("snapshot ({}) completed to {}, took [{}]\n{}", snapshot, repository, TimeValue.timeValueMillis(snapshotStatus.time()), sb);
            }
        } finally {
            indexShard.releaseIndexCommit(snapshotIndexCommit);
        }
    } catch (SnapshotFailedEngineException e) {
        throw e;
    } catch (IndexShardSnapshotFailedException e) {
        throw e;
    } catch (Exception e) {
        throw new IndexShardSnapshotFailedException(shardId, "Failed to snapshot", e);
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Repository(org.elasticsearch.repositories.Repository) SnapshotFailedEngineException(org.elasticsearch.index.engine.SnapshotFailedEngineException) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) IndexShardSnapshotFailedException(org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException) IndexCommit(org.apache.lucene.index.IndexCommit) IndexShardSnapshotFailedException(org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException) SnapshotFailedEngineException(org.elasticsearch.index.engine.SnapshotFailedEngineException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 IndexCommit (org.apache.lucene.index.IndexCommit)1 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)1 SnapshotFailedEngineException (org.elasticsearch.index.engine.SnapshotFailedEngineException)1 ShardId (org.elasticsearch.index.shard.ShardId)1 IndexShardSnapshotFailedException (org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException)1 Repository (org.elasticsearch.repositories.Repository)1