Search in sources :

Example 1 with Engine

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

the class IndexShard method internalPerformTranslogRecovery.

private void internalPerformTranslogRecovery(boolean skipTranslogRecovery, boolean indexExists, long maxUnsafeAutoIdTimestamp) throws IOException {
    if (state != IndexShardState.RECOVERING) {
        throw new IndexShardNotRecoveringException(shardId, state);
    }
    recoveryState.setStage(RecoveryState.Stage.VERIFY_INDEX);
    // also check here, before we apply the translog
    if (Booleans.isTrue(checkIndexOnStartup)) {
        try {
            checkIndex();
        } catch (IOException ex) {
            throw new RecoveryFailedException(recoveryState, "check index failed", ex);
        }
    }
    recoveryState.setStage(RecoveryState.Stage.TRANSLOG);
    final EngineConfig.OpenMode openMode;
    /* by default we recover and index and replay the translog but if the index
         * doesn't exist we create everything from the scratch. Yet, if the index
         * doesn't exist we don't need to worry about the skipTranslogRecovery since
         * there is no translog on a non-existing index.
         * The skipTranslogRecovery invariant is used if we do remote recovery since
         * there the translog isn't local but on the remote host, hence we can skip it.
         */
    if (indexExists == false) {
        openMode = EngineConfig.OpenMode.CREATE_INDEX_AND_TRANSLOG;
    } else if (skipTranslogRecovery) {
        openMode = EngineConfig.OpenMode.OPEN_INDEX_CREATE_TRANSLOG;
    } else {
        openMode = EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG;
    }
    final EngineConfig config = newEngineConfig(openMode, maxUnsafeAutoIdTimestamp);
    // we disable deletes since we allow for operations to be executed against the shard while recovering
    // but we need to make sure we don't loose deletes until we are done recovering
    config.setEnableGcDeletes(false);
    Engine newEngine = createNewEngine(config);
    verifyNotClosed();
    if (openMode == EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG) {
        // We set active because we are now writing operations to the engine; this way, if we go idle after some time and become inactive,
        // we still give sync'd flush a chance to run:
        active.set(true);
        newEngine.recoverFromTranslog();
    }
}
Also used : RecoveryFailedException(org.elasticsearch.indices.recovery.RecoveryFailedException) IOException(java.io.IOException) EngineConfig(org.elasticsearch.index.engine.EngineConfig) Engine(org.elasticsearch.index.engine.Engine)

Example 2 with Engine

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

the class IndexShard method index.

public Engine.IndexResult index(Engine.Index index) throws IOException {
    ensureWriteAllowed(index);
    Engine engine = getEngine();
    return index(engine, index);
}
Also used : Engine(org.elasticsearch.index.engine.Engine)

Example 3 with Engine

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

the class IndexShard method indexingStats.

public IndexingStats indexingStats(String... types) {
    Engine engine = getEngineOrNull();
    final boolean throttled;
    final long throttleTimeInMillis;
    if (engine == null) {
        throttled = false;
        throttleTimeInMillis = 0;
    } else {
        throttled = engine.isThrottled();
        throttleTimeInMillis = engine.getIndexThrottleTimeInMillis();
    }
    return internalIndexingStats.stats(throttled, throttleTimeInMillis, types);
}
Also used : Engine(org.elasticsearch.index.engine.Engine)

Example 4 with Engine

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

the class IndexShard method writeIndexingBuffer.

/**
     * Called when our shard is using too much heap and should move buffered indexed/deleted documents to disk.
     */
public void writeIndexingBuffer() {
    if (canIndex() == false) {
        throw new UnsupportedOperationException();
    }
    try {
        Engine engine = getEngine();
        long bytes = engine.getIndexBufferRAMBytesUsed();
        // NOTE: this can be an overestimate by up to 20%, if engine uses IW.flush not refresh, because version map
        // memory is low enough, but this is fine because after the writes finish, IMC will poll again and see that
        // there's still up to the 20% being used and continue writing if necessary:
        logger.debug("add [{}] writing bytes for shard [{}]", new ByteSizeValue(bytes), shardId());
        writingBytes.addAndGet(bytes);
        try {
            engine.writeIndexingBuffer();
        } finally {
            writingBytes.addAndGet(-bytes);
            logger.debug("remove [{}] writing bytes for shard [{}]", new ByteSizeValue(bytes), shardId());
        }
    } catch (Exception e) {
        handleRefreshException(e);
    }
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Engine(org.elasticsearch.index.engine.Engine) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) ThreadInterruptedException(org.apache.lucene.util.ThreadInterruptedException) RecoveryFailedException(org.elasticsearch.indices.recovery.RecoveryFailedException) EngineException(org.elasticsearch.index.engine.EngineException) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) NoSuchFileException(java.nio.file.NoSuchFileException) TimeoutException(java.util.concurrent.TimeoutException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) RefreshFailedEngineException(org.elasticsearch.index.engine.RefreshFailedEngineException) FileNotFoundException(java.io.FileNotFoundException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException)

Example 5 with Engine

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

the class IndexShard method delete.

public Engine.DeleteResult delete(Engine.Delete delete) throws IOException {
    ensureWriteAllowed(delete);
    Engine engine = getEngine();
    return delete(engine, delete);
}
Also used : Engine(org.elasticsearch.index.engine.Engine)

Aggregations

Engine (org.elasticsearch.index.engine.Engine)38 ReadOnlyEngine (org.elasticsearch.index.engine.ReadOnlyEngine)16 IOException (java.io.IOException)11 ElasticsearchException (org.elasticsearch.ElasticsearchException)7 Translog (org.elasticsearch.index.translog.Translog)7 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)6 RecoveryFailedException (org.elasticsearch.indices.recovery.RecoveryFailedException)6 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)5 TimeoutException (java.util.concurrent.TimeoutException)5 ThreadInterruptedException (org.apache.lucene.util.ThreadInterruptedException)5 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)5 EngineException (org.elasticsearch.index.engine.EngineException)5 RefreshFailedEngineException (org.elasticsearch.index.engine.RefreshFailedEngineException)5 Store (org.elasticsearch.index.store.Store)4 Collections (java.util.Collections)3 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)3 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)3 WriteStateException (org.elasticsearch.gateway.WriteStateException)3 Index (org.elasticsearch.index.Index)3 EngineConfig (org.elasticsearch.index.engine.EngineConfig)3