Index: src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- src/java/org/apache/lucene/index/IndexWriter.java (revision 412530) +++ src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -610,18 +610,8 @@ if(sReader != null) sReader.close(); - synchronized (directory) { // in- & inter-process sync - new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), commitLockTimeout) { - public Object doBody() throws IOException { - segmentInfos.write(directory); // commit changes - return null; - } - }.run(); - } - - deleteSegments(segmentsToDelete); // delete now-unused segments - if (useCompoundFile) { + // create Coumpound File final Vector filesToDelete = merger.createCompoundFile(mergedName + ".tmp"); synchronized (directory) { // in- & inter-process sync new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), commitLockTimeout) { @@ -636,6 +626,19 @@ // delete now unused files of segment deleteFiles(filesToDelete); } + + synchronized (directory) { // in- & inter-process sync + new Lock.With(directory.makeLock(COMMIT_LOCK_NAME), commitLockTimeout) { + public Object doBody() throws IOException { + segmentInfos.write(directory); // commit changes + return null; + } + }.run(); + } + + deleteSegments(segmentsToDelete); // delete now-unused segments + + } /** Merges all RAM-resident segments. */