Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,6 @@ tests:
- class: org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT
method: testEndpointGetsUpdated_GivenFingerprintChanges_FromNull
issue: https://github.com/elastic/elasticsearch/issues/143845
- class: org.elasticsearch.compute.aggregation.HistogramMergeTDigestAggregatorFunctionTests
method: testSimpleWithCranky
issue: https://github.com/elastic/elasticsearch/issues/143860
- class: org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT
method: testCreatesEisChatCompletionEndpoint
issue: https://github.com/elastic/elasticsearch/issues/140849
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,17 @@ private static class BreakingBytesStreamOutput extends StreamOutput implements R

BreakingBytesStreamOutput(CircuitBreaker breaker) {
this.breaker = breaker;
this.delegate = new BreakingBytesRefBuilder(breaker, CIRCUIT_BREAKER_LABEL);
breaker.addEstimateBytesAndMaybeBreak(SHALLOW_SIZE, CIRCUIT_BREAKER_LABEL);
BreakingBytesRefBuilder delegate = new BreakingBytesRefBuilder(breaker, CIRCUIT_BREAKER_LABEL);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called after adding the estimated bytes to the breaker, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BreakingBytesRefBuilder performs the memory accounting for itself in the constructor.
The addEstimateBytesAndMaybeBreak is just for the shallow object size of BreakingBytesStreamOutput.
Technically, BreakingBytesStreamOutput has already been allocated here because we are in the constructor and we adjust the breaker afterwards. However, the object is so small that this overshoot doesn't really matter, BreakingBytesRefBuilder does the same.

You shouldn't do this if e.g. you are allocating large arrays: In that case you should make sure to adjust the breaker before you allocate. For objects this usually means adding a factory method which does the accounting and only calling the constructor at the end of it. However, for such small objects this is not worth the additional lines of code.

boolean success = false;
try {
breaker.addEstimateBytesAndMaybeBreak(SHALLOW_SIZE, CIRCUIT_BREAKER_LABEL);
success = true;
} finally {
if (success == false) {
Releasables.close(delegate);
}
}
this.delegate = delegate;
}

void clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void testCrankyCircuitBreaker() {
}
}
});
assertThat(breaker.getUsed(), equalTo(0L));
}

private TDigestHolder randomStandaloneTDigestHolder() {
Expand Down
Loading