Search in sources :

Example 1 with IndicesFieldDataCache

use of org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache in project elasticsearch by elastic.

the class AggregatorTestCase method createAggregator.

protected <A extends Aggregator, B extends AggregationBuilder> A createAggregator(B aggregationBuilder, IndexSearcher indexSearcher, MappedFieldType... fieldTypes) throws IOException {
    IndexSettings indexSettings = createIndexSettings();
    SearchContext searchContext = createSearchContext(indexSearcher, indexSettings);
    CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
    when(searchContext.bigArrays()).thenReturn(new MockBigArrays(Settings.EMPTY, circuitBreakerService));
    // TODO: now just needed for top_hits, this will need to be revised for other agg unit tests:
    MapperService mapperService = mapperServiceMock();
    when(mapperService.hasNested()).thenReturn(false);
    when(searchContext.mapperService()).thenReturn(mapperService);
    IndexFieldDataService ifds = new IndexFieldDataService(indexSettings, new IndicesFieldDataCache(Settings.EMPTY, new IndexFieldDataCache.Listener() {
    }), circuitBreakerService, mapperService);
    when(searchContext.fieldData()).thenReturn(ifds);
    SearchLookup searchLookup = new SearchLookup(mapperService, ifds, new String[] { "type" });
    when(searchContext.lookup()).thenReturn(searchLookup);
    QueryShardContext queryShardContext = queryShardContextMock(fieldTypes, indexSettings, circuitBreakerService);
    when(searchContext.getQueryShardContext()).thenReturn(queryShardContext);
    @SuppressWarnings("unchecked") A aggregator = (A) aggregationBuilder.build(searchContext, null).create(null, true);
    return aggregator;
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) SearchContext(org.elasticsearch.search.internal.SearchContext) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) MapperService(org.elasticsearch.index.mapper.MapperService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) SearchLookup(org.elasticsearch.search.lookup.SearchLookup)

Example 2 with IndicesFieldDataCache

use of org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache in project elasticsearch by elastic.

the class IndexFieldDataServiceTests method doTestRequireDocValues.

private void doTestRequireDocValues(MappedFieldType ft) {
    ThreadPool threadPool = new TestThreadPool("random_threadpool_name");
    try {
        IndicesFieldDataCache cache = new IndicesFieldDataCache(Settings.EMPTY, null);
        IndexFieldDataService ifds = new IndexFieldDataService(IndexSettingsModule.newIndexSettings("test", Settings.EMPTY), cache, null, null);
        ft.setName("some_long");
        ft.setHasDocValues(true);
        // no exception
        ifds.getForField(ft);
        ft.setHasDocValues(false);
        try {
            ifds.getForField(ft);
            fail();
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage(), containsString("doc values"));
        }
    } finally {
        threadPool.shutdown();
    }
}
Also used : IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool)

Example 3 with IndicesFieldDataCache

use of org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache in project elasticsearch by elastic.

the class IndicesService method verifyIndexMetadata.

/**
     * This method verifies that the given {@code metaData} holds sane values to create an {@link IndexService}.
     * This method tries to update the meta data of the created {@link IndexService} if the given {@code metaDataUpdate} is different from the given {@code metaData}.
     * This method will throw an exception if the creation or the update fails.
     * The created {@link IndexService} will not be registered and will be closed immediately.
     */
public synchronized void verifyIndexMetadata(IndexMetaData metaData, IndexMetaData metaDataUpdate) throws IOException {
    final List<Closeable> closeables = new ArrayList<>();
    try {
        IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() {
        });
        closeables.add(indicesFieldDataCache);
        IndicesQueryCache indicesQueryCache = new IndicesQueryCache(settings);
        closeables.add(indicesQueryCache);
        // this will also fail if some plugin fails etc. which is nice since we can verify that early
        final IndexService service = createIndexService("metadata verification", metaData, indicesQueryCache, indicesFieldDataCache, emptyList(), s -> {
        });
        closeables.add(() -> service.close("metadata verification", false));
        service.mapperService().merge(metaData, MapperService.MergeReason.MAPPING_RECOVERY, true);
        if (metaData.equals(metaDataUpdate) == false) {
            service.updateMetaData(metaDataUpdate);
        }
    } finally {
        IOUtils.close(closeables);
    }
}
Also used : IndexFieldDataCache(org.elasticsearch.index.fielddata.IndexFieldDataCache) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) IndexService(org.elasticsearch.index.IndexService) Closeable(java.io.Closeable) CollectionUtils.arrayAsArrayList(org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList) ArrayList(java.util.ArrayList)

Example 4 with IndicesFieldDataCache

use of org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache in project elasticsearch by elastic.

the class AbstractSortTestCase method createMockShardContext.

protected QueryShardContext createMockShardContext() {
    Index index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_");
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(index, Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build());
    IndicesFieldDataCache cache = new IndicesFieldDataCache(Settings.EMPTY, null);
    IndexFieldDataService ifds = new IndexFieldDataService(IndexSettingsModule.newIndexSettings("test", Settings.EMPTY), cache, null, null);
    BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(idxSettings, new BitsetFilterCache.Listener() {

        @Override
        public void onRemoval(ShardId shardId, Accountable accountable) {
        }

        @Override
        public void onCache(ShardId shardId, Accountable accountable) {
        }
    });
    long nowInMillis = randomNonNegativeLong();
    return new QueryShardContext(0, idxSettings, bitsetFilterCache, ifds, null, null, scriptService, xContentRegistry(), null, null, () -> nowInMillis) {

        @Override
        public MappedFieldType fieldMapper(String name) {
            return provideMappedFieldType(name);
        }

        @Override
        public ObjectMapper getObjectMapper(String name) {
            BuilderContext context = new BuilderContext(this.getIndexSettings().getSettings(), new ContentPath());
            return new ObjectMapper.Builder<>(name).nested(Nested.newNested(false, false)).build(context);
        }
    };
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) Accountable(org.apache.lucene.util.Accountable) Index(org.elasticsearch.index.Index) ContentPath(org.elasticsearch.index.mapper.ContentPath) ShardId(org.elasticsearch.index.shard.ShardId) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) BuilderContext(org.elasticsearch.index.mapper.Mapper.BuilderContext) BitsetFilterCache(org.elasticsearch.index.cache.bitset.BitsetFilterCache)

Example 5 with IndicesFieldDataCache

use of org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache in project elasticsearch by elastic.

the class InternalTestCluster method ensureEstimatedStats.

@Override
public void ensureEstimatedStats() {
    if (size() > 0) {
        // of the breakers
        for (NodeAndClient nodeAndClient : nodes.values()) {
            final IndicesFieldDataCache fdCache = getInstanceFromNode(IndicesService.class, nodeAndClient.node).getIndicesFieldDataCache();
            // Clean up the cache, ensuring that entries' listeners have been called
            fdCache.getCache().refresh();
            final String name = nodeAndClient.name;
            final CircuitBreakerService breakerService = getInstanceFromNode(CircuitBreakerService.class, nodeAndClient.node);
            CircuitBreaker fdBreaker = breakerService.getBreaker(CircuitBreaker.FIELDDATA);
            assertThat("Fielddata breaker not reset to 0 on node: " + name, fdBreaker.getUsed(), equalTo(0L));
            // fail if it never reached 0
            try {
                assertBusy(new Runnable() {

                    @Override
                    public void run() {
                        CircuitBreaker reqBreaker = breakerService.getBreaker(CircuitBreaker.REQUEST);
                        assertThat("Request breaker not reset to 0 on node: " + name, reqBreaker.getUsed(), equalTo(0L));
                    }
                });
            } catch (Exception e) {
                fail("Exception during check for request breaker reset to 0: " + e);
            }
            NodeService nodeService = getInstanceFromNode(NodeService.class, nodeAndClient.node);
            CommonStatsFlags flags = new CommonStatsFlags(Flag.FieldData, Flag.QueryCache, Flag.Segments);
            NodeStats stats = nodeService.stats(flags, false, false, false, false, false, false, false, false, false, false, false);
            assertThat("Fielddata size must be 0 on node: " + stats.getNode(), stats.getIndices().getFieldData().getMemorySizeInBytes(), equalTo(0L));
            assertThat("Query cache size must be 0 on node: " + stats.getNode(), stats.getIndices().getQueryCache().getMemorySizeInBytes(), equalTo(0L));
            assertThat("FixedBitSet cache size must be 0 on node: " + stats.getNode(), stats.getIndices().getSegments().getBitsetMemoryInBytes(), equalTo(0L));
        }
    }
}
Also used : IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags) NodeService(org.elasticsearch.node.NodeService) IndicesService(org.elasticsearch.indices.IndicesService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) NodeValidationException(org.elasticsearch.node.NodeValidationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException)

Aggregations

IndicesFieldDataCache (org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache)7 IndexSettings (org.elasticsearch.index.IndexSettings)3 IndexFieldDataService (org.elasticsearch.index.fielddata.IndexFieldDataService)3 IOException (java.io.IOException)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)2 Settings (org.elasticsearch.common.settings.Settings)2 IndexFieldDataCache (org.elasticsearch.index.fielddata.IndexFieldDataCache)2 IndicesService (org.elasticsearch.indices.IndicesService)2 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)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 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 BiFunction (java.util.function.BiFunction)1 Document (org.apache.lucene.document.Document)1