Index: src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- src/java/org/apache/lucene/index/IndexWriter.java (revision 746340) +++ src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -3587,20 +3587,6 @@ finishCommit(); } - private boolean committing; - - synchronized private void waitForCommit() { - // Only allow a single thread to do the commit, at a time: - while(committing) - doWait(); - committing = true; - } - - synchronized private void doneCommit() { - committing = false; - notifyAll(); - } - /** *
Commits all pending updates (added & deleted * documents) to the index, and syncs all referenced index @@ -3647,24 +3633,17 @@ ensureOpen(); - // Only let one thread do the prepare/finish at a time - waitForCommit(); + if (infoStream != null) + message("commit: start"); - try { + if (autoCommit || pendingCommit == null) { if (infoStream != null) - message("commit: start"); + message("commit: now prepare"); + prepareCommit(commitUserData, true); + } else if (infoStream != null) + message("commit: already prepared"); - if (autoCommit || pendingCommit == null) { - if (infoStream != null) - message("commit: now prepare"); - prepareCommit(commitUserData, true); - } else if (infoStream != null) - message("commit: already prepared"); - - finishCommit(); - } finally { - doneCommit(); - } + finishCommit(); } private synchronized final void finishCommit() throws CorruptIndexException, IOException { @@ -3722,8 +3701,6 @@ flushCount++; - // Make sure no threads are actively adding a document - flushDeletes |= docWriter.deletesFull(); // When autoCommit=true we must always flush deletes @@ -3732,6 +3709,7 @@ // from an updateDocument call flushDeletes |= autoCommit; + // Make sure no threads are actively adding a document. // Returns true if docWriter is currently aborting, in // which case we skip flushing this segment if (docWriter.pauseAllThreads()) { @@ -4868,45 +4846,50 @@ // since I first started syncing my version, I can // safely skip saving myself since I've been // superseded: - if (myChangeCount > lastCommitChangeCount && (pendingCommit == null || myChangeCount > pendingCommitChangeCount)) { - // Wait now for any current pending commit to complete: - while(pendingCommit != null) { - if (infoStream != null) - message("wait for existing pendingCommit to finish..."); - doWait(); - } + while(true) { + if (myChangeCount <= lastCommitChangeCount) { + if (infoStream != null) { + message("sync superseded by newer infos"); + } + break; + } else if (pendingCommit == null) { + // My turn to commit - if (segmentInfos.getGeneration() > toSync.getGeneration()) - toSync.updateGeneration(segmentInfos); + if (segmentInfos.getGeneration() > toSync.getGeneration()) + toSync.updateGeneration(segmentInfos); - boolean success = false; - try { - - // Exception here means nothing is prepared - // (this method unwinds everything it did on - // an exception) + boolean success = false; try { - toSync.prepareCommit(directory); + + // Exception here means nothing is prepared + // (this method unwinds everything it did on + // an exception) + try { + toSync.prepareCommit(directory); + } finally { + // Have our master segmentInfos record the + // generations we just prepared. We do this + // on error or success so we don't + // double-write a segments_N file. + segmentInfos.updateGeneration(toSync); + } + + assert pendingCommit == null; + setPending = true; + pendingCommit = toSync; + pendingCommitChangeCount = myChangeCount; + success = true; } finally { - // Have our master segmentInfos record the - // generations we just prepared. We do this - // on error or success so we don't - // double-write a segments_N file. - segmentInfos.updateGeneration(toSync); + if (!success && infoStream != null) + message("hit exception committing segments file"); } - - assert pendingCommit == null; - setPending = true; - pendingCommit = toSync; - pendingCommitChangeCount = myChangeCount; - success = true; - } finally { - if (!success && infoStream != null) - message("hit exception committing segments file"); + break; + } else { + // Must wait for other commit to complete + doWait(); } - } else if (infoStream != null) - message("sync superseded by newer infos"); + } } if (infoStream != null)