Search in sources :

Example 1 with IndexShardNotRecoveringException

use of org.elasticsearch.index.shard.IndexShardNotRecoveringException in project crate by crate.

the class RecoveryTarget method indexTranslogOperations.

@Override
public void indexTranslogOperations(List<Translog.Operation> operations, int totalTranslogOps, long maxSeenAutoIdTimestampOnPrimary, long maxSeqNoOfDeletesOrUpdatesOnPrimary, RetentionLeases retentionLeases, long mappingVersionOnPrimary, ActionListener<Long> listener) {
    ActionListener.completeWith(listener, () -> {
        final RecoveryState.Translog translog = state().getTranslog();
        translog.totalOperations(totalTranslogOps);
        assert indexShard().recoveryState() == state();
        if (indexShard().state() != IndexShardState.RECOVERING) {
            throw new IndexShardNotRecoveringException(shardId, indexShard().state());
        }
        /*
             * The maxSeenAutoIdTimestampOnPrimary received from the primary is at least the highest auto_id_timestamp from any operation
             * will be replayed. Bootstrapping this timestamp here will disable the optimization for original append-only requests
             * (source of these operations) replicated via replication. Without this step, we may have duplicate documents if we
             * replay these operations first (without timestamp), then optimize append-only requests (with timestamp).
             */
        indexShard().updateMaxUnsafeAutoIdTimestamp(maxSeenAutoIdTimestampOnPrimary);
        /*
             * Bootstrap the max_seq_no_of_updates from the primary to make sure that the max_seq_no_of_updates on this replica when
             * replaying any of these operations will be at least the max_seq_no_of_updates on the primary when that op was executed on.
             */
        indexShard().advanceMaxSeqNoOfUpdatesOrDeletes(maxSeqNoOfDeletesOrUpdatesOnPrimary);
        /*
             * We have to update the retention leases before we start applying translog operations to ensure we are retaining according to
             * the policy.
             */
        indexShard().updateRetentionLeasesOnReplica(retentionLeases);
        for (Translog.Operation operation : operations) {
            Engine.Result result = indexShard().applyTranslogOperation(operation, Engine.Operation.Origin.PEER_RECOVERY);
            if (result.getResultType() == Engine.Result.Type.MAPPING_UPDATE_REQUIRED) {
                throw new MapperException("mapping updates are not allowed [" + operation + "]");
            }
            Exception failure = result.getFailure();
            if (failure != null) {
                if (Assertions.ENABLED && result.getFailure() instanceof MapperException == false) {
                    throw new AssertionError("unexpected failure while replicating translog entry", result.getFailure());
                }
                Exceptions.rethrowRuntimeException(failure);
            }
        }
        // update stats only after all operations completed (to ensure that mapping updates don't mess with stats)
        translog.incrementRecoveredOperations(operations.size());
        indexShard().sync();
        // roll over / flush / trim if needed
        indexShard().afterWriteOperation();
        return indexShard().getLocalCheckpoint();
    });
}
Also used : MapperException(org.elasticsearch.index.mapper.MapperException) IndexShardNotRecoveringException(org.elasticsearch.index.shard.IndexShardNotRecoveringException) Engine(org.elasticsearch.index.engine.Engine) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IOException(java.io.IOException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) IndexShardNotRecoveringException(org.elasticsearch.index.shard.IndexShardNotRecoveringException) MapperException(org.elasticsearch.index.mapper.MapperException) Translog(org.elasticsearch.index.translog.Translog)

Aggregations

IOException (java.io.IOException)1 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)1 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)1 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 Engine (org.elasticsearch.index.engine.Engine)1 MapperException (org.elasticsearch.index.mapper.MapperException)1 IndexShardNotRecoveringException (org.elasticsearch.index.shard.IndexShardNotRecoveringException)1 Translog (org.elasticsearch.index.translog.Translog)1