Skip to content

Commit 0dc14fa

Browse files
committed
fix tests
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
1 parent 88c6733 commit 0dc14fa

File tree

4 files changed

+22
-39
lines changed

4 files changed

+22
-39
lines changed

rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/10_histogram.yml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -716,25 +716,6 @@ setup:
716716
- '{"index": {}}'
717717
- '{"number": 500000}'
718718

719-
- do:
720-
catch: /circuit_breaking_exception/
721-
search:
722-
index: test_cb
723-
body:
724-
size: 0
725-
aggs:
726-
histo:
727-
histogram:
728-
field: number
729-
interval: 10
730-
extended_bounds:
731-
min: 0
732-
max: 174155895372
733-
734-
- match: { error.type: "search_phase_execution_exception" }
735-
- match: { error.caused_by.type: "circuit_breaking_exception"}
736-
- match: { status: 429 }
737-
738719
- do:
739720
catch: /too_many_buckets_exception/
740721
search:
@@ -745,7 +726,7 @@ setup:
745726
histo:
746727
histogram:
747728
field: number
748-
interval: 100000
729+
interval: 10
749730
extended_bounds:
750731
min: 0
751732
max: 174155895372

rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/360_date_histogram.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ setup:
195195
- '{"date": "2016-03-01"}'
196196

197197
- do:
198-
catch: /circuit_breaking_exception/
198+
catch: /too_many_buckets_exception/
199199
search:
200200
index: test_cb
201201
body:
@@ -210,5 +210,5 @@ setup:
210210
max: 174155895372
211211

212212
- match: { error.type: "search_phase_execution_exception" }
213-
- match: { error.caused_by.type: "circuit_breaking_exception"}
214-
- match: { status: 429 }
213+
- match: { error.caused_by.type: "too_many_buckets_exception"}
214+
- match: { status: 503 }

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ protected Bucket reduceBucket(List<Bucket> buckets, ReduceContext context) {
401401
private int estimateTotalBucketCount(List<Bucket> list) {
402402
LongBounds bounds = emptyBucketInfo.bounds;
403403
int bucketCount = 0;
404-
if (bounds != null && bounds.getMin() != null && bounds.getMax() != null) {
404+
if (bounds != null && bounds.getMin() != null && bounds.getMax() != null && !list.isEmpty()) {
405405
long min = min(bounds.getMin() + offset, list.getFirst().key);
406406
long max = max(bounds.getMax() + offset, list.getLast().key);
407407
long intervalWidth = 0;
@@ -431,16 +431,17 @@ void addEmptyBuckets(List<Bucket> list, ReduceContext reduceContext) {
431431
final int originalSize = list.size();
432432
// we use counts here only to add those values to the CircuitBreaker, list's count has already been added in #reduce, so we only
433433
// need to add emptyBucketCount
434-
final int estimateEmptyBucketCount = estimateTotalBucketCount(list) - originalSize;
435-
assert estimateEmptyBucketCount >= 0;
434+
final int estimateEmptyBucketCount = Math.max(0, estimateTotalBucketCount(list) - originalSize);
436435

437436
// First check bucket count limit before attempting memory allocation
438-
reduceContext.consumeBucketsAndMaybeBreak(estimateEmptyBucketCount);
437+
if (estimateEmptyBucketCount > 0) {
438+
reduceContext.consumeBucketsAndMaybeBreak(estimateEmptyBucketCount);
439439

440-
CircuitBreaker breaker = reduceContext.getBreaker();
441-
if (breaker != null) {
442-
// 50 bytes memory usage for each empty bucket
443-
breaker.addEstimateBytesAndMaybeBreak(50L * estimateEmptyBucketCount, "empty date histogram buckets");
440+
CircuitBreaker breaker = reduceContext.getBreaker();
441+
if (breaker != null) {
442+
// 50 bytes memory usage for each empty bucket
443+
breaker.addEstimateBytesAndMaybeBreak(50L * estimateEmptyBucketCount, "empty date histogram buckets");
444+
}
444445
}
445446

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

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ private double round(double key) {
388388

389389
private int estimateTotalBucketCount(List<Bucket> list) {
390390
int bucketCount = 0;
391-
if (emptyBucketInfo != null) {
391+
if (emptyBucketInfo != null && !list.isEmpty()) {
392392
double min = min(emptyBucketInfo.minBound, list.getFirst().key);
393393
double max = max(emptyBucketInfo.maxBound, list.getLast().key);
394394

@@ -416,16 +416,17 @@ void addEmptyBuckets(List<Bucket> list, ReduceContext reduceContext) {
416416
final int originalSize = list.size();
417417
// we use counts here only to add those values to the CircuitBreaker, list's count has already been added in #reduce, so we only
418418
// need to add emptyBucketCount
419-
final int estimateEmptyBucketCount = estimateTotalBucketCount(list) - originalSize;
420-
assert estimateEmptyBucketCount >= 0;
419+
final int estimateEmptyBucketCount = Math.max(0, estimateTotalBucketCount(list) - originalSize);
421420

422421
// First check bucket count limit before attempting memory allocation
423-
reduceContext.consumeBucketsAndMaybeBreak(estimateEmptyBucketCount);
422+
if (estimateEmptyBucketCount > 0) {
423+
reduceContext.consumeBucketsAndMaybeBreak(estimateEmptyBucketCount);
424424

425-
CircuitBreaker breaker = reduceContext.getBreaker();
426-
if (breaker != null) {
427-
// 50 bytes memory usage for each empty bucket
428-
breaker.addEstimateBytesAndMaybeBreak(50L * estimateEmptyBucketCount, "empty histogram buckets");
425+
CircuitBreaker breaker = reduceContext.getBreaker();
426+
if (breaker != null) {
427+
// 50 bytes memory usage for each empty bucket
428+
breaker.addEstimateBytesAndMaybeBreak(50L * estimateEmptyBucketCount, "empty histogram buckets");
429+
}
429430
}
430431

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

0 commit comments

Comments
 (0)