Skip to content

Commit e3e8dc3

Browse files
committed
Flip impl
1 parent e332b82 commit e3e8dc3

File tree

7 files changed

+38
-23
lines changed

7 files changed

+38
-23
lines changed

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

Lines changed: 4 additions & 2 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: 4 additions & 2 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: 4 additions & 2 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: 4 additions & 2 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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,14 @@ private void grow(int bucket) {
285285
long oldMax = values.size();
286286
assert oldMax % common.bucketSize == 0;
287287

288-
long newSizeInBuckets = BigArrays.overSize(
289-
bucket + 1,
288+
long newSize = BigArrays.overSize(
289+
((long) bucket + 1) * common.bucketSize,
290290
PageCacheRecycler.OBJECT_PAGE_SIZE,
291-
RamUsageEstimator.NUM_BYTES_OBJECT_REF * common.bucketSize
291+
RamUsageEstimator.NUM_BYTES_OBJECT_REF
292292
);
293-
values = common.bigArrays.resize(values, newSizeInBuckets * common.bucketSize);
293+
// Round up to the next full bucket.
294+
newSize = (newSize + common.bucketSize - 1) / common.bucketSize;
295+
values = common.bigArrays.resize(values, newSize * common.bucketSize);
294296
// Set the next gather offsets for all newly allocated buckets.
295297
fillGatherOffsets(oldMax);
296298
}

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.common.util.BigArrays;
1212
import org.elasticsearch.common.util.ByteArray;
1313
import org.elasticsearch.common.util.ByteUtils;
14+
import org.elasticsearch.common.util.PageCacheRecycler;
1415
import org.elasticsearch.compute.data.Block;
1516
import org.elasticsearch.compute.data.BlockFactory;
1617
import org.elasticsearch.compute.data.IntVector;
@@ -106,7 +107,7 @@ public void collect(BytesRef value, int bucket) {
106107
// Gathering mode
107108
long requiredSize = common.endIndex(rootIndex) * IP_LENGTH;
108109
if (values.size() < requiredSize) {
109-
grow(requiredSize);
110+
grow(bucket);
110111
}
111112
int next = getNextGatherOffset(rootIndex);
112113
common.assertValidNextOffset(next);
@@ -273,17 +274,23 @@ private void swap(long lhs, long rhs) {
273274
* Allocate storage for more buckets and store the "next gather offset"
274275
* for those new buckets.
275276
*/
276-
private void grow(long minSize) {
277+
private void grow(int bucket) {
277278
long oldMax = values.size() / IP_LENGTH;
278-
values = common.bigArrays.grow(values, minSize);
279+
assert oldMax % common.bucketSize == 0;
280+
281+
int bucketBytes = common.bucketSize * IP_LENGTH;
282+
long newSize = BigArrays.overSize(((long) bucket + 1) * bucketBytes, PageCacheRecycler.BYTE_PAGE_SIZE, 1);
283+
// Round up to the next full bucket.
284+
newSize = (newSize + bucketBytes - 1) / bucketBytes;
285+
values = common.bigArrays.resize(values, newSize * bucketBytes);
279286
// Set the next gather offsets for all newly allocated buckets.
280-
setNextGatherOffsets(oldMax - (oldMax % common.bucketSize));
287+
fillGatherOffsets(oldMax);
281288
}
282289

283290
/**
284291
* Maintain the "next gather offsets" for newly allocated buckets.
285292
*/
286-
private void setNextGatherOffsets(long startingAt) {
293+
private void fillGatherOffsets(long startingAt) {
287294
int nextOffset = common.bucketSize - 1;
288295
for (long bucketRoot = startingAt; bucketRoot < values.size() / IP_LENGTH; bucketRoot += common.bucketSize) {
289296
setNextGatherOffset(bucketRoot, nextOffset);

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,10 @@ $endif$
269269
long oldMax = values.size();
270270
assert oldMax % bucketSize == 0;
271271

272-
long newSizeInBuckets = BigArrays.overSize(
273-
bucket + 1,
274-
PageCacheRecycler.$TYPE$_PAGE_SIZE,
275-
$BYTES$ * bucketSize
276-
);
277-
values = bigArrays.resize(values, newSizeInBuckets * bucketSize);
272+
long newSize = BigArrays.overSize(((long) bucket + 1) * bucketSize, PageCacheRecycler.$TYPE$_PAGE_SIZE, $BYTES$);
273+
// Round up to the next full bucket.
274+
newSize = (newSize + bucketSize - 1) / bucketSize;
275+
values = bigArrays.resize(values, newSize * bucketSize);
278276
// Set the next gather offsets for all newly allocated buckets.
279277
fillGatherOffsets(oldMax);
280278
}

0 commit comments

Comments
 (0)