From dc3d6fc9c18308a3a7f097c19c1af3f9b68c0561 Mon Sep 17 00:00:00 2001 From: expani Date: Sat, 19 Oct 2024 09:53:15 +0530 Subject: [PATCH] Closing IndexInput after every use --- .../benchmark/jmh/DocIdEncodingBenchmark.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/DocIdEncodingBenchmark.java b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/DocIdEncodingBenchmark.java index aacd654ae88..83b1c194044 100644 --- a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/DocIdEncodingBenchmark.java +++ b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/DocIdEncodingBenchmark.java @@ -81,8 +81,6 @@ public class DocIdEncodingBenchmark { private Path tmpDir; - private IndexInput in; - private final int[] scratch = new int[512]; private String decoderInputFile; @@ -126,8 +124,8 @@ public class DocIdEncodingBenchmark { Files.delete(tmpDir.resolve(outputFile)); } } else if (methodName.equalsIgnoreCase("decode")) { - try (Directory dir = FSDirectory.open(tmpDir)) { - in = dir.openInput(decoderInputFile, IOContext.DEFAULT); + try (Directory dir = FSDirectory.open(tmpDir); + IndexInput in = dir.openInput(decoderInputFile, IOContext.DEFAULT)) { for (int[] docIdSequence : DOC_ID_SEQUENCES) { for (int i = 1; i <= INPUT_SCALE_FACTOR; i++) { docIdEncoder.decode(in, 0, docIdSequence.length, scratch); @@ -309,7 +307,7 @@ public class DocIdEncodingBenchmark { out.writeLong(packedLong); } for (; i < count; i++) { - //out.writeInt(docIds[i]); + // out.writeInt(docIds[i]); out.writeLong(docIds[i]); } } @@ -324,7 +322,7 @@ public class DocIdEncodingBenchmark { docIDs[i + 2] = (int) (packedLong & BPV_21_MASK); } for (; i < count; i++) { - //docIDs[i] = in.readInt(); + // docIDs[i] = in.readInt(); docIDs[i] = (int) in.readLong(); } } @@ -365,7 +363,7 @@ public class DocIdEncodingBenchmark { out.writeLong(packedLong); } for (; i < count; i++) { - //out.writeInt(docIds[i]); + // out.writeInt(docIds[i]); out.writeLong(docIds[i]); } } @@ -394,7 +392,7 @@ public class DocIdEncodingBenchmark { docIDs[i + 2] = (int) (packedLong & BPV_21_MASK); } for (; i < count; i++) { - //docIDs[i] = in.readInt(); + // docIDs[i] = in.readInt(); docIDs[i] = (int) in.readLong(); } } @@ -543,6 +541,5 @@ public class DocIdEncodingBenchmark { } catch (IOException e) { throw new RuntimeException(e); } - } }