Search in sources :

Example 1 with DisabledQueryCache

use of org.elasticsearch.index.cache.query.DisabledQueryCache in project crate by crate.

the class IndexModule method newIndexService.

public IndexService newIndexService(IndexService.IndexCreationContext indexCreationContext, NodeEnvironment environment, NamedXContentRegistry xContentRegistry, IndexService.ShardStoreDeleter shardStoreDeleter, CircuitBreakerService circuitBreakerService, BigArrays bigArrays, ThreadPool threadPool, IndicesQueryCache indicesQueryCache, MapperRegistry mapperRegistry) throws IOException {
    final IndexEventListener eventListener = freeze();
    eventListener.beforeIndexCreated(indexSettings.getIndex(), indexSettings.getSettings());
    final IndexStorePlugin.DirectoryFactory directoryFactory = getDirectoryFactory(indexSettings, directoryFactories);
    final QueryCache queryCache;
    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);
    }
    return new IndexService(indexSettings, indexCreationContext, environment, xContentRegistry, shardStoreDeleter, analysisRegistry, engineFactory, circuitBreakerService, bigArrays, threadPool, queryCache, directoryFactory, eventListener, mapperRegistry, indexOperationListeners);
}
Also used : IndicesQueryCache(org.elasticsearch.indices.IndicesQueryCache) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) IndicesQueryCache(org.elasticsearch.indices.IndicesQueryCache) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) IndexQueryCache(org.elasticsearch.index.cache.query.IndexQueryCache) QueryCache(org.elasticsearch.index.cache.query.QueryCache) IndexQueryCache(org.elasticsearch.index.cache.query.IndexQueryCache) IndexStorePlugin(org.elasticsearch.plugins.IndexStorePlugin) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache)

Example 2 with DisabledQueryCache

use of org.elasticsearch.index.cache.query.DisabledQueryCache in project elasticsearch by elastic.

the class IndexModuleTests method testDisableQueryCacheHasPrecedenceOverForceQueryCache.

public void testDisableQueryCacheHasPrecedenceOverForceQueryCache() throws IOException {
    Settings indexSettings = Settings.builder().put(IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING.getKey(), false).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings("foo", indexSettings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    module.forceQueryCacheProvider((a, b) -> new CustomQueryCache());
    IndexService indexService = newIndexService(module);
    assertTrue(indexService.cache().query() instanceof DisabledQueryCache);
    indexService.close("simon says", false);
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache)

Example 3 with DisabledQueryCache

use of org.elasticsearch.index.cache.query.DisabledQueryCache in project elasticsearch by elastic.

the class IndexShardTestCase method newShard.

/**
     * creates a new initializing shard.
     *
     * @param routing              shard routing to use
     * @param shardPath            path to use for shard data
     * @param indexMetaData        indexMetaData for the shard, including any mapping
     * @param indexSearcherWrapper an optional wrapper to be used during searchers
     * @param listeners            an optional set of listeners to add to the shard
     */
protected IndexShard newShard(ShardRouting routing, ShardPath shardPath, IndexMetaData indexMetaData, @Nullable IndexSearcherWrapper indexSearcherWrapper, Runnable globalCheckpointSyncer, @Nullable EngineFactory engineFactory, IndexingOperationListener... listeners) throws IOException {
    final Settings nodeSettings = Settings.builder().put("node.name", routing.currentNodeId()).build();
    final IndexSettings indexSettings = new IndexSettings(indexMetaData, nodeSettings);
    final IndexShard indexShard;
    final Store store = createStore(indexSettings, shardPath);
    boolean success = false;
    try {
        IndexCache indexCache = new IndexCache(indexSettings, new DisabledQueryCache(indexSettings), null);
        MapperService mapperService = MapperTestUtils.newMapperService(xContentRegistry(), createTempDir(), indexSettings.getSettings());
        mapperService.merge(indexMetaData, MapperService.MergeReason.MAPPING_RECOVERY, true);
        SimilarityService similarityService = new SimilarityService(indexSettings, Collections.emptyMap());
        final IndexEventListener indexEventListener = new IndexEventListener() {
        };
        final Engine.Warmer warmer = searcher -> {
        };
        IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(nodeSettings, new IndexFieldDataCache.Listener() {
        });
        IndexFieldDataService indexFieldDataService = new IndexFieldDataService(indexSettings, indicesFieldDataCache, new NoneCircuitBreakerService(), mapperService);
        indexShard = new IndexShard(routing, indexSettings, shardPath, store, indexCache, mapperService, similarityService, indexFieldDataService, engineFactory, indexEventListener, indexSearcherWrapper, threadPool, BigArrays.NON_RECYCLING_INSTANCE, warmer, globalCheckpointSyncer, Collections.emptyList(), Arrays.asList(listeners));
        success = true;
    } finally {
        if (success == false) {
            IOUtils.close(store);
        }
    }
    return indexShard;
}
Also used : IndexNotFoundException(org.apache.lucene.index.IndexNotFoundException) Versions(org.elasticsearch.common.lucene.uid.Versions) ByteSizeUnit(org.elasticsearch.common.unit.ByteSizeUnit) Arrays(java.util.Arrays) Nullable(org.elasticsearch.common.Nullable) BigArrays(org.elasticsearch.common.util.BigArrays) BiFunction(java.util.function.BiFunction) VersionType(org.elasticsearch.index.VersionType) Document(org.apache.lucene.document.Document) IndexRequest(org.elasticsearch.action.index.IndexRequest) Settings(org.elasticsearch.common.settings.Settings) ShardRoutingHelper(org.elasticsearch.cluster.routing.ShardRoutingHelper) Directory(org.apache.lucene.store.Directory) ThreadPool(org.elasticsearch.threadpool.ThreadPool) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) UidFieldMapper(org.elasticsearch.index.mapper.UidFieldMapper) EnumSet(java.util.EnumSet) PeerRecoveryTargetService(org.elasticsearch.indices.recovery.PeerRecoveryTargetService) Set(java.util.Set) MapperTestUtils(org.elasticsearch.index.MapperTestUtils) Engine(org.elasticsearch.index.engine.Engine) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) RecoverySource(org.elasticsearch.cluster.routing.RecoverySource) MapperService(org.elasticsearch.index.mapper.MapperService) Version(org.elasticsearch.Version) Matchers.contains(org.hamcrest.Matchers.contains) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) LeafReader(org.apache.lucene.index.LeafReader) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) StartRecoveryRequest(org.elasticsearch.indices.recovery.StartRecoveryRequest) XContentType(org.elasticsearch.common.xcontent.XContentType) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) RecoveryFailedException(org.elasticsearch.indices.recovery.RecoveryFailedException) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) BytesArray(org.elasticsearch.common.bytes.BytesArray) RecoverySourceHandler(org.elasticsearch.indices.recovery.RecoverySourceHandler) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IndexCache(org.elasticsearch.index.cache.IndexCache) SequenceNumbersService(org.elasticsearch.index.seqno.SequenceNumbersService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Store(org.elasticsearch.index.store.Store) IndexSettings(org.elasticsearch.index.IndexSettings) Node(org.elasticsearch.node.Node) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ESTestCase(org.elasticsearch.test.ESTestCase) Bits(org.apache.lucene.util.Bits) SourceToParse(org.elasticsearch.index.mapper.SourceToParse) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IndexFieldDataCache(org.elasticsearch.index.fielddata.IndexFieldDataCache) Uid(org.elasticsearch.index.mapper.Uid) RecoveryTarget(org.elasticsearch.indices.recovery.RecoveryTarget) IOUtils(org.apache.lucene.util.IOUtils) IOException(java.io.IOException) DirectoryService(org.elasticsearch.index.store.DirectoryService) EngineFactory(org.elasticsearch.index.engine.EngineFactory) TimeUnit(java.util.concurrent.TimeUnit) FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) DummyShardLock(org.elasticsearch.test.DummyShardLock) Collections(java.util.Collections) IndexSettings(org.elasticsearch.index.IndexSettings) Store(org.elasticsearch.index.store.Store) IndexFieldDataCache(org.elasticsearch.index.fielddata.IndexFieldDataCache) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) IndexCache(org.elasticsearch.index.cache.IndexCache) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) MapperService(org.elasticsearch.index.mapper.MapperService) Engine(org.elasticsearch.index.engine.Engine) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 4 with DisabledQueryCache

use of org.elasticsearch.index.cache.query.DisabledQueryCache in project elasticsearch by elastic.

the class IndexModule method newIndexService.

public IndexService newIndexService(NodeEnvironment environment, NamedXContentRegistry xContentRegistry, IndexService.ShardStoreDeleter shardStoreDeleter, CircuitBreakerService circuitBreakerService, BigArrays bigArrays, ThreadPool threadPool, ScriptService scriptService, ClusterService clusterService, Client client, IndicesQueryCache indicesQueryCache, MapperRegistry mapperRegistry, Consumer<ShardId> globalCheckpointSyncer, IndicesFieldDataCache indicesFieldDataCache) throws IOException {
    final IndexEventListener eventListener = freeze();
    IndexSearcherWrapperFactory searcherWrapperFactory = indexSearcherWrapper.get() == null ? (shard) -> null : indexSearcherWrapper.get();
    eventListener.beforeIndexCreated(indexSettings.getIndex(), indexSettings.getSettings());
    final String storeType = indexSettings.getValue(INDEX_STORE_TYPE_SETTING);
    final IndexStore store;
    if (Strings.isEmpty(storeType) || isBuiltinType(storeType)) {
        store = new IndexStore(indexSettings);
    } else {
        Function<IndexSettings, IndexStore> factory = storeTypes.get(storeType);
        if (factory == null) {
            throw new IllegalArgumentException("Unknown store type [" + storeType + "]");
        }
        store = factory.apply(indexSettings);
        if (store == null) {
            throw new IllegalStateException("store must not be null");
        }
    }
    final QueryCache queryCache;
    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);
    }
    return new IndexService(indexSettings, environment, xContentRegistry, new SimilarityService(indexSettings, similarities), shardStoreDeleter, analysisRegistry, engineFactory.get(), circuitBreakerService, bigArrays, threadPool, scriptService, clusterService, client, queryCache, store, eventListener, searcherWrapperFactory, mapperRegistry, indicesFieldDataCache, globalCheckpointSyncer, searchOperationListeners, indexOperationListeners);
}
Also used : IndicesQueryCache(org.elasticsearch.indices.IndicesQueryCache) IndicesQueryCache(org.elasticsearch.indices.IndicesQueryCache) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) IndexQueryCache(org.elasticsearch.index.cache.query.IndexQueryCache) QueryCache(org.elasticsearch.index.cache.query.QueryCache) IndexQueryCache(org.elasticsearch.index.cache.query.IndexQueryCache) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) IndexStore(org.elasticsearch.index.store.IndexStore) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache)

Example 5 with DisabledQueryCache

use of org.elasticsearch.index.cache.query.DisabledQueryCache in project elasticsearch by elastic.

the class AggregatorTestCase method createSearchContext.

protected SearchContext createSearchContext(IndexSearcher indexSearcher, IndexSettings indexSettings) {
    Engine.Searcher searcher = new Engine.Searcher("aggregator_test", indexSearcher);
    QueryCache queryCache = new DisabledQueryCache(indexSettings);
    QueryCachingPolicy queryCachingPolicy = new QueryCachingPolicy() {

        @Override
        public void onUse(Query query) {
        }

        @Override
        public boolean shouldCache(Query query) throws IOException {
            // never cache a query
            return false;
        }
    };
    ContextIndexSearcher contextIndexSearcher = new ContextIndexSearcher(searcher, queryCache, queryCachingPolicy);
    SearchContext searchContext = mock(SearchContext.class);
    when(searchContext.numberOfShards()).thenReturn(1);
    when(searchContext.searcher()).thenReturn(contextIndexSearcher);
    when(searchContext.fetchPhase()).thenReturn(new FetchPhase(Arrays.asList(new FetchSourceSubPhase(), new DocValueFieldsFetchSubPhase())));
    doAnswer(invocation -> {
        releasables.add((Releasable) invocation.getArguments()[0]);
        return null;
    }).when(searchContext).addReleasable(anyObject(), anyObject());
    return searchContext;
}
Also used : QueryCachingPolicy(org.apache.lucene.search.QueryCachingPolicy) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) QueryCache(org.apache.lucene.search.QueryCache) Query(org.apache.lucene.search.Query) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) FetchPhase(org.elasticsearch.search.fetch.FetchPhase) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) SearchContext(org.elasticsearch.search.internal.SearchContext) Engine(org.elasticsearch.index.engine.Engine) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) FetchSourceSubPhase(org.elasticsearch.search.fetch.subphase.FetchSourceSubPhase) DocValueFieldsFetchSubPhase(org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase)

Aggregations

DisabledQueryCache (org.elasticsearch.index.cache.query.DisabledQueryCache)6 Settings (org.elasticsearch.common.settings.Settings)3 IndexSettings (org.elasticsearch.index.IndexSettings)2 IndexCache (org.elasticsearch.index.cache.IndexCache)2 Engine (org.elasticsearch.index.engine.Engine)2 MapperService (org.elasticsearch.index.mapper.MapperService)2 SimilarityService (org.elasticsearch.index.similarity.SimilarityService)2 Store (org.elasticsearch.index.store.Store)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 BiFunction (java.util.function.BiFunction)1 Document (org.apache.lucene.document.Document)1 IndexNotFoundException (org.apache.lucene.index.IndexNotFoundException)1 LeafReader (org.apache.lucene.index.LeafReader)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1