Search in sources :

Example 1 with IndexQueryCache

use of org.opensearch.index.cache.query.IndexQueryCache in project OpenSearch by opensearch-project.

the class IndexModule method newIndexService.

public IndexService newIndexService(IndexService.IndexCreationContext indexCreationContext, NodeEnvironment environment, NamedXContentRegistry xContentRegistry, IndexService.ShardStoreDeleter shardStoreDeleter, CircuitBreakerService circuitBreakerService, BigArrays bigArrays, ThreadPool threadPool, ScriptService scriptService, ClusterService clusterService, Client client, IndicesQueryCache indicesQueryCache, MapperRegistry mapperRegistry, IndicesFieldDataCache indicesFieldDataCache, NamedWriteableRegistry namedWriteableRegistry, BooleanSupplier idFieldDataEnabled, ValuesSourceRegistry valuesSourceRegistry) throws IOException {
    final IndexEventListener eventListener = freeze();
    Function<IndexService, CheckedFunction<DirectoryReader, DirectoryReader, IOException>> readerWrapperFactory = indexReaderWrapper.get() == null ? (shard) -> null : indexReaderWrapper.get();
    eventListener.beforeIndexCreated(indexSettings.getIndex(), indexSettings.getSettings());
    final IndexStorePlugin.DirectoryFactory directoryFactory = getDirectoryFactory(indexSettings, directoryFactories);
    final IndexStorePlugin.RecoveryStateFactory recoveryStateFactory = getRecoveryStateFactory(indexSettings, recoveryStateFactories);
    QueryCache queryCache = null;
    IndexAnalyzers indexAnalyzers = null;
    boolean success = false;
    try {
        if (indexSettings.getValue(INDEX_QUERY_CACHE_ENABLED_SETTING)) {
            BiFunction<IndexSettings, IndicesQueryCache, QueryCache> queryCacheProvider = forceQueryCacheProvider.get();
            if (queryCacheProvider == null) {
                queryCache = new IndexQueryCache(indexSettings, indicesQueryCache);
            } else {
                queryCache = queryCacheProvider.apply(indexSettings, indicesQueryCache);
            }
        } else {
            queryCache = new DisabledQueryCache(indexSettings);
        }
        if (IndexService.needsMapperService(indexSettings, indexCreationContext)) {
            indexAnalyzers = analysisRegistry.build(indexSettings);
        }
        final IndexService indexService = new IndexService(indexSettings, indexCreationContext, environment, xContentRegistry, new SimilarityService(indexSettings, scriptService, similarities), shardStoreDeleter, indexAnalyzers, engineFactory, engineConfigFactory, circuitBreakerService, bigArrays, threadPool, scriptService, clusterService, client, queryCache, directoryFactory, eventListener, readerWrapperFactory, mapperRegistry, indicesFieldDataCache, searchOperationListeners, indexOperationListeners, namedWriteableRegistry, idFieldDataEnabled, allowExpensiveQueries, expressionResolver, valuesSourceRegistry, recoveryStateFactory);
        success = true;
        return indexService;
    } finally {
        if (success == false) {
            IOUtils.closeWhileHandlingException(queryCache, indexAnalyzers);
        }
    }
}
Also used : IndicesQueryCache(org.opensearch.indices.IndicesQueryCache) QueryCache(org.opensearch.index.cache.query.QueryCache) IndicesQueryCache(org.opensearch.indices.IndicesQueryCache) IndexQueryCache(org.opensearch.index.cache.query.IndexQueryCache) DisabledQueryCache(org.opensearch.index.cache.query.DisabledQueryCache) IndexQueryCache(org.opensearch.index.cache.query.IndexQueryCache) IndexEventListener(org.opensearch.index.shard.IndexEventListener) SimilarityService(org.opensearch.index.similarity.SimilarityService) IndexStorePlugin(org.opensearch.plugins.IndexStorePlugin) IndexAnalyzers(org.opensearch.index.analysis.IndexAnalyzers) DisabledQueryCache(org.opensearch.index.cache.query.DisabledQueryCache) CheckedFunction(org.opensearch.common.CheckedFunction)

Example 2 with IndexQueryCache

use of org.opensearch.index.cache.query.IndexQueryCache in project OpenSearch by opensearch-project.

the class IndexModuleTests method testDefaultQueryCacheImplIsSelected.

public void testDefaultQueryCacheImplIsSelected() throws IOException {
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build();
    final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
    IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry);
    IndexService indexService = newIndexService(module);
    assertTrue(indexService.cache().query() instanceof IndexQueryCache);
    indexService.close("simon says", false);
}
Also used : IndexQueryCache(org.opensearch.index.cache.query.IndexQueryCache) Settings(org.opensearch.common.settings.Settings)

Aggregations

IndexQueryCache (org.opensearch.index.cache.query.IndexQueryCache)2 CheckedFunction (org.opensearch.common.CheckedFunction)1 Settings (org.opensearch.common.settings.Settings)1 IndexAnalyzers (org.opensearch.index.analysis.IndexAnalyzers)1 DisabledQueryCache (org.opensearch.index.cache.query.DisabledQueryCache)1 QueryCache (org.opensearch.index.cache.query.QueryCache)1 IndexEventListener (org.opensearch.index.shard.IndexEventListener)1 SimilarityService (org.opensearch.index.similarity.SimilarityService)1 IndicesQueryCache (org.opensearch.indices.IndicesQueryCache)1 IndexStorePlugin (org.opensearch.plugins.IndexStorePlugin)1