Skip to content

Commit f2da509

Browse files
committed
spotless and comment fixes
1 parent c4f00b3 commit f2da509

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExponentialHistogramState.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

server/src/test/java/org/elasticsearch/search/aggregations/metrics/ExponentialHistogramStateTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
import java.util.stream.IntStream;
2929

3030
import static org.elasticsearch.exponentialhistogram.ExponentialHistogram.MAX_SCALE;
31-
import static org.hamcrest.Matchers.containsString;
3231
import static org.hamcrest.Matchers.equalTo;
33-
import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
3432

3533
public class ExponentialHistogramStateTests extends ESTestCase {
3634

@@ -67,7 +65,13 @@ public void testFailedDeserializationDoesNotLeak() throws IOException {
6765
ExponentialHistogram histogram = ExponentialHistogram.create(
6866
4,
6967
ExponentialHistogramCircuitBreaker.noop(),
70-
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0
68+
1.0,
69+
2.0,
70+
3.0,
71+
4.0,
72+
5.0,
73+
6.0,
74+
7.0
7175
);
7276

7377
ExponentialHistogramState state = ExponentialHistogramState.create(breaker());
@@ -79,10 +83,7 @@ public void testFailedDeserializationDoesNotLeak() throws IOException {
7983
BytesReference bytes = out.bytes();
8084
BytesReference invalidBytes = bytes.slice(0, bytes.length() - 1);
8185

82-
expectThrows(
83-
EOFException.class,
84-
() -> ExponentialHistogramState.read(breaker(), invalidBytes.streamInput())
85-
);
86+
expectThrows(EOFException.class, () -> ExponentialHistogramState.read(breaker(), invalidBytes.streamInput()));
8687
}
8788

8889
public void testAdd() throws IOException {

0 commit comments

Comments
 (0)