Search in sources :

Example 16 with NoneCircuitBreakerService

use of org.opensearch.indices.breaker.NoneCircuitBreakerService in project OpenSearch by opensearch-project.

the class GatewayMetaStatePersistedStateTests method setUp.

@Override
public void setUp() throws Exception {
    bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
    nodeEnvironment = newNodeEnvironment();
    localNode = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Collections.emptyMap(), Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
    clusterName = new ClusterName(randomAlphaOfLength(10));
    settings = Settings.builder().put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName.value()).build();
    super.setUp();
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) ClusterName(org.opensearch.cluster.ClusterName) MockBigArrays(org.opensearch.common.util.MockBigArrays) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 17 with NoneCircuitBreakerService

use of org.opensearch.indices.breaker.NoneCircuitBreakerService in project OpenSearch by opensearch-project.

the class BucketsAggregatorTests method buildMergeAggregator.

public BucketsAggregator buildMergeAggregator() throws IOException {
    try (Directory directory = newDirectory()) {
        try (RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
            Document document = new Document();
            document.add(new SortedNumericDocValuesField("numeric", 0));
            indexWriter.addDocument(document);
        }
        try (IndexReader indexReader = DirectoryReader.open(directory)) {
            IndexSearcher indexSearcher = new IndexSearcher(indexReader);
            SearchContext searchContext = createSearchContext(indexSearcher, createIndexSettings(), null, new MultiBucketConsumerService.MultiBucketConsumer(DEFAULT_MAX_BUCKETS, new NoneCircuitBreakerService().getBreaker(CircuitBreaker.REQUEST)), new NumberFieldMapper.NumberFieldType("test", NumberFieldMapper.NumberType.INTEGER));
            return new BucketsAggregator("test", AggregatorFactories.EMPTY, searchContext, null, null, null) {

                @Override
                protected LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException {
                    return null;
                }

                @Override
                public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws IOException {
                    return new InternalAggregation[0];
                }

                @Override
                public InternalAggregation buildEmptyAggregation() {
                    return null;
                }
            };
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) NumberFieldMapper(org.opensearch.index.mapper.NumberFieldMapper) SearchContext(org.opensearch.search.internal.SearchContext) Document(org.apache.lucene.document.Document) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) LeafBucketCollector(org.opensearch.search.aggregations.LeafBucketCollector) MultiBucketConsumerService(org.opensearch.search.aggregations.MultiBucketConsumerService) IndexReader(org.apache.lucene.index.IndexReader) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 18 with NoneCircuitBreakerService

use of org.opensearch.indices.breaker.NoneCircuitBreakerService in project OpenSearch by opensearch-project.

the class BestDocsDeferringCollectorTests method testReplay.

public void testReplay() throws Exception {
    Directory directory = newDirectory();
    RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
    int numDocs = randomIntBetween(1, 128);
    int maxNumValues = randomInt(16);
    for (int i = 0; i < numDocs; i++) {
        Document document = new Document();
        document.add(new StringField("field", String.valueOf(randomInt(maxNumValues)), Field.Store.NO));
        indexWriter.addDocument(document);
    }
    indexWriter.close();
    IndexReader indexReader = DirectoryReader.open(directory);
    IndexSearcher indexSearcher = new IndexSearcher(indexReader);
    TermQuery termQuery = new TermQuery(new Term("field", String.valueOf(randomInt(maxNumValues))));
    TopDocs topDocs = indexSearcher.search(termQuery, numDocs);
    final AtomicLong bytes = new AtomicLong(0);
    BestDocsDeferringCollector collector = new BestDocsDeferringCollector(numDocs, new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService()), bytes::addAndGet);
    Set<Integer> deferredCollectedDocIds = new HashSet<>();
    collector.setDeferredCollector(Collections.singleton(testCollector(deferredCollectedDocIds)));
    collector.preCollection();
    indexSearcher.search(termQuery, collector);
    collector.postCollection();
    collector.prepareSelectedBuckets(0);
    assertEquals(topDocs.scoreDocs.length, deferredCollectedDocIds.size());
    for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
        assertTrue("expected docid [" + scoreDoc.doc + "] is missing", deferredCollectedDocIds.contains(scoreDoc.doc));
    }
    collector.close();
    indexReader.close();
    directory.close();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TermQuery(org.apache.lucene.search.TermQuery) MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) Term(org.apache.lucene.index.Term) MockBigArrays(org.opensearch.common.util.MockBigArrays) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc) TopDocs(org.apache.lucene.search.TopDocs) AtomicLong(java.util.concurrent.atomic.AtomicLong) StringField(org.apache.lucene.document.StringField) IndexReader(org.apache.lucene.index.IndexReader) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) HashSet(java.util.HashSet)

Example 19 with NoneCircuitBreakerService

use of org.opensearch.indices.breaker.NoneCircuitBreakerService in project OpenSearch by opensearch-project.

the class InternalVariableWidthHistogramTests method testSingleShardReduceLong.

public void testSingleShardReduceLong() {
    InternalVariableWidthHistogram dummy_histogram = createEmptyTestInstance();
    List<InternalVariableWidthHistogram.Bucket> buckets = new ArrayList<>();
    for (long value : new long[] { 1, 2, 5, 10, 12, 200 }) {
        InternalVariableWidthHistogram.Bucket.BucketBounds bounds = new InternalVariableWidthHistogram.Bucket.BucketBounds(value, value + 1);
        InternalVariableWidthHistogram.Bucket bucket = new InternalVariableWidthHistogram.Bucket(value, bounds, 3, format, InternalAggregations.EMPTY);
        buckets.add(bucket);
    }
    InternalVariableWidthHistogram histogram = dummy_histogram.create(buckets);
    MockBigArrays bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
    ScriptService mockScriptService = mockScriptService();
    MultiBucketConsumerService.MultiBucketConsumer bucketConsumer = new MultiBucketConsumerService.MultiBucketConsumer(DEFAULT_MAX_BUCKETS, new NoneCircuitBreakerService().getBreaker(CircuitBreaker.REQUEST));
    InternalAggregation.ReduceContext context = InternalAggregation.ReduceContext.forFinalReduction(bigArrays, mockScriptService, bucketConsumer, PipelineAggregator.PipelineTree.EMPTY);
    ArrayList<InternalAggregation> aggs = new ArrayList<>();
    aggs.add(histogram);
    List<InternalVariableWidthHistogram.Bucket> reduced_buckets = ((InternalVariableWidthHistogram) histogram.reduce(aggs, context)).getBuckets();
    // Final clusters should be [ (1,2,5), (10,12), 200) ]
    // Final centroids should be [ 3, 11, 200 ]
    // Final keys should be [ 1, 5, 200 ]
    double double_error = 1d / 10000d;
    assertEquals(1d, reduced_buckets.get(0).min(), double_error);
    assertEquals((8d / 3d), (double) reduced_buckets.get(0).getKey(), double_error);
    assertEquals(9, reduced_buckets.get(0).getDocCount());
    assertEquals(10d, reduced_buckets.get(1).min(), double_error);
    assertEquals(11d, (double) reduced_buckets.get(1).getKey(), double_error);
    assertEquals(6, reduced_buckets.get(1).getDocCount());
    assertEquals(200d, reduced_buckets.get(2).min(), double_error);
    assertEquals(200d, (double) reduced_buckets.get(2).getKey(), double_error);
    assertEquals(3, reduced_buckets.get(2).getDocCount());
}
Also used : MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) ArrayList(java.util.ArrayList) MockBigArrays(org.opensearch.common.util.MockBigArrays) ScriptService(org.opensearch.script.ScriptService) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) MultiBucketConsumerService(org.opensearch.search.aggregations.MultiBucketConsumerService) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 20 with NoneCircuitBreakerService

use of org.opensearch.indices.breaker.NoneCircuitBreakerService in project OpenSearch by opensearch-project.

the class InternalVariableWidthHistogramTests method testSingleShardReduceDouble.

public void testSingleShardReduceDouble() {
    InternalVariableWidthHistogram dummy_histogram = createEmptyTestInstance();
    List<InternalVariableWidthHistogram.Bucket> buckets = new ArrayList<>();
    for (double value : new double[] { -1.3, -1.3, 12.0, 13.0, 20.0, 21.5, 23.0, 24.5 }) {
        InternalVariableWidthHistogram.Bucket.BucketBounds bounds = new InternalVariableWidthHistogram.Bucket.BucketBounds(value - 0.7, value + 1);
        InternalVariableWidthHistogram.Bucket bucket = new InternalVariableWidthHistogram.Bucket(value, bounds, 1, format, InternalAggregations.EMPTY);
        buckets.add(bucket);
    }
    InternalVariableWidthHistogram histogram = dummy_histogram.create(buckets);
    MockBigArrays bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
    ScriptService mockScriptService = mockScriptService();
    MultiBucketConsumerService.MultiBucketConsumer bucketConsumer = new MultiBucketConsumerService.MultiBucketConsumer(DEFAULT_MAX_BUCKETS, new NoneCircuitBreakerService().getBreaker(CircuitBreaker.REQUEST));
    InternalAggregation.ReduceContext context = InternalAggregation.ReduceContext.forFinalReduction(bigArrays, mockScriptService, bucketConsumer, PipelineAggregator.PipelineTree.EMPTY);
    ArrayList<InternalAggregation> aggs = new ArrayList<>();
    aggs.add(histogram);
    List<InternalVariableWidthHistogram.Bucket> reduced_buckets = ((InternalVariableWidthHistogram) histogram.reduce(aggs, context)).getBuckets();
    // Final clusters should be [ (-1.3,-1.3), (12.0,13.0), (20.0, 21.5, 23.0, 24.5) ]
    // Final centroids should be [ -1.3, 12.5, 22.25 ]
    // Final keys should be [ -1.3, 11.7, 19.7 ]
    double double_error = 1d / 10000d;
    assertEquals(-2.0, reduced_buckets.get(0).min(), double_error);
    assertEquals(-1.3, (double) reduced_buckets.get(0).getKey(), double_error);
    assertEquals(2, reduced_buckets.get(0).getDocCount());
    assertEquals(11.3, reduced_buckets.get(1).min(), double_error);
    assertEquals(12.5, (double) reduced_buckets.get(1).getKey(), double_error);
    assertEquals(2, reduced_buckets.get(1).getDocCount());
    assertEquals(19.3, reduced_buckets.get(2).min(), double_error);
    assertEquals(22.25, (double) reduced_buckets.get(2).getKey(), double_error);
    assertEquals(4, reduced_buckets.get(2).getDocCount());
}
Also used : MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) ArrayList(java.util.ArrayList) MockBigArrays(org.opensearch.common.util.MockBigArrays) ScriptService(org.opensearch.script.ScriptService) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) MultiBucketConsumerService(org.opensearch.search.aggregations.MultiBucketConsumerService) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Aggregations

NoneCircuitBreakerService (org.opensearch.indices.breaker.NoneCircuitBreakerService)51 MockPageCacheRecycler (org.opensearch.common.util.MockPageCacheRecycler)30 MockBigArrays (org.opensearch.common.util.MockBigArrays)24 NetworkService (org.opensearch.common.network.NetworkService)20 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)15 ArrayList (java.util.ArrayList)14 TestThreadPool (org.opensearch.threadpool.TestThreadPool)14 Before (org.junit.Before)11 MockNioTransport (org.opensearch.transport.nio.MockNioTransport)10 Directory (org.apache.lucene.store.Directory)9 IOException (java.io.IOException)8 ScriptService (org.opensearch.script.ScriptService)8 IndexSearcher (org.apache.lucene.search.IndexSearcher)7 ActionListener (org.opensearch.action.ActionListener)7 InternalAggregation (org.opensearch.search.aggregations.InternalAggregation)7 List (java.util.List)6 IndexReader (org.apache.lucene.index.IndexReader)6 ThreadPool (org.opensearch.threadpool.ThreadPool)6 Collections (java.util.Collections)5 HashSet (java.util.HashSet)5