Skip to content

Commit d5f202f

Browse files
Adjust size of BigArrays in circuit breaker test
With this commit we restore the previous behavior in `BigArraysTests#testMaxSizeExceededOnResize` but lower the sizes that are tested to the range between 256 bytes to 16 kB so the test does not produce a whole lot of garbage. The previous attempt to reduce the amount of garbage produced by that test was to properly size the array initially but it failed to account for object alignment which lead to test failures in some cases. While it would be possible to account for object alignment, we would need to open up BigArrays or directly use the underlying Lucene API which would require us to allocate an array upfront only to find its size (incl. object alignment). Instead we have fixed this issue by conservatively sizing the array initially (so the initial allocation will never trip the circuit breaker) and reduce garbage by reducing the circuit breaker's upper bound as described previously. Closes #33750 Relates #34325
1 parent 1c775ae commit d5f202f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

server/src/test/java/org/elasticsearch/common/util/BigArraysTests.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,20 +351,26 @@ public void testMaxSizeExceededOnNew() throws Exception {
351351

352352
public void testMaxSizeExceededOnResize() throws Exception {
353353
for (String type : Arrays.asList("Byte", "Int", "Long", "Float", "Double", "Object")) {
354-
final int maxSize = randomIntBetween(1 << 10, 1 << 22);
354+
final int maxSize = randomIntBetween(1 << 8, 1 << 14);
355355
HierarchyCircuitBreakerService hcbs = new HierarchyCircuitBreakerService(
356356
Settings.builder()
357357
.put(REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), maxSize, ByteSizeUnit.BYTES)
358358
.build(),
359359
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
360360
BigArrays bigArrays = new BigArrays(null, hcbs, false).withCircuitBreaking();
361361
Method create = BigArrays.class.getMethod("new" + type + "Array", long.class);
362-
final int size = scaledRandomIntBetween(10, maxSize / 8);
362+
final int size = scaledRandomIntBetween(10, maxSize / 16);
363363
BigArray array = (BigArray) create.invoke(bigArrays, size);
364364
Method resize = BigArrays.class.getMethod("resize", array.getClass().getInterfaces()[0], long.class);
365-
final long newSize = maxSize + 1;
366-
InvocationTargetException e = expectThrows(InvocationTargetException.class, () -> resize.invoke(bigArrays, array, newSize));
367-
assertTrue(e.getCause() instanceof CircuitBreakingException);
365+
while (true) {
366+
long newSize = array.size() * 2;
367+
try {
368+
array = (BigArray) resize.invoke(bigArrays, array, newSize);
369+
} catch (InvocationTargetException e) {
370+
assertTrue(e.getCause() instanceof CircuitBreakingException);
371+
break;
372+
}
373+
}
368374
assertEquals(array.ramBytesUsed(), hcbs.getBreaker(CircuitBreaker.REQUEST).getUsed());
369375
array.close();
370376
assertEquals(0, hcbs.getBreaker(CircuitBreaker.REQUEST).getUsed());

0 commit comments

Comments
 (0)