Fix circuit breaker leak in BreakingTDigestHolder#143873
Fix circuit breaker leak in BreakingTDigestHolder#143873JonasKunz merged 6 commits intoelastic:mainfrom
Conversation
|
Pinging @elastic/es-storage-engine (Team:StorageEngine) |
| 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); |
There was a problem hiding this comment.
This should be called after adding the estimated bytes to the breaker, no?
There was a problem hiding this comment.
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.
…elocations * upstream/main: (54 commits) [ES|QL|DS] Wire parallel parsing into production for text formats (elastic#143997) ESQL: Allow EXTERNAL commands be run part of the CsvTests suite (elastic#143970) [ESQL] Push stats to external source via metadata (elastic#143940) Mute org.elasticsearch.xpack.esql.CsvIT test {csv-spec:approximation.Approximate stats with stats where} elastic#144051 Refactored SortedNumericDocValuesSyntheticFieldLoader into a Layer (elastic#143912) Enable extended doc_values params feature flag in RandomizedRollingUpgradeIT (elastic#143918) Mute org.elasticsearch.xpack.esql.qa.multi_node.EsqlSpecIT test {csv-spec:approximation.Approximate stats with sample} elastic#144022 Ensure we use float values for rolling upgrade float vectors (elastic#144032) Remove sensitive info from reindex task description (elastic#143635) Fix HistogramUnionState.equals (elastic#143990) Use dedicated IndexRouting API in ShardSplittingQuery (elastic#143776) Engine/Store DistributedArchitectureGuide doc (elastic#143818) Mute org.elasticsearch.snapshots.ConcurrentSnapshotsIT testDeletesAreBatched elastic#144034 Avoid serializing exceptions as JSON in remote write endpoint (elastic#143987) allow testLoadDocSequenceReturnsCorrectResultsText to circuit break, it happens in serverless occasionally (elastic#144023) [ESQL] Adds memory accounting to GroupedLimitOperator (elastic#143941) Adjust ESIntegTestCase.getLiveDocs method to account for pruned sequence numbers (elastic#143999) Support target bucket count in `TBUCKET` with explicit from/to date range (elastic#142747) TSDBDocValuesFormatSingleNodeTests with and without synthetic id (elastic#144002) Fix circuit breaker leak in BreakingTDigestHolder (elastic#143873) ...
Fixes #143860.
There indeed was a code path in
BreakingTDigestHolderwhich could cause a circuit breaker memory leak if the breaker trips.This confused me a little, because it should have been caught by
BreakingTDigestHolderTests.testCrankyCircuitBreaker, as I ran that with many iterations before merging the PR that introduced it.As it turns out, I simply forgot to assert the circuit breaker reserved bytes 🤦