Search in sources :

Example 1 with IndexShardSnapshotFailedException

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

the class BlobStoreRepository method snapshotShard.

@Override
public void snapshotShard(IndexShard shard, SnapshotId snapshotId, IndexId indexId, IndexCommit snapshotIndexCommit, IndexShardSnapshotStatus snapshotStatus) {
    SnapshotContext snapshotContext = new SnapshotContext(shard, snapshotId, indexId, snapshotStatus);
    snapshotStatus.startTime(System.currentTimeMillis());
    try {
        snapshotContext.snapshot(snapshotIndexCommit);
        snapshotStatus.time(System.currentTimeMillis() - snapshotStatus.startTime());
        snapshotStatus.updateStage(IndexShardSnapshotStatus.Stage.DONE);
    } catch (Exception e) {
        snapshotStatus.time(System.currentTimeMillis() - snapshotStatus.startTime());
        snapshotStatus.updateStage(IndexShardSnapshotStatus.Stage.FAILURE);
        snapshotStatus.failure(ExceptionsHelper.detailedMessage(e));
        if (e instanceof IndexShardSnapshotFailedException) {
            throw (IndexShardSnapshotFailedException) e;
        } else {
            throw new IndexShardSnapshotFailedException(shard.shardId(), e);
        }
    }
}
Also used : IndexShardSnapshotFailedException(org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException) IndexNotFoundException(org.apache.lucene.index.IndexNotFoundException) IndexShardSnapshotFailedException(org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) SnapshotCreationException(org.elasticsearch.snapshots.SnapshotCreationException) SnapshotException(org.elasticsearch.snapshots.SnapshotException) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) IOException(java.io.IOException) SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) NoSuchFileException(java.nio.file.NoSuchFileException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IndexShardRestoreFailedException(org.elasticsearch.index.snapshots.IndexShardRestoreFailedException) RepositoryException(org.elasticsearch.repositories.RepositoryException) NotXContentException(org.elasticsearch.common.compress.NotXContentException) InvalidSnapshotNameException(org.elasticsearch.snapshots.InvalidSnapshotNameException) IndexShardSnapshotException(org.elasticsearch.index.snapshots.IndexShardSnapshotException) RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException)

Example 2 with IndexShardSnapshotFailedException

use of org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException 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)2 IndexShardSnapshotFailedException (org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException)2 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)1 IndexCommit (org.apache.lucene.index.IndexCommit)1 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)1 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)1 IndexNotFoundException (org.apache.lucene.index.IndexNotFoundException)1 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)1 NotXContentException (org.elasticsearch.common.compress.NotXContentException)1 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)1 SnapshotFailedEngineException (org.elasticsearch.index.engine.SnapshotFailedEngineException)1 ShardId (org.elasticsearch.index.shard.ShardId)1 IndexShardRestoreFailedException (org.elasticsearch.index.snapshots.IndexShardRestoreFailedException)1 IndexShardSnapshotException (org.elasticsearch.index.snapshots.IndexShardSnapshotException)1 Repository (org.elasticsearch.repositories.Repository)1 RepositoryException (org.elasticsearch.repositories.RepositoryException)1 RepositoryVerificationException (org.elasticsearch.repositories.RepositoryVerificationException)1 InvalidSnapshotNameException (org.elasticsearch.snapshots.InvalidSnapshotNameException)1