mirror of https://github.com/apache/lucene.git
LUCENE-4245: use IOUtils to close everything in finally block
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1364931 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
845a3c3d60
commit
2b53e08898
|
@ -893,45 +893,46 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
// clean up merge scheduler in all cases, although flushing may have failed:
|
try {
|
||||||
interrupted = Thread.interrupted();
|
// clean up merge scheduler in all cases, although flushing may have failed:
|
||||||
|
interrupted = Thread.interrupted();
|
||||||
|
|
||||||
if (waitForMerges) {
|
if (waitForMerges) {
|
||||||
try {
|
|
||||||
// Give merge scheduler last chance to run, in case
|
|
||||||
// any pending merges are waiting:
|
|
||||||
mergeScheduler.merge(this);
|
|
||||||
} catch (ThreadInterruptedException tie) {
|
|
||||||
// ignore any interruption, does not matter
|
|
||||||
interrupted = true;
|
|
||||||
if (infoStream.isEnabled("IW")) {
|
|
||||||
infoStream.message("IW", "interrupted while waiting for final merges");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mergePolicy.close();
|
|
||||||
|
|
||||||
synchronized(this) {
|
|
||||||
for (;;) {
|
|
||||||
try {
|
try {
|
||||||
finishMerges(waitForMerges && !interrupted);
|
// Give merge scheduler last chance to run, in case
|
||||||
break;
|
// any pending merges are waiting:
|
||||||
|
mergeScheduler.merge(this);
|
||||||
} catch (ThreadInterruptedException tie) {
|
} catch (ThreadInterruptedException tie) {
|
||||||
// by setting the interrupted status, the
|
// ignore any interruption, does not matter
|
||||||
// next call to finishMerges will pass false,
|
|
||||||
// so it will not wait
|
|
||||||
interrupted = true;
|
interrupted = true;
|
||||||
if (infoStream.isEnabled("IW")) {
|
if (infoStream.isEnabled("IW")) {
|
||||||
infoStream.message("IW", "interrupted while waiting for merges to finish");
|
infoStream.message("IW", "interrupted while waiting for final merges");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stopMerges = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// shutdown scheduler and all threads (this call is not interruptible):
|
synchronized(this) {
|
||||||
mergeScheduler.close();
|
for (;;) {
|
||||||
|
try {
|
||||||
|
finishMerges(waitForMerges && !interrupted);
|
||||||
|
break;
|
||||||
|
} catch (ThreadInterruptedException tie) {
|
||||||
|
// by setting the interrupted status, the
|
||||||
|
// next call to finishMerges will pass false,
|
||||||
|
// so it will not wait
|
||||||
|
interrupted = true;
|
||||||
|
if (infoStream.isEnabled("IW")) {
|
||||||
|
infoStream.message("IW", "interrupted while waiting for merges to finish");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stopMerges = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
// shutdown policy, scheduler and all threads (this call is not interruptible):
|
||||||
|
IOUtils.closeWhileHandlingException(mergePolicy, mergeScheduler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (infoStream.isEnabled("IW")) {
|
if (infoStream.isEnabled("IW")) {
|
||||||
|
|
Loading…
Reference in New Issue