Search in sources :

Example 1 with IndexingOperationListener

use of org.opensearch.index.shard.IndexingOperationListener in project OpenSearch by opensearch-project.

the class IndicesService method createIndexService.

/**
 * This creates a new IndexService without registering it
 */
private synchronized IndexService createIndexService(IndexService.IndexCreationContext indexCreationContext, IndexMetadata indexMetadata, IndicesQueryCache indicesQueryCache, IndicesFieldDataCache indicesFieldDataCache, List<IndexEventListener> builtInListeners, IndexingOperationListener... indexingOperationListeners) throws IOException {
    final IndexSettings idxSettings = new IndexSettings(indexMetadata, settings, indexScopedSettings);
    if (idxSettings.getIndexVersionCreated().onOrAfter(LegacyESVersion.V_7_0_0) && EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.exists(idxSettings.getSettings())) {
        throw new IllegalArgumentException("Setting [" + EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS.getKey() + "] was removed in version 7.0.0");
    }
    // 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), getEngineConfigFactory(idxSettings), directoryFactories, () -> allowExpensiveQueries, indexNameExpressionResolver, recoveryStateFactories);
    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, scriptService, clusterService, client, indicesQueryCache, mapperRegistry, indicesFieldDataCache, namedWriteableRegistry, this::isIdFieldDataEnabled, valuesSourceRegistry);
}
Also used : IndexingOperationListener(org.opensearch.index.shard.IndexingOperationListener) IndexEventListener(org.opensearch.index.shard.IndexEventListener) IndexSettings(org.opensearch.index.IndexSettings) IndexModule(org.opensearch.index.IndexModule)

Example 2 with IndexingOperationListener

use of org.opensearch.index.shard.IndexingOperationListener in project OpenSearch by opensearch-project.

the class IndexModuleTests method testAddIndexOperationListener.

public void testAddIndexOperationListener() throws IOException {
    final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
    IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry);
    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", null);
    Engine.Index index = new Engine.Index(new Term("_id", Uid.encodeId(doc.id())), randomNonNegativeLong(), 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.opensearch.index.shard.ShardId) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexingOperationListener(org.opensearch.index.shard.IndexingOperationListener) ParsedDocument(org.opensearch.index.mapper.ParsedDocument) Term(org.apache.lucene.index.Term) Engine(org.opensearch.index.engine.Engine)

Aggregations

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