diff --git a/benchmarks/src/main/java/org/opensearch/benchmark/search/aggregations/BKDTreeMultiRangesTraverseBenchmark.java b/benchmarks/src/main/java/org/opensearch/benchmark/search/aggregations/BKDTreeMultiRangesTraverseBenchmark.java index 0ef0a261cecd0..c29808cb3ae4f 100644 --- a/benchmarks/src/main/java/org/opensearch/benchmark/search/aggregations/BKDTreeMultiRangesTraverseBenchmark.java +++ b/benchmarks/src/main/java/org/opensearch/benchmark/search/aggregations/BKDTreeMultiRangesTraverseBenchmark.java @@ -45,7 +45,7 @@ import org.opensearch.index.mapper.MappedFieldType; import org.opensearch.index.mapper.NumberFieldMapper; import org.opensearch.index.mapper.NumericPointEncoder; -import org.opensearch.search.optimization.filterrewrite.Ranges; +import org.opensearch.search.optimization.filterrewrite.PackedValueRanges; import org.opensearch.search.optimization.filterrewrite.TreeTraversal; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; @@ -102,7 +102,7 @@ public static class treeState { // multiRangesTraverse params PointValues.PointTree pointTree; - Ranges ranges; + PackedValueRanges packedValueRanges; BiConsumer> collectRangeIDs; int maxNumNonZeroRanges = Integer.MAX_VALUE; @@ -136,7 +136,7 @@ public void setup() throws IOException { uppers[i] = numericPointEncoder.encodePoint(i * bucketWidth); } - ranges = new Ranges(lowers, uppers); + packedValueRanges = new PackedValueRanges(lowers, uppers); } @TearDown @@ -154,7 +154,7 @@ public Map> multiRangeTraverseTree(treeState state) throw TreeTraversal.RangeAwareIntersectVisitor treeVisitor = new TreeTraversal.DocCollectRangeAwareIntersectVisitor( state.pointTree, - state.ranges, + state.packedValueRanges, state.maxNumNonZeroRanges, (activeIndex, docID) -> { if (mockIDCollect.containsKey(activeIndex)) { diff --git a/release-notes/opensearch.release-notes-2.1.0.md b/release-notes/opensearch.release-notes-2.1.0.md index b32864990b82e..e55aab4810c2c 100644 --- a/release-notes/opensearch.release-notes-2.1.0.md +++ b/release-notes/opensearch.release-notes-2.1.0.md @@ -61,7 +61,7 @@ * Update github action gradle-check to use pull_request_target for accessing token (#3728) ([#3731](https://github.com/opensearch-project/opensearch/pull/3731)) * Add gradle check test for github workflows (#3717) ([#3723](https://github.com/opensearch-project/opensearch/pull/3723)) * Used set to make shell scripts more strict (#3278) ([#3344](https://github.com/opensearch-project/opensearch/pull/3344)) -* Bootstrap should implement a denylist of Java versions (ranges) (#3164) ([#3292](https://github.com/opensearch-project/opensearch/pull/3292)) +* Bootstrap should implement a denylist of Java versions (packedValueRanges) (#3164) ([#3292](https://github.com/opensearch-project/opensearch/pull/3292)) * Add Github Workflow to build and publish lucene snapshots. (#2906) ([#3038](https://github.com/opensearch-project/opensearch/pull/3038)) * Remove JavaVersion in favour of standard Runtime.Version (java-version-checker) (#3027) ([#3034](https://github.com/opensearch-project/opensearch/pull/3034)) * Remove JavaVersion, use builtin Runtime.Version to deal with runtime versions (#3006) ([#3013](https://github.com/opensearch-project/opensearch/pull/3013)) diff --git a/release-notes/opensearch.release-notes-2.14.0.md b/release-notes/opensearch.release-notes-2.14.0.md index c5fc3e895c45d..c55e0a6c27196 100644 --- a/release-notes/opensearch.release-notes-2.14.0.md +++ b/release-notes/opensearch.release-notes-2.14.0.md @@ -34,7 +34,7 @@ - [Search Pipeline] Handle default pipeline for multiple indices ([#13276](https://github.com/opensearch-project/OpenSearch/pull/13276)) - [Batch Ingestion] Add `batch_size` to `_bulk` API. ([#12457](https://github.com/opensearch-project/OpenSearch/issues/12457)) - [Remote Store] Add capability of doing refresh as determined by the translog ([#12992](https://github.com/opensearch-project/OpenSearch/pull/12992)) -- Support multi ranges traversal when doing date histogram rewrite optimization. ([#13317](https://github.com/opensearch-project/OpenSearch/pull/13317)) +- Support multi packedValueRanges traversal when doing date histogram rewrite optimization. ([#13317](https://github.com/opensearch-project/OpenSearch/pull/13317)) ### Dependencies - Bump `org.apache.commons:commons-configuration2` from 2.10.0 to 2.10.1 ([#12896](https://github.com/opensearch-project/OpenSearch/pull/12896)) diff --git a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/DateHistogramAggregatorBridge.java b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/DateHistogramAggregatorBridge.java index 164e6a2c9aefd..b73e3f5442117 100644 --- a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/DateHistogramAggregatorBridge.java +++ b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/DateHistogramAggregatorBridge.java @@ -57,7 +57,7 @@ public void prepareFromSegment(LeafReaderContext leaf) throws IOException { optimizationContext.setRangesFromSegment(buildRanges(bounds)); } - private Ranges buildRanges(long[] bounds) { + private PackedValueRanges buildRanges(long[] bounds) { bounds = processHardBounds(bounds); if (bounds == null) { return null; diff --git a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/Helper.java b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/Helper.java index eb57cd90b9ad9..a79a7d5d0b1a0 100644 --- a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/Helper.java +++ b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/Helper.java @@ -155,7 +155,7 @@ private static long[] getBoundsWithRangeQuery(PointRangeQuery prq, String fieldN * Creates the date ranges from date histo aggregations using its interval, * and min/max boundaries */ - static Ranges createRangesFromAgg( + static PackedValueRanges createRangesFromAgg( final DateFieldMapper.DateFieldType fieldType, final long interval, final Rounding.Prepared preparedRounding, @@ -208,6 +208,6 @@ static Ranges createRangesFromAgg( uppers[i] = max; } - return new Ranges(lowers, uppers); + return new PackedValueRanges(lowers, uppers); } } diff --git a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/OptimizationContext.java b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/OptimizationContext.java index 98c42f3aea049..8611b0b1fd201 100644 --- a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/OptimizationContext.java +++ b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/OptimizationContext.java @@ -42,8 +42,8 @@ public final class OptimizationContext { int maxAggRewriteFilters; String shardId; - private Ranges ranges; - private Ranges rangesFromSegment; + private PackedValueRanges packedValueRanges; + private PackedValueRanges packedValueRangesFromSegment; // debug info related fields private int leaf; @@ -70,9 +70,9 @@ public boolean canOptimize(final Object parent, SearchContext context) { } public void prepare() throws IOException { - assert ranges == null : "Ranges should only be built once at shard level, but they are already built"; + assert packedValueRanges == null : "Ranges should only be built once at shard level, but they are already built"; aggregatorBridge.prepare(); - if (ranges != null) { + if (packedValueRanges != null) { preparedAtShardLevel = true; } } @@ -81,17 +81,17 @@ public void prepareFromSegment(LeafReaderContext leaf) throws IOException { aggregatorBridge.prepareFromSegment(leaf); } - void setRanges(Ranges ranges) { - this.ranges = ranges; + void setRanges(PackedValueRanges packedValueRanges) { + this.packedValueRanges = packedValueRanges; } - void setRangesFromSegment(Ranges ranges) { - this.rangesFromSegment = ranges; + void setRangesFromSegment(PackedValueRanges packedValueRanges) { + this.packedValueRangesFromSegment = packedValueRanges; } - Ranges getRanges() { - if (rangesFromSegment != null) return rangesFromSegment; - return ranges; + PackedValueRanges getRanges() { + if (packedValueRangesFromSegment != null) return packedValueRangesFromSegment; + return packedValueRanges; } /** @@ -130,8 +130,8 @@ public boolean tryOptimize( return false; } - Ranges ranges = tryBuildRangesFromSegment(leafCtx, segmentMatchAll); - if (ranges == null) return false; + PackedValueRanges packedValueRanges = tryBuildRangesFromSegment(leafCtx, segmentMatchAll); + if (packedValueRanges == null) return false; aggregatorBridge.tryOptimize(values, incrementDocCount, sub); @@ -139,7 +139,7 @@ public boolean tryOptimize( logger.debug("Fast filter optimization applied to shard {} segment {}", shardId, leafCtx.ord); logger.debug("crossed leaf nodes: {}, inner nodes: {}", leaf, inner); - rangesFromSegment = null; + packedValueRangesFromSegment = null; return true; } @@ -147,17 +147,17 @@ public boolean tryOptimize( * Even when ranges cannot be built at shard level, we can still build ranges * at segment level when it's functionally match-all at segment level */ - private Ranges tryBuildRangesFromSegment(LeafReaderContext leafCtx, boolean segmentMatchAll) throws IOException { + private PackedValueRanges tryBuildRangesFromSegment(LeafReaderContext leafCtx, boolean segmentMatchAll) throws IOException { if (!preparedAtShardLevel && !segmentMatchAll) { return null; } - if (ranges == null) { // not built at shard level but segment match all + if (packedValueRanges == null) { // not built at shard level but segment match all logger.debug("Shard {} segment {} functionally match all documents. Build the fast filter", shardId, leafCtx.ord); prepareFromSegment(leafCtx); - return rangesFromSegment; + return packedValueRangesFromSegment; } - return ranges; + return packedValueRanges; } /** diff --git a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/Ranges.java b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/PackedValueRanges.java similarity index 88% rename from server/src/main/java/org/opensearch/search/optimization/filterrewrite/Ranges.java rename to server/src/main/java/org/opensearch/search/optimization/filterrewrite/PackedValueRanges.java index c9aaf0b39f9c9..4e839fe20e5bd 100644 --- a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/Ranges.java +++ b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/PackedValueRanges.java @@ -13,14 +13,14 @@ /** * Internal ranges representation for the filter rewrite optimization */ -public final class Ranges { +public final class PackedValueRanges { static ArrayUtil.ByteArrayComparator comparator; byte[][] lowers; // inclusive byte[][] uppers; // exclusive int size; int byteLen; - public Ranges(byte[][] lowers, byte[][] uppers) { + public PackedValueRanges(byte[][] lowers, byte[][] uppers) { this.lowers = lowers; this.uppers = uppers; assert lowers.length == uppers.length; @@ -42,11 +42,11 @@ public static boolean withinUpperBound(byte[] value, byte[] upperBound) { } public boolean withinLowerBound(byte[] value, int idx) { - return Ranges.withinLowerBound(value, lowers[idx]); + return PackedValueRanges.withinLowerBound(value, lowers[idx]); } public boolean withinUpperBound(byte[] value, int idx) { - return Ranges.withinUpperBound(value, uppers[idx]); + return PackedValueRanges.withinUpperBound(value, uppers[idx]); } public boolean withinRange(byte[] value, int idx) { diff --git a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/RangeAggregatorBridge.java b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/RangeAggregatorBridge.java index 6fda3b4ea6951..016711684f85f 100644 --- a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/RangeAggregatorBridge.java +++ b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/RangeAggregatorBridge.java @@ -66,7 +66,7 @@ protected void buildRanges(RangeAggregator.Range[] ranges) { uppers[i] = upper; } - optimizationContext.setRanges(new Ranges(lowers, uppers)); + optimizationContext.setRanges(new PackedValueRanges(lowers, uppers)); } @Override diff --git a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/TreeTraversal.java b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/TreeTraversal.java index 3b837cf161c3c..3924724566e4c 100644 --- a/server/src/main/java/org/opensearch/search/optimization/filterrewrite/TreeTraversal.java +++ b/server/src/main/java/org/opensearch/search/optimization/filterrewrite/TreeTraversal.java @@ -60,16 +60,16 @@ public static OptimizationContext.DebugInfo multiRangesTraverse(RangeAwareInters */ public static abstract class RangeAwareIntersectVisitor implements PointValues.IntersectVisitor { private final PointValues.PointTree pointTree; - private final Ranges ranges; + private final PackedValueRanges packedValueRanges; private final int maxNumNonZeroRange; protected int visitedRange = 0; protected int activeIndex; - public RangeAwareIntersectVisitor(PointValues.PointTree pointTree, Ranges ranges, int maxNumNonZeroRange) { - this.ranges = ranges; + public RangeAwareIntersectVisitor(PointValues.PointTree pointTree, PackedValueRanges packedValueRanges, int maxNumNonZeroRange) { + this.packedValueRanges = packedValueRanges; this.pointTree = pointTree; this.maxNumNonZeroRange = maxNumNonZeroRange; - this.activeIndex = ranges.firstRangeIndex(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue()); + this.activeIndex = packedValueRanges.firstRangeIndex(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue()); } public int getActiveIndex() { @@ -121,17 +121,17 @@ public void traverse(OptimizationContext.DebugInfo debug) throws IOException { @Override public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) { // try to find the first range that may collect values from this cell - if (!ranges.withinUpperBound(minPackedValue, activeIndex) && iterateRangeEnd(minPackedValue)) { + if (!packedValueRanges.withinUpperBound(minPackedValue, activeIndex) && iterateRangeEnd(minPackedValue)) { throw new CollectionTerminatedException(); } // after the loop, min < upper // cell could be outside [min max] lower - if (!ranges.withinLowerBound(maxPackedValue, activeIndex) && iterateRangeEnd(maxPackedValue)) { + if (!packedValueRanges.withinLowerBound(maxPackedValue, activeIndex) && iterateRangeEnd(maxPackedValue)) { return PointValues.Relation.CELL_OUTSIDE_QUERY; } - if (ranges.withinRange(minPackedValue, activeIndex) && ranges.withinRange(maxPackedValue, activeIndex)) { + if (packedValueRanges.withinRange(minPackedValue, activeIndex) && packedValueRanges.withinRange(maxPackedValue, activeIndex)) { return PointValues.Relation.CELL_INSIDE_QUERY; } return PointValues.Relation.CELL_CROSSES_QUERY; @@ -143,10 +143,10 @@ public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue * @return true when packedValue falls within the activeIndex range */ protected boolean canCollect(byte[] packedValue) { - if (!ranges.withinUpperBound(packedValue, activeIndex) && iterateRangeEnd(packedValue)) { + if (!packedValueRanges.withinUpperBound(packedValue, activeIndex) && iterateRangeEnd(packedValue)) { throw new CollectionTerminatedException(); } - return ranges.withinRange(packedValue, activeIndex); + return packedValueRanges.withinRange(packedValue, activeIndex); } /** @@ -156,8 +156,8 @@ protected boolean canCollect(byte[] packedValue) { protected boolean iterateRangeEnd(byte[] packedValue) { // the new value may not be contiguous to the previous one // so try to find the first next range that cross the new value - while (!ranges.withinUpperBound(packedValue, activeIndex)) { - if (++activeIndex >= ranges.size) { + while (!packedValueRanges.withinUpperBound(packedValue, activeIndex)) { + if (++activeIndex >= packedValueRanges.size) { return true; } } @@ -176,11 +176,11 @@ public static class DocCountRangeAwareIntersectVisitor extends RangeAwareInterse public DocCountRangeAwareIntersectVisitor( PointValues.PointTree pointTree, - Ranges ranges, + PackedValueRanges packedValueRanges, int maxNumNonZeroRange, BiConsumer countDocs ) { - super(pointTree, ranges, maxNumNonZeroRange); + super(pointTree, packedValueRanges, maxNumNonZeroRange); this.countDocs = countDocs; } @@ -223,11 +223,11 @@ public static class DocCollectRangeAwareIntersectVisitor extends RangeAwareInter public DocCollectRangeAwareIntersectVisitor( PointValues.PointTree pointTree, - Ranges ranges, + PackedValueRanges packedValueRanges, int maxNumNonZeroRange, BiConsumer collectDocs ) { - super(pointTree, ranges, maxNumNonZeroRange); + super(pointTree, packedValueRanges, maxNumNonZeroRange); this.collectDocs = collectDocs; }