LUCENE-3661: remove SI.getDelFileName

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3661@1233709 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-01-20 01:46:07 +00:00
parent c2ad31a702
commit 2dee41b88e
4 changed files with 36 additions and 52 deletions

View File

@ -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<String> 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()));
}
}
}

View File

@ -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.........");

View File

@ -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;

View File

@ -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
*/