Search in sources :

Example 1 with IndexingOperationListener

use of org.elasticsearch.index.shard.IndexingOperationListener in project elasticsearch by elastic.

the class IndicesService method createIndexService.

/**
     * This creates a new IndexService without registering it
     */
private synchronized IndexService createIndexService(final String reason, IndexMetaData indexMetaData, IndicesQueryCache indicesQueryCache, IndicesFieldDataCache indicesFieldDataCache, List<IndexEventListener> builtInListeners, Consumer<ShardId> globalCheckpointSyncer, IndexingOperationListener... indexingOperationListeners) throws IOException {
    final Index index = indexMetaData.getIndex();
    final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, indexScopeSetting);
    logger.debug("creating Index [{}], shards [{}]/[{}{}] - reason [{}]", indexMetaData.getIndex(), idxSettings.getNumberOfShards(), idxSettings.getNumberOfReplicas(), idxSettings.isShadowReplicaIndex() ? "s" : "", reason);
    final IndexModule indexModule = new IndexModule(idxSettings, analysisRegistry);
    for (IndexingOperationListener operationListener : indexingOperationListeners) {
        indexModule.addIndexOperationListener(operationListener);
    }
    pluginsService.onIndexModule(indexModule);
    for (IndexEventListener listener : builtInListeners) {
        indexModule.addIndexEventListener(listener);
    }
    return indexModule.newIndexService(nodeEnv, xContentRegistry, this, circuitBreakerService, bigArrays, threadPool, scriptService, clusterService, client, indicesQueryCache, mapperRegistry, globalCheckpointSyncer, indicesFieldDataCache);
}
Also used : IndexingOperationListener(org.elasticsearch.index.shard.IndexingOperationListener) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) IndexSettings(org.elasticsearch.index.IndexSettings) Index(org.elasticsearch.index.Index) IndexModule(org.elasticsearch.index.IndexModule)

Example 2 with IndexingOperationListener

use of org.elasticsearch.index.shard.IndexingOperationListener in project elasticsearch by elastic.

the class IndexModuleTests method testAddIndexOperationListener.

public void testAddIndexOperationListener() throws IOException {
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings(index, settings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    AtomicBoolean executed = new AtomicBoolean(false);
    IndexingOperationListener listener = new IndexingOperationListener() {

        @Override
        public Engine.Index preIndex(ShardId shardId, Engine.Index operation) {
            executed.set(true);
            return operation;
        }
    };
    module.addIndexOperationListener(listener);
    expectThrows(IllegalArgumentException.class, () -> module.addIndexOperationListener(listener));
    expectThrows(IllegalArgumentException.class, () -> module.addIndexOperationListener(null));
    IndexService indexService = newIndexService(module);
    assertEquals(2, indexService.getIndexOperationListeners().size());
    assertEquals(IndexingSlowLog.class, indexService.getIndexOperationListeners().get(0).getClass());
    assertSame(listener, indexService.getIndexOperationListeners().get(1));
    ParsedDocument doc = InternalEngineTests.createParsedDoc("1", "test", null);
    Engine.Index index = new Engine.Index(new Term("_uid", doc.uid()), doc);
    ShardId shardId = new ShardId(new Index("foo", "bar"), 0);
    for (IndexingOperationListener l : indexService.getIndexOperationListeners()) {
        l.preIndex(shardId, index);
    }
    assertTrue(executed.get());
    indexService.close("simon says", false);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexingOperationListener(org.elasticsearch.index.shard.IndexingOperationListener) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) Term(org.apache.lucene.index.Term) Engine(org.elasticsearch.index.engine.Engine)

Example 3 with IndexingOperationListener

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

the class IndicesService method createIndexService.

/**
 * This creates a new IndexService without registering itcreateIndex
 */
private synchronized IndexService createIndexService(IndexCreationContext indexCreationContext, IndexMetadata indexMetadata, IndicesQueryCache indicesQueryCache, List<IndexEventListener> builtInListeners, IndexingOperationListener... indexingOperationListeners) throws IOException {
    final IndexSettings idxSettings = new IndexSettings(indexMetadata, this.settings, indexScopedSettings);
    // we ignore private settings since they are not registered settings
    indexScopedSettings.validate(indexMetadata.getSettings(), true, true, true);
    LOGGER.debug("creating Index [{}], shards [{}]/[{}] - reason [{}]", indexMetadata.getIndex(), idxSettings.getNumberOfShards(), idxSettings.getNumberOfReplicas(), indexCreationContext);
    final IndexModule indexModule = new IndexModule(idxSettings, analysisRegistry, getEngineFactory(idxSettings), directoryFactories);
    for (IndexingOperationListener operationListener : indexingOperationListeners) {
        indexModule.addIndexOperationListener(operationListener);
    }
    pluginsService.onIndexModule(indexModule);
    for (IndexEventListener listener : builtInListeners) {
        indexModule.addIndexEventListener(listener);
    }
    return indexModule.newIndexService(indexCreationContext, nodeEnv, xContentRegistry, this, circuitBreakerService, bigArrays, threadPool, indicesQueryCache, mapperRegistry);
}
Also used : IndexingOperationListener(org.elasticsearch.index.shard.IndexingOperationListener) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) IndexSettings(org.elasticsearch.index.IndexSettings) IndexModule(org.elasticsearch.index.IndexModule)

Aggregations

IndexingOperationListener (org.elasticsearch.index.shard.IndexingOperationListener)3 IndexModule (org.elasticsearch.index.IndexModule)2 IndexSettings (org.elasticsearch.index.IndexSettings)2 IndexEventListener (org.elasticsearch.index.shard.IndexEventListener)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Term (org.apache.lucene.index.Term)1 Index (org.elasticsearch.index.Index)1 AnalysisRegistry (org.elasticsearch.index.analysis.AnalysisRegistry)1 Engine (org.elasticsearch.index.engine.Engine)1 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)1 ShardId (org.elasticsearch.index.shard.ShardId)1