LUCENE-845: fixed a case that was allowing same segment name to be used twice when a concurrent merge was aborted in between

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@576934 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2007-09-18 14:44:04 +00:00
parent ddb17c6397
commit 963635448e
2 changed files with 8 additions and 0 deletions

View File

@ -1472,6 +1472,12 @@ public class IndexWriter {
// Cannot synchronize on IndexWriter because that causes // Cannot synchronize on IndexWriter because that causes
// deadlock // deadlock
synchronized(segmentInfos) { synchronized(segmentInfos) {
// Important to set commitPending so that the
// segmentInfos is written on close. Otherwise we
// could close, re-open and re-return the same segment
// name that was previously returned which can cause
// problems at least with ConcurrentMergeScheduler.
commitPending = true;
return "_" + Integer.toString(segmentInfos.counter++, Character.MAX_RADIX); return "_" + Integer.toString(segmentInfos.counter++, Character.MAX_RADIX);
} }
} }
@ -1906,6 +1912,7 @@ public class IndexWriter {
private synchronized void checkpoint() throws IOException { private synchronized void checkpoint() throws IOException {
if (autoCommit) { if (autoCommit) {
segmentInfos.write(directory); segmentInfos.write(directory);
commitPending = false;
if (infoStream != null) if (infoStream != null)
message("checkpoint: wrote segments file \"" + segmentInfos.getCurrentSegmentFileName() + "\""); message("checkpoint: wrote segments file \"" + segmentInfos.getCurrentSegmentFileName() + "\"");
} else { } else {

View File

@ -698,6 +698,7 @@ public class TestIndexWriterDelete extends TestCase {
} }
public void eval(MockRAMDirectory dir) throws IOException { public void eval(MockRAMDirectory dir) throws IOException {
if (!failed) { if (!failed) {
failed = true;
throw new IOException("fail in add doc"); throw new IOException("fail in add doc");
} }
} }