diff --git a/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeWriter.java b/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeWriter.java index f0ad40e3025..888fee6d83f 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeWriter.java +++ b/lucene/sandbox/src/java/org/apache/lucene/bkdtree/BKDTreeWriter.java @@ -220,7 +220,7 @@ class BKDTreeWriter { if (success) { IOUtils.close(sortedWriter, reader); } else { - IOUtils.closeWhileHandlingException(reader); + IOUtils.closeWhileHandlingException(sortedWriter, reader); try { sortedWriter.destroy(); } catch (Throwable t) { @@ -287,6 +287,7 @@ class BKDTreeWriter { heapWriter.ords[i], heapWriter.docIDs[i]); } + sorted.close(); return sorted; } else { diff --git a/lucene/sandbox/src/java/org/apache/lucene/bkdtree/HeapLatLonWriter.java b/lucene/sandbox/src/java/org/apache/lucene/bkdtree/HeapLatLonWriter.java index 0bf68a24ce7..cb32d3caa4c 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/bkdtree/HeapLatLonWriter.java +++ b/lucene/sandbox/src/java/org/apache/lucene/bkdtree/HeapLatLonWriter.java @@ -23,6 +23,7 @@ final class HeapLatLonWriter implements LatLonWriter { final int[] docIDs; final long[] ords; private int nextWrite; + private boolean closed; public HeapLatLonWriter(int count) { latEncs = new int[count]; @@ -42,11 +43,13 @@ final class HeapLatLonWriter implements LatLonWriter { @Override public LatLonReader getReader(long start) { + assert closed; return new HeapLatLonReader(latEncs, lonEncs, ords, docIDs, (int) start, latEncs.length); } @Override public void close() { + closed = true; if (nextWrite != latEncs.length) { throw new IllegalStateException("only wrote " + nextWrite + " values, but expected " + latEncs.length); } diff --git a/lucene/sandbox/src/java/org/apache/lucene/bkdtree/OfflineLatLonWriter.java b/lucene/sandbox/src/java/org/apache/lucene/bkdtree/OfflineLatLonWriter.java index ec22883371d..271d1ff680f 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/bkdtree/OfflineLatLonWriter.java +++ b/lucene/sandbox/src/java/org/apache/lucene/bkdtree/OfflineLatLonWriter.java @@ -34,6 +34,7 @@ final class OfflineLatLonWriter implements LatLonWriter { final OutputStreamDataOutput out; final long count; private long countWritten; + private boolean closed; public OfflineLatLonWriter(Path tempDir, long count) throws IOException { tempFile = Files.createTempFile(tempDir, "size" + count + ".", ""); @@ -52,11 +53,13 @@ final class OfflineLatLonWriter implements LatLonWriter { @Override public LatLonReader getReader(long start) throws IOException { + assert closed; return new OfflineLatLonReader(tempFile, start, count-start); } @Override public void close() throws IOException { + closed = true; out.close(); if (count != countWritten) { throw new IllegalStateException("wrote " + countWritten + " values, but expected " + count); diff --git a/lucene/sandbox/src/java/org/apache/lucene/rangetree/HeapSliceWriter.java b/lucene/sandbox/src/java/org/apache/lucene/rangetree/HeapSliceWriter.java index 1b5ab433f07..fef37f4a8f3 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/rangetree/HeapSliceWriter.java +++ b/lucene/sandbox/src/java/org/apache/lucene/rangetree/HeapSliceWriter.java @@ -22,6 +22,7 @@ final class HeapSliceWriter implements SliceWriter { final int[] docIDs; final long[] ords; private int nextWrite; + private boolean closed; public HeapSliceWriter(int count) { values = new long[count]; @@ -39,11 +40,13 @@ final class HeapSliceWriter implements SliceWriter { @Override public SliceReader getReader(long start) { + assert closed; return new HeapSliceReader(values, ords, docIDs, (int) start, values.length); } @Override public void close() { + closed = true; if (nextWrite != values.length) { throw new IllegalStateException("only wrote " + nextWrite + " values, but expected " + values.length); } diff --git a/lucene/sandbox/src/java/org/apache/lucene/rangetree/OfflineSliceWriter.java b/lucene/sandbox/src/java/org/apache/lucene/rangetree/OfflineSliceWriter.java index 5ca254962a0..bbf0af6f1e5 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/rangetree/OfflineSliceWriter.java +++ b/lucene/sandbox/src/java/org/apache/lucene/rangetree/OfflineSliceWriter.java @@ -33,6 +33,7 @@ final class OfflineSliceWriter implements SliceWriter { final ByteArrayDataOutput scratchBytesOutput = new ByteArrayDataOutput(scratchBytes); final OutputStreamDataOutput out; final long count; + private boolean closed; private long countWritten; public OfflineSliceWriter(Path tempDir, long count) throws IOException { @@ -51,11 +52,13 @@ final class OfflineSliceWriter implements SliceWriter { @Override public SliceReader getReader(long start) throws IOException { + assert closed; return new OfflineSliceReader(tempFile, start, count-start); } @Override public void close() throws IOException { + closed = true; out.close(); if (count != countWritten) { throw new IllegalStateException("wrote " + countWritten + " values, but expected " + count); diff --git a/lucene/sandbox/src/java/org/apache/lucene/rangetree/RangeTreeWriter.java b/lucene/sandbox/src/java/org/apache/lucene/rangetree/RangeTreeWriter.java index bf297a1b956..ee145244ba6 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/rangetree/RangeTreeWriter.java +++ b/lucene/sandbox/src/java/org/apache/lucene/rangetree/RangeTreeWriter.java @@ -188,7 +188,7 @@ class RangeTreeWriter { if (success) { IOUtils.close(sortedWriter, reader); } else { - IOUtils.closeWhileHandlingException(reader); + IOUtils.closeWhileHandlingException(sortedWriter, reader); try { sortedWriter.destroy(); } catch (Throwable t) { @@ -245,6 +245,7 @@ class RangeTreeWriter { heapWriter.ords[i], heapWriter.docIDs[i]); } + sorted.close(); return sorted; } else { @@ -468,6 +469,7 @@ class RangeTreeWriter { assert hasNext; writer.append(reader.value(), reader.ord(), reader.docID()); } + writer.close(); source = new PathSlice(writer, 0, count); }