Search in sources :

Example 1 with NoOpEngine

use of org.elasticsearch.index.engine.NoOpEngine in project crate by crate.

the class IndicesService method getEngineFactory.

private EngineFactory getEngineFactory(final IndexSettings idxSettings) {
    final IndexMetadata indexMetadata = idxSettings.getIndexMetadata();
    if (indexMetadata != null && indexMetadata.getState() == IndexMetadata.State.CLOSE) {
        // NoOpEngine takes precedence as long as the index is closed
        return NoOpEngine::new;
    }
    final List<Optional<EngineFactory>> engineFactories = engineFactoryProviders.stream().map(engineFactoryProvider -> engineFactoryProvider.apply(idxSettings)).filter(maybe -> Objects.requireNonNull(maybe).isPresent()).collect(Collectors.toList());
    if (engineFactories.isEmpty()) {
        return new InternalEngineFactory();
    } else if (engineFactories.size() == 1) {
        assert engineFactories.get(0).isPresent();
        return engineFactories.get(0).get();
    } else {
        final String message = String.format(Locale.ROOT, "multiple engine factories provided for %s: %s", idxSettings.getIndex(), engineFactories.stream().map(t -> {
            assert t.isPresent();
            return "[" + t.get().getClass().getName() + "]";
        }).collect(Collectors.joining(",")));
        throw new IllegalStateException(message);
    }
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) ShardId(org.elasticsearch.index.shard.ShardId) NoOpEngine(org.elasticsearch.index.engine.NoOpEngine) BigArrays(org.elasticsearch.common.util.BigArrays) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) MetadataStateFormat(org.elasticsearch.gateway.MetadataStateFormat) MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) Sets(io.crate.common.collections.Sets) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) IndexStorePlugin(org.elasticsearch.plugins.IndexStorePlugin) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) InternalEngineFactory(org.elasticsearch.index.engine.InternalEngineFactory) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) PeerRecoveryTargetService(org.elasticsearch.indices.recovery.PeerRecoveryTargetService) PluginsService(org.elasticsearch.plugins.PluginsService) Setting(org.elasticsearch.common.settings.Setting) AbstractRefCounted(org.elasticsearch.common.util.concurrent.AbstractRefCounted) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException) AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Iterables(io.crate.common.collections.Iterables) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) RecoverySource(org.elasticsearch.cluster.routing.RecoverySource) MapperService(org.elasticsearch.index.mapper.MapperService) List(java.util.List) AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) Logger(org.apache.logging.log4j.Logger) IndicesClusterStateService(org.elasticsearch.indices.cluster.IndicesClusterStateService) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) RetentionLeaseSyncer(org.elasticsearch.index.seqno.RetentionLeaseSyncer) TimeValue(io.crate.common.unit.TimeValue) Optional(java.util.Optional) EsExecutors.daemonThreadFactory(org.elasticsearch.common.util.concurrent.EsExecutors.daemonThreadFactory) IndexingOperationListener(org.elasticsearch.index.shard.IndexingOperationListener) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) MapBuilder.newMapBuilder(io.crate.common.collections.MapBuilder.newMapBuilder) XContentType(org.elasticsearch.common.xcontent.XContentType) HashMap(java.util.HashMap) MetaStateService(org.elasticsearch.gateway.MetaStateService) Index(org.elasticsearch.index.Index) IndexModule(org.elasticsearch.index.IndexModule) EsThreadPoolExecutor(org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor) Function(java.util.function.Function) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ArrayList(java.util.ArrayList) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) IndexSettings(org.elasticsearch.index.IndexSettings) Node(org.elasticsearch.node.Node) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) Collections.emptyMap(java.util.Collections.emptyMap) FileSystemUtils(org.elasticsearch.common.io.FileSystemUtils) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) AbstractIndexComponent(org.elasticsearch.index.AbstractIndexComponent) Iterator(java.util.Iterator) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) Files(java.nio.file.Files) IndexCreationContext(org.elasticsearch.index.IndexService.IndexCreationContext) Client(org.elasticsearch.client.Client) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IOUtils(io.crate.common.io.IOUtils) IOException(java.io.IOException) ShardLock(org.elasticsearch.env.ShardLock) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) AbstractLifecycleComponent(org.elasticsearch.common.component.AbstractLifecycleComponent) EngineFactory(org.elasticsearch.index.engine.EngineFactory) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CollectionUtil(org.apache.lucene.util.CollectionUtil) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) Closeable(java.io.Closeable) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) LogManager(org.apache.logging.log4j.LogManager) Optional(java.util.Optional) InternalEngineFactory(org.elasticsearch.index.engine.InternalEngineFactory) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata)

Example 2 with NoOpEngine

use of org.elasticsearch.index.engine.NoOpEngine in project crate by crate.

the class PeerRecoveryTargetServiceTests method testClosedIndexSkipsLocalRecovery.

@Test
public void testClosedIndexSkipsLocalRecovery() throws Exception {
    DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), Collections.emptyMap(), Collections.emptySet(), Version.CURRENT);
    IndexShard shard = newStartedShard(false);
    long globalCheckpoint = populateRandomData(shard).getGlobalCheckpoint();
    Optional<SequenceNumbers.CommitInfo> safeCommit = shard.store().findSafeIndexCommit(globalCheckpoint);
    assertTrue(safeCommit.isPresent());
    final IndexMetadata indexMetadata;
    if (randomBoolean()) {
        indexMetadata = IndexMetadata.builder(shard.indexSettings().getIndexMetadata()).settings(shard.indexSettings().getSettings()).state(IndexMetadata.State.CLOSE).build();
    } else {
        indexMetadata = IndexMetadata.builder(shard.indexSettings().getIndexMetadata()).settings(Settings.builder().put(shard.indexSettings().getSettings()).put(IndexMetadata.SETTING_BLOCKS_WRITE, true)).build();
    }
    IndexShard replica = reinitShard(shard, ShardRoutingHelper.initWithSameId(shard.routingEntry(), RecoverySource.PeerRecoverySource.INSTANCE), indexMetadata, NoOpEngine::new);
    replica.markAsRecovering("for testing", new RecoveryState(replica.routingEntry(), localNode, localNode));
    replica.prepareForIndexRecovery();
    assertThat(replica.recoverLocallyUpToGlobalCheckpoint(), equalTo(safeCommit.get().localCheckpoint + 1));
    assertThat(replica.recoveryState().getTranslog().totalLocal(), equalTo(0));
    assertThat(replica.recoveryState().getTranslog().recoveredOperations(), equalTo(0));
    assertThat(replica.getLastKnownGlobalCheckpoint(), equalTo(UNASSIGNED_SEQ_NO));
    closeShards(replica);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NoOpEngine(org.elasticsearch.index.engine.NoOpEngine) IndexShard(org.elasticsearch.index.shard.IndexShard) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Test(org.junit.Test)

Aggregations

IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 NoOpEngine (org.elasticsearch.index.engine.NoOpEngine)2 IndexShard (org.elasticsearch.index.shard.IndexShard)2 Iterables (io.crate.common.collections.Iterables)1 MapBuilder.newMapBuilder (io.crate.common.collections.MapBuilder.newMapBuilder)1 Sets (io.crate.common.collections.Sets)1 IOUtils (io.crate.common.io.IOUtils)1 TimeValue (io.crate.common.unit.TimeValue)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1