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