@@ -60,8 +60,16 @@ public static ExponentialHistogramState create(CircuitBreaker circuitBreaker) {
6060
6161 // Visible for testing
6262 static ExponentialHistogramState create (CircuitBreaker circuitBreaker , ReleasableExponentialHistogram deserializedHistogram ) {
63- circuitBreaker .addEstimateBytesAndMaybeBreak (SHALLOW_SIZE , "exponential-histogram-state" );
64- return new ExponentialHistogramState (circuitBreaker , deserializedHistogram );
63+ boolean success = false ;
64+ try {
65+ circuitBreaker .addEstimateBytesAndMaybeBreak (SHALLOW_SIZE , "exponential-histogram-state" );
66+ success = true ;
67+ return new ExponentialHistogramState (circuitBreaker , deserializedHistogram );
68+ } finally {
69+ if (success == false ) {
70+ Releasables .close (deserializedHistogram );
71+ }
72+ }
6573 }
6674
6775 private ExponentialHistogramState (CircuitBreaker circuitBreaker , ReleasableExponentialHistogram deserializedHistogram ) {
@@ -140,11 +148,11 @@ private static void writeZeroBucket(StreamOutput out, ZeroBucket zb) throws IOEx
140148 }
141149
142150 private static void writeBuckets (StreamOutput out , ExponentialHistogram .Buckets buckets ) throws IOException {
143- // We write the buckets with delta-encoding of the indexes , where a delta of 1 is implicit.
151+ // We write the buckets with delta-encoding of the indices , where a delta of 1 is implicit.
144152 // This allows for a good and yet fast compression using vlongs.
145- // We write the indices as negative values (except for the first index) to distinguish them from the counts
153+ // We write the index deltas as negative values (except for the first index) to distinguish them from the counts
146154 // So for example, the following buckets:
147- // Index: 3 4 5 7 8
155+ // Index: _3 | _4 | _5 | _7 | _8
148156 // Count: 10 | 20 | 30 | 40 | 50
149157 // Would be written as:
150158 // 3, 10, 20, 30, -2, 40, 50
0 commit comments