Skip to content

Commit 88c6733

Browse files
committed
fix edge case
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
1 parent f7b31b0 commit 88c6733

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/InternalDateHistogram.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,15 @@ void addEmptyBuckets(List<Bucket> list, ReduceContext reduceContext) {
433433
// need to add emptyBucketCount
434434
final int estimateEmptyBucketCount = estimateTotalBucketCount(list) - originalSize;
435435
assert estimateEmptyBucketCount >= 0;
436+
437+
// First check bucket count limit before attempting memory allocation
438+
reduceContext.consumeBucketsAndMaybeBreak(estimateEmptyBucketCount);
439+
436440
CircuitBreaker breaker = reduceContext.getBreaker();
437441
if (breaker != null) {
438442
// 50 bytes memory usage for each empty bucket
439443
breaker.addEstimateBytesAndMaybeBreak(50L * estimateEmptyBucketCount, "empty date histogram buckets");
440444
}
441-
reduceContext.consumeBucketsAndMaybeBreak(estimateEmptyBucketCount);
442445

443446
ListIterator<Bucket> iter = list.listIterator();
444447

server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/InternalHistogram.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,15 @@ void addEmptyBuckets(List<Bucket> list, ReduceContext reduceContext) {
418418
// need to add emptyBucketCount
419419
final int estimateEmptyBucketCount = estimateTotalBucketCount(list) - originalSize;
420420
assert estimateEmptyBucketCount >= 0;
421+
422+
// First check bucket count limit before attempting memory allocation
423+
reduceContext.consumeBucketsAndMaybeBreak(estimateEmptyBucketCount);
424+
421425
CircuitBreaker breaker = reduceContext.getBreaker();
422426
if (breaker != null) {
423427
// 50 bytes memory usage for each empty bucket
424428
breaker.addEstimateBytesAndMaybeBreak(50L * estimateEmptyBucketCount, "empty histogram buckets");
425429
}
426-
reduceContext.consumeBucketsAndMaybeBreak(estimateEmptyBucketCount);
427430

428431
ListIterator<Bucket> iter = list.listIterator();
429432

0 commit comments

Comments
 (0)