class IndexWriter.ReaderPool {
/**
* Release the segment reader (i.e. decRef it and close if there
* are no more references.
* @param sr
* @throws IOException
*/
public synchronized void release(SegmentReader sr, boolean drop) throws IOException {
final boolean pooled = readerMap.containsKey(sr.getSegmentInfo());
assert !pooled | readerMap.get(sr.getSegmentInfo()) == sr;
// Drop caller's ref
sr.decRef();
if (pooled && (drop || (!poolReaders && sr.getRefCount() == 1))) {
// We are the last ref to this reader; since we're
// not pooling readers, we release it:
readerMap.remove(sr.getSegmentInfo());
// TODO: java 5
// assert !sr.hasChanges || Thread.holdsLock(IndexWriter.this);
// Drop our ref -- this will commit any pending
// changes to the dir
boolean success = false;
try {
sr.close();
success = true;
} finally {
if (!success && sr.hasChanges) {
// Abandon the changes & retry closing:
sr.hasChanges = false;
try {
sr.close();
} catch (Throwable ignore) {
// Keep throwing original exception
}
}
}
}
}
}