Index: contrib/misc/src/java/org/apache/lucene/index/IndexSplitter.java =================================================================== --- contrib/misc/src/java/org/apache/lucene/index/IndexSplitter.java (revision 1042904) +++ contrib/misc/src/java/org/apache/lucene/index/IndexSplitter.java (working copy) @@ -134,6 +134,7 @@ int idx = getIdx(n); infos.remove(idx); } + infos.changed(); infos.commit(fsDir); } @@ -152,6 +153,7 @@ copyFile(srcFile, destFile); } } + destInfos.changed(); destInfos.commit(destFSDir); // System.out.println("destDir:"+destDir.getAbsolutePath()); } Index: src/java/org/apache/lucene/index/CheckIndex.java =================================================================== --- src/java/org/apache/lucene/index/CheckIndex.java (revision 1042904) +++ src/java/org/apache/lucene/index/CheckIndex.java (working copy) @@ -879,6 +879,7 @@ public void fixIndex(Status result) throws IOException { if (result.partial) throw new IllegalArgumentException("can only fix an index that was fully checked (this status checked a subset of segments)"); + result.newSegments.changed(); result.newSegments.commit(result.dir); } Index: src/java/org/apache/lucene/index/DirectoryReader.java =================================================================== --- src/java/org/apache/lucene/index/DirectoryReader.java (revision 1042904) +++ src/java/org/apache/lucene/index/DirectoryReader.java (working copy) @@ -770,6 +770,7 @@ deletionPolicy == null ? new KeepOnlyLastCommitDeletionPolicy() : deletionPolicy, segmentInfos, null, null, codecs); segmentInfos.updateGeneration(deleter.getLastSegmentInfos()); + segmentInfos.changed(); // Checkpoint the state we are about to change, in // case we have to roll back: @@ -782,7 +783,6 @@ // Sync all files we just wrote directory.sync(segmentInfos.files(directory, false)); - segmentInfos.commit(directory); success = true; } finally { Index: src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- src/java/org/apache/lucene/index/IndexWriter.java (revision 1042904) +++ src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -741,6 +741,7 @@ // Record that we have a change (zero out all // segments) pending: changeCount++; + segmentInfos.changed(); } else { segmentInfos.read(directory, codecs); @@ -757,6 +758,7 @@ oldInfos.read(directory, commit.getSegmentsFileName(), codecs); segmentInfos.replace(oldInfos); changeCount++; + segmentInfos.changed(); if (infoStream != null) message("init: loaded commit \"" + commit.getSegmentsFileName() + "\""); } @@ -774,12 +776,14 @@ conf.getIndexDeletionPolicy(), segmentInfos, infoStream, docWriter, codecs); - if (deleter.startingCommitDeleted) + if (deleter.startingCommitDeleted) { // Deletion policy deleted the "head" commit point. // We have to mark ourself as changed so that if we // are closed w/o any further changes we write a new // segments_N file. changeCount++; + segmentInfos.changed(); + } docWriter.setMaxBufferedDeleteTerms(conf.getMaxBufferedDeleteTerms()); docWriter.setRAMBufferSizeMB(conf.getRAMBufferSizeMB()); @@ -1537,6 +1541,7 @@ // name that was previously returned which can cause // problems at least with ConcurrentMergeScheduler. changeCount++; + segmentInfos.changed(); return "_" + Integer.toString(segmentInfos.counter++, Character.MAX_RADIX); } } @@ -2038,6 +2043,7 @@ // Mark that the index has changed ++changeCount; + segmentInfos.changed(); } catch (OutOfMemoryError oom) { handleOOM(oom, "deleteAll"); } finally { @@ -2119,6 +2125,7 @@ */ private synchronized void checkpoint() throws IOException { changeCount++; + segmentInfos.changed(); deleter.checkpoint(segmentInfos, false); } @@ -3686,6 +3693,7 @@ } toSync.remove(toSync.size()-1); changeCount++; + segmentInfos.changed(); } } assert filesExist(toSync); Index: src/java/org/apache/lucene/index/SegmentInfos.java =================================================================== --- src/java/org/apache/lucene/index/SegmentInfos.java (revision 1042904) +++ src/java/org/apache/lucene/index/SegmentInfos.java (working copy) @@ -696,7 +696,6 @@ void updateGeneration(SegmentInfos other) { lastGeneration = other.lastGeneration; generation = other.generation; - version = other.version; } final void rollbackCommit(Directory dir) throws IOException { @@ -811,7 +810,11 @@ } /** Writes & syncs to the Directory dir, taking care to - * remove the segments file on exception */ + * remove the segments file on exception + *

+ * Note: {@link #changed()} should be called prior to this + * method if changes have been made to this {@link SegmentInfos} + **/ final void commit(Directory dir) throws IOException { prepareCommit(dir); finishCommit(dir); @@ -862,4 +865,10 @@ } return count; } + + /** Call this before committing if changes have been made to the + * segments. */ + public void changed() { + version++; + } } Index: src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java =================================================================== --- src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java (revision 1042904) +++ src/java/org/apache/lucene/index/codecs/DefaultSegmentInfosWriter.java (working copy) @@ -51,8 +51,7 @@ throws IOException { IndexOutput out = createOutput(dir, segmentFileName); out.writeInt(FORMAT_CURRENT); // write FORMAT - out.writeLong(++infos.version); // every write changes - // the index + out.writeLong(infos.version); out.writeInt(infos.counter); // write counter out.writeInt(infos.size()); // write infos for (SegmentInfo si : infos) {