diff --git a/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.java b/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.java index 768d3d7d7b3..76850fc1e14 100644 --- a/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.java +++ b/lucene/src/java/org/apache/lucene/codecs/lucene40/Lucene40LiveDocsFormat.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.util.Set; import org.apache.lucene.codecs.LiveDocsFormat; +import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; @@ -21,22 +22,36 @@ public class Lucene40LiveDocsFormat extends LiveDocsFormat { @Override public Bits readLiveDocs(Directory dir, SegmentInfo info, IOContext context) throws IOException { - // nocommit: compute filename here - return new BitVector(dir, info.getDelFileName(), context); + String filename = IndexFileNames.fileNameFromGeneration(info.name, IndexFileNames.DELETES_EXTENSION, info.getDelGen()); + return new BitVector(dir, filename, context); } @Override public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, IOContext context) throws IOException { - // nocommit: compute filename here // nocommit: this api is ugly... - ((BitVector)bits).write(dir, info.getDelFileName(), context); + String filename = IndexFileNames.fileNameFromGeneration(info.name, IndexFileNames.DELETES_EXTENSION, info.getDelGen()); + + // nocommit: is it somehow cleaner to still have IW do this try/finally/delete stuff and add abort() instead? + boolean success = false; + try { + ((BitVector)bits).write(dir, filename, context); + success = true; + } finally { + if (!success) { + try { + dir.deleteFile(filename); + } catch (Throwable t) { + // suppress this so we keep throwing the + // original exception + } + } + } } @Override public void files(Directory dir, SegmentInfo info, Set files) throws IOException { - // nocommit: compute filename here if (info.hasDeletions()) { - files.add(info.getDelFileName()); + files.add(IndexFileNames.fileNameFromGeneration(info.name, IndexFileNames.DELETES_EXTENSION, info.getDelGen())); } } } diff --git a/lucene/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/src/java/org/apache/lucene/index/CheckIndex.java index efac32a9c5c..a993fb8f27c 100644 --- a/lucene/src/java/org/apache/lucene/index/CheckIndex.java +++ b/lucene/src/java/org/apache/lucene/index/CheckIndex.java @@ -174,8 +174,8 @@ public class CheckIndex { /** True if this segment has pending deletions. */ public boolean hasDeletions; - /** Name of the current deletions file name. */ - public String deletionsFileName; + /** Current deletions generation. */ + public long deletionsGen; /** Number of deleted documents. */ public int numDeleted; @@ -526,15 +526,14 @@ public class CheckIndex { segInfoStat.docStoreCompoundFile = info.getDocStoreIsCompoundFile(); } - final String delFileName = info.getDelFileName(); - if (delFileName == null){ + if (info.hasDeletions()) { msg(" no deletions"); segInfoStat.hasDeletions = false; } else{ - msg(" has deletions [delFileName=" + delFileName + "]"); + msg(" has deletions [delGen=" + info.getDelGen() + "]"); segInfoStat.hasDeletions = true; - segInfoStat.deletionsFileName = delFileName; + segInfoStat.deletionsGen = info.getDelGen(); } if (infoStream != null) infoStream.print(" test: open reader........."); diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.java index c94c47862fe..512157f063a 100644 --- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java @@ -616,7 +616,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { // We can write directly to the actual name (vs to a // .tmp & renaming it) because the file is not live // until segments file is written: - final String delFileName = info.getDelFileName(); boolean success = false; try { info.getCodec().liveDocsFormat().writeLiveDocs(liveDocs, dir, info, IOContext.DEFAULT); @@ -624,12 +623,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { } finally { if (!success) { info.reset(sav); - try { - dir.deleteFile(delFileName); - } catch (Throwable t) { - // Suppress this so we keep throwing the - // original exception - } } } assert (info.docCount - liveDocs.count()) == info.getDelCount() + pendingDeleteCount: @@ -2257,32 +2250,19 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { assert delCount > 0; newSegment.setDelCount(delCount); newSegment.advanceDelGen(); - final String delFileName = newSegment.getDelFileName(); if (infoStream.isEnabled("IW")) { - infoStream.message("IW", "flush: write " + delCount + " deletes to " + delFileName); + infoStream.message("IW", "flush: write " + delCount + " deletes gen=" + flushedSegment.segmentInfo.getDelGen()); } - boolean success2 = false; - try { - // TODO: in the NRT case it'd be better to hand - // this del vector over to the - // shortly-to-be-opened SegmentReader and let it - // carry the changes; there's no reason to use - // filesystem as intermediary here. + + // TODO: in the NRT case it'd be better to hand + // this del vector over to the + // shortly-to-be-opened SegmentReader and let it + // carry the changes; there's no reason to use + // filesystem as intermediary here. - SegmentInfo info = flushedSegment.segmentInfo; - Codec codec = info.getCodec(); - codec.liveDocsFormat().writeLiveDocs(flushedSegment.liveDocs, directory, info, context); - success2 = true; - } finally { - if (!success2) { - try { - directory.deleteFile(delFileName); - } catch (Throwable t) { - // suppress this so we keep throwing the - // original exception - } - } - } + SegmentInfo info = flushedSegment.segmentInfo; + Codec codec = info.getCodec(); + codec.liveDocsFormat().writeLiveDocs(flushedSegment.liveDocs, directory, info, context); } success = true; diff --git a/lucene/src/java/org/apache/lucene/index/SegmentInfo.java b/lucene/src/java/org/apache/lucene/index/SegmentInfo.java index 1da48086864..d5b01d6d38d 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentInfo.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentInfo.java @@ -326,16 +326,6 @@ public final class SegmentInfo implements Cloneable { return si; } - public String getDelFileName() { - if (delGen == NO) { - // In this case we know there is no deletion filename - // against this segment - return null; - } else { - return IndexFileNames.fileNameFromGeneration(name, IndexFileNames.DELETES_EXTENSION, delGen); - } - } - /** * @deprecated separate norms are not supported in >= 4.0 */