Range/BKDTree: add missing closing, when handling exc; add further asserts

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1696010 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2015-08-14 23:30:52 +00:00
parent 6924d616e5
commit 37a4a90705
6 changed files with 17 additions and 2 deletions

View File

@ -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 {

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}