Search in sources :

Example 1 with IndicesQueryCache

use of org.opensearch.indices.IndicesQueryCache in project OpenSearch by opensearch-project.

the class IndexShardTests method testShardStats.

public void testShardStats() throws IOException {
    IndexShard shard = newStartedShard();
    ShardStats stats = new ShardStats(shard.routingEntry(), shard.shardPath(), new CommonStats(new IndicesQueryCache(Settings.EMPTY), shard, new CommonStatsFlags()), shard.commitStats(), shard.seqNoStats(), shard.getRetentionLeaseStats());
    assertEquals(shard.shardPath().getRootDataPath().toString(), stats.getDataPath());
    assertEquals(shard.shardPath().getRootStatePath().toString(), stats.getStatePath());
    assertEquals(shard.shardPath().isCustomDataPath(), stats.isCustomDataPath());
    // try to serialize it to ensure values survive the serialization
    BytesStreamOutput out = new BytesStreamOutput();
    stats.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    stats = new ShardStats(in);
    XContentBuilder builder = jsonBuilder();
    builder.startObject();
    stats.toXContent(builder, EMPTY_PARAMS);
    builder.endObject();
    String xContent = Strings.toString(builder);
    StringBuilder expectedSubSequence = new StringBuilder("\"shard_path\":{\"state_path\":\"");
    expectedSubSequence.append(shard.shardPath().getRootStatePath().toString());
    expectedSubSequence.append("\",\"data_path\":\"");
    expectedSubSequence.append(shard.shardPath().getRootDataPath().toString());
    expectedSubSequence.append("\",\"is_custom_data_path\":").append(shard.shardPath().isCustomDataPath()).append("}");
    if (Constants.WINDOWS) {
    // Some path weirdness on windows
    } else {
        assertTrue(xContent.contains(expectedSubSequence));
    }
    closeShards(shard);
}
Also used : ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) IndicesQueryCache(org.opensearch.indices.IndicesQueryCache) CommonStats(org.opensearch.action.admin.indices.stats.CommonStats) CommonStatsFlags(org.opensearch.action.admin.indices.stats.CommonStatsFlags) StreamInput(org.opensearch.common.io.stream.StreamInput) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 2 with IndicesQueryCache

use of org.opensearch.indices.IndicesQueryCache 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 3 with IndicesQueryCache

use of org.opensearch.indices.IndicesQueryCache in project OpenSearch by opensearch-project.

the class IndexModuleTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    indicesQueryCache = new IndicesQueryCache(settings);
    indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
    index = indexSettings.getIndex();
    environment = TestEnvironment.newEnvironment(settings);
    emptyAnalysisRegistry = new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap());
    threadPool = new TestThreadPool("test");
    circuitBreakerService = new NoneCircuitBreakerService();
    PageCacheRecycler pageCacheRecycler = new PageCacheRecycler(settings);
    bigArrays = new BigArrays(pageCacheRecycler, circuitBreakerService, CircuitBreaker.REQUEST);
    scriptService = new ScriptService(settings, Collections.emptyMap(), Collections.emptyMap());
    clusterService = ClusterServiceUtils.createClusterService(threadPool);
    nodeEnvironment = new NodeEnvironment(settings, environment);
    mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry();
}
Also used : IndicesQueryCache(org.opensearch.indices.IndicesQueryCache) ScriptService(org.opensearch.script.ScriptService) AnalysisRegistry(org.opensearch.index.analysis.AnalysisRegistry) BigArrays(org.opensearch.common.util.BigArrays) IndicesModule(org.opensearch.indices.IndicesModule) PageCacheRecycler(org.opensearch.common.util.PageCacheRecycler) NodeEnvironment(org.opensearch.env.NodeEnvironment) TestThreadPool(org.opensearch.threadpool.TestThreadPool) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Aggregations

IndicesQueryCache (org.opensearch.indices.IndicesQueryCache)3 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.hasToString (org.hamcrest.Matchers.hasToString)1 CommonStats (org.opensearch.action.admin.indices.stats.CommonStats)1 CommonStatsFlags (org.opensearch.action.admin.indices.stats.CommonStatsFlags)1 ShardStats (org.opensearch.action.admin.indices.stats.ShardStats)1 CheckedFunction (org.opensearch.common.CheckedFunction)1 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)1 StreamInput (org.opensearch.common.io.stream.StreamInput)1 BigArrays (org.opensearch.common.util.BigArrays)1 PageCacheRecycler (org.opensearch.common.util.PageCacheRecycler)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1 NodeEnvironment (org.opensearch.env.NodeEnvironment)1 AnalysisRegistry (org.opensearch.index.analysis.AnalysisRegistry)1 IndexAnalyzers (org.opensearch.index.analysis.IndexAnalyzers)1 DisabledQueryCache (org.opensearch.index.cache.query.DisabledQueryCache)1 IndexQueryCache (org.opensearch.index.cache.query.IndexQueryCache)1 QueryCache (org.opensearch.index.cache.query.QueryCache)1 IndexEventListener (org.opensearch.index.shard.IndexEventListener)1 SimilarityService (org.opensearch.index.similarity.SimilarityService)1