Skip to content

Commit d7248cd

Browse files
committed
Flip others
1 parent 5dc546f commit d7248cd

File tree

7 files changed

+85
-30
lines changed

7 files changed

+85
-30
lines changed

x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/DoubleBucketedSort.java

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/FloatBucketedSort.java

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/IntBucketedSort.java

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/sort/LongBucketedSort.java

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/BytesRefBucketedSort.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
/**
3232
* Aggregates the top N variable length {@link BytesRef} values per bucket.
3333
* See {@link BucketedSort} for more information.
34+
* <p>
35+
* This is substantially different from {@link IpBucketedSort} because
36+
* this has to handle variable length byte strings. To do that it allocates
37+
* a heap of {@link BreakingBytesRefBuilder}s.
38+
* </p>
3439
*/
3540
public class BytesRefBucketedSort implements Releasable {
3641
private final BucketedSortCommon common;

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/IpBucketedSort.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
/**
2727
* Aggregates the top N IP values per bucket.
2828
* See {@link BucketedSort} for more information.
29+
* <p>
30+
* This is substantially different from {@link BytesRefBucketedSort} because
31+
* this takes advantage of IPs having a fixed length and allocates a dense
32+
* storage for them.
33+
* </p>
2934
*/
3035
public class IpBucketedSort implements Releasable {
3136
private static final int IP_LENGTH = 16; // Bytes. It's ipv6.

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/X-BucketedSort.java.st

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package org.elasticsearch.compute.data.sort;
1010
import org.elasticsearch.common.util.BigArrays;
1111
import org.elasticsearch.common.util.BitArray;
1212
import org.elasticsearch.common.util.$Type$Array;
13+
import org.elasticsearch.common.util.PageCacheRecycler;
1314
import org.elasticsearch.compute.data.Block;
1415
import org.elasticsearch.compute.data.BlockFactory;
1516
import org.elasticsearch.compute.data.IntVector;
@@ -101,7 +102,7 @@ public class $Type$BucketedSort implements Releasable {
101102
// Gathering mode
102103
long requiredSize = rootIndex + bucketSize;
103104
if (values.size() < requiredSize) {
104-
grow(requiredSize);
105+
grow(bucket);
105106
}
106107
int next = getNextGatherOffset(rootIndex);
107108
assert 0 <= next && next < bucketSize
@@ -261,19 +262,27 @@ $endif$
261262

262263
/**
263264
* Allocate storage for more buckets and store the "next gather offset"
264-
* for those new buckets.
265+
* for those new buckets. We always grow the storage by whole bucket's
266+
* worth of slots at a time. We never allocate space for partial buckets.
265267
*/
266-
private void grow(long minSize) {
268+
private void grow(int bucket) {
267269
long oldMax = values.size();
268-
values = bigArrays.grow(values, minSize);
270+
assert oldMax % bucketSize == 0;
271+
272+
long newSizeInBuckets = BigArrays.overSize(
273+
bucket + 1,
274+
PageCacheRecycler.$TYPE$_PAGE_SIZE,
275+
$BYTES$ * bucketSize
276+
);
277+
values = bigArrays.resize(values, newSizeInBuckets * bucketSize);
269278
// Set the next gather offsets for all newly allocated buckets.
270-
setNextGatherOffsets(oldMax - (oldMax % getBucketSize()));
279+
fillGatherOffsets(oldMax);
271280
}
272281

273282
/**
274283
* Maintain the "next gather offsets" for newly allocated buckets.
275284
*/
276-
private void setNextGatherOffsets(long startingAt) {
285+
private void fillGatherOffsets(long startingAt) {
277286
int nextOffset = getBucketSize() - 1;
278287
for (long bucketRoot = startingAt; bucketRoot < values.size(); bucketRoot += getBucketSize()) {
279288
setNextGatherOffset(bucketRoot, nextOffset);

0 commit comments

Comments
 (0)