Skip to content

Commit e332619

Browse files
committed
Self close BlockMetadataAcc if throw during construction
1 parent b1d4b17 commit e332619

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

server/src/main/java/org/elasticsearch/index/codec/tsdb/es819/BlockMetadataAccumulator.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ public final class BlockMetadataAccumulator implements Closeable {
2626
private final DelayedOffsetAccumulator blockDocRangeAcc;
2727

2828
BlockMetadataAccumulator(Directory dir, IOContext context, IndexOutput data, long addressesStart) throws IOException {
29-
blockDocRangeAcc = new DelayedOffsetAccumulator(dir, context, data, "block-doc-ranges", 0);
30-
blockAddressAcc = new DelayedOffsetAccumulator(dir, context, data, "block-addresses", addressesStart);
29+
boolean success = false;
30+
try {
31+
blockDocRangeAcc = new DelayedOffsetAccumulator(dir, context, data, "block-doc-ranges", 0);
32+
blockAddressAcc = new DelayedOffsetAccumulator(dir, context, data, "block-addresses", addressesStart);
33+
success = true;
34+
} finally {
35+
if (success == false) {
36+
IOUtils.closeWhileHandlingException(this); // self-close because constructor caller can't
37+
}
38+
}
3139
}
3240

3341
public void addDoc(long numDocsInBlock, long blockLenInBytes) throws IOException {

0 commit comments

Comments
 (0)