mirror of https://github.com/apache/lucene.git
LUCENE-4055: remove SegmentInfo.reset method
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4055@1339328 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4554a4ff2f
commit
bd0d03833a
|
@ -29,13 +29,21 @@ import org.apache.lucene.util.MutableBits;
|
||||||
/** Format for live/deleted documents
|
/** Format for live/deleted documents
|
||||||
* @lucene.experimental */
|
* @lucene.experimental */
|
||||||
public abstract class LiveDocsFormat {
|
public abstract class LiveDocsFormat {
|
||||||
/** creates a new mutablebits, with all bits set, for the specified size */
|
/** Creates a new MutableBits, with all bits set, for the specified size. */
|
||||||
public abstract MutableBits newLiveDocs(int size) throws IOException;
|
public abstract MutableBits newLiveDocs(int size) throws IOException;
|
||||||
/** creates a new mutablebits of the same bits set and size of existing */
|
|
||||||
|
/** Creates a new mutablebits of the same bits set and size of existing. */
|
||||||
public abstract MutableBits newLiveDocs(Bits existing) throws IOException;
|
public abstract MutableBits newLiveDocs(Bits existing) throws IOException;
|
||||||
/** reads bits from a file */
|
|
||||||
|
/** Read live docs bits. */
|
||||||
public abstract Bits readLiveDocs(Directory dir, SegmentInfo info, IOContext context) throws IOException;
|
public abstract Bits readLiveDocs(Directory dir, SegmentInfo info, IOContext context) throws IOException;
|
||||||
/** writes bits to a file */
|
|
||||||
public abstract void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, IOContext context) throws IOException;
|
/** Persist live docs bits. Use {@link
|
||||||
|
* SegmentInfo#getNextDelGen} to determine the
|
||||||
|
* generation of the deletes file you should write to. */
|
||||||
|
public abstract void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, int newDelCount, IOContext context) throws IOException;
|
||||||
|
|
||||||
|
/** Records all files in use by this {@link SegmentInfo}
|
||||||
|
* into the files argument. */
|
||||||
public abstract void files(SegmentInfo info, Set<String> files) throws IOException;
|
public abstract void files(SegmentInfo info, Set<String> files) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class Lucene3xCodec extends Codec {
|
||||||
// TODO: this should really be a different impl
|
// TODO: this should really be a different impl
|
||||||
private final LiveDocsFormat liveDocsFormat = new Lucene40LiveDocsFormat() {
|
private final LiveDocsFormat liveDocsFormat = new Lucene40LiveDocsFormat() {
|
||||||
@Override
|
@Override
|
||||||
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, IOContext context) throws IOException {
|
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, int newDelCount, IOContext context) throws IOException {
|
||||||
throw new UnsupportedOperationException("this codec can only be used for reading");
|
throw new UnsupportedOperationException("this codec can only be used for reading");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -90,10 +90,10 @@ public class Lucene40LiveDocsFormat extends LiveDocsFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, IOContext context) throws IOException {
|
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, int newDelCount, IOContext context) throws IOException {
|
||||||
String filename = IndexFileNames.fileNameFromGeneration(info.name, DELETES_EXTENSION, info.getDelGen());
|
String filename = IndexFileNames.fileNameFromGeneration(info.name, DELETES_EXTENSION, info.getNextDelGen());
|
||||||
final BitVector liveDocs = (BitVector) bits;
|
final BitVector liveDocs = (BitVector) bits;
|
||||||
assert liveDocs.count() == info.docCount - info.getDelCount();
|
assert liveDocs.count() == info.docCount - info.getDelCount() - newDelCount;
|
||||||
assert liveDocs.length() == info.docCount;
|
assert liveDocs.length() == info.docCount;
|
||||||
liveDocs.write(dir, filename, context);
|
liveDocs.write(dir, filename, context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,12 +105,12 @@ public class SimpleTextLiveDocsFormat extends LiveDocsFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, IOContext context) throws IOException {
|
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfo info, int newDelCount, IOContext context) throws IOException {
|
||||||
BitSet set = ((SimpleTextBits) bits).bits;
|
BitSet set = ((SimpleTextBits) bits).bits;
|
||||||
int size = bits.length();
|
int size = bits.length();
|
||||||
BytesRef scratch = new BytesRef();
|
BytesRef scratch = new BytesRef();
|
||||||
|
|
||||||
String fileName = IndexFileNames.fileNameFromGeneration(info.name, LIVEDOCS_EXTENSION, info.getDelGen());
|
String fileName = IndexFileNames.fileNameFromGeneration(info.name, LIVEDOCS_EXTENSION, info.getNextDelGen());
|
||||||
IndexOutput out = null;
|
IndexOutput out = null;
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1996,8 +1996,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
||||||
if (flushedSegment.liveDocs != null) {
|
if (flushedSegment.liveDocs != null) {
|
||||||
final int delCount = flushedSegment.delCount;
|
final int delCount = flushedSegment.delCount;
|
||||||
assert delCount > 0;
|
assert delCount > 0;
|
||||||
newSegment.setDelCount(delCount);
|
|
||||||
newSegment.advanceDelGen();
|
|
||||||
if (infoStream.isEnabled("IW")) {
|
if (infoStream.isEnabled("IW")) {
|
||||||
infoStream.message("IW", "flush: write " + delCount + " deletes gen=" + flushedSegment.segmentInfo.getDelGen());
|
infoStream.message("IW", "flush: write " + delCount + " deletes gen=" + flushedSegment.segmentInfo.getDelGen());
|
||||||
}
|
}
|
||||||
|
@ -2010,7 +2008,9 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
||||||
|
|
||||||
SegmentInfo info = flushedSegment.segmentInfo;
|
SegmentInfo info = flushedSegment.segmentInfo;
|
||||||
Codec codec = info.getCodec();
|
Codec codec = info.getCodec();
|
||||||
codec.liveDocsFormat().writeLiveDocs(flushedSegment.liveDocs, directory, info, context);
|
codec.liveDocsFormat().writeLiveDocs(flushedSegment.liveDocs, directory, info, delCount, context);
|
||||||
|
newSegment.setDelCount(delCount);
|
||||||
|
newSegment.advanceDelGen();
|
||||||
}
|
}
|
||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
|
|
|
@ -272,23 +272,17 @@ class ReadersAndLiveDocs {
|
||||||
// We have new deletes
|
// We have new deletes
|
||||||
assert liveDocs.length() == info.docCount;
|
assert liveDocs.length() == info.docCount;
|
||||||
|
|
||||||
// Save in case we need to rollback on failure:
|
|
||||||
final SegmentInfo sav = info.clone();
|
|
||||||
info.advanceDelGen();
|
|
||||||
info.setDelCount(info.getDelCount() + pendingDeleteCount);
|
|
||||||
|
|
||||||
// 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:
|
||||||
boolean success = false;
|
info.getCodec().liveDocsFormat().writeLiveDocs((MutableBits)liveDocs, dir, info, pendingDeleteCount, IOContext.DEFAULT);
|
||||||
try {
|
|
||||||
info.getCodec().liveDocsFormat().writeLiveDocs((MutableBits)liveDocs, dir, info, IOContext.DEFAULT);
|
// If we hit an exc in the line above (eg disk full)
|
||||||
success = true;
|
// then info remains pointing to the previous
|
||||||
} finally {
|
// (successfully written) del docs:
|
||||||
if (!success) {
|
info.advanceDelGen();
|
||||||
info.reset(sav);
|
info.setDelCount(info.getDelCount() + pendingDeleteCount);
|
||||||
}
|
|
||||||
}
|
|
||||||
pendingDeleteCount = 0;
|
pendingDeleteCount = 0;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -127,35 +127,6 @@ public final class SegmentInfo implements Cloneable {
|
||||||
this.fieldInfos = fieldInfos;
|
this.fieldInfos = fieldInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy everything from src SegmentInfo into our instance.
|
|
||||||
*/
|
|
||||||
void reset(SegmentInfo src) {
|
|
||||||
clearFilesCache();
|
|
||||||
version = src.version;
|
|
||||||
name = src.name;
|
|
||||||
docCount = src.docCount;
|
|
||||||
dir = src.dir;
|
|
||||||
delGen = src.delGen;
|
|
||||||
docStoreOffset = src.docStoreOffset;
|
|
||||||
docStoreSegment = src.docStoreSegment;
|
|
||||||
docStoreIsCompoundFile = src.docStoreIsCompoundFile;
|
|
||||||
hasVectors = src.hasVectors;
|
|
||||||
hasProx = src.hasProx;
|
|
||||||
fieldInfos = src.fieldInfos == null ? null : src.fieldInfos.clone();
|
|
||||||
if (src.normGen == null) {
|
|
||||||
normGen = null;
|
|
||||||
} else {
|
|
||||||
normGen = new HashMap<Integer, Long>(src.normGen.size());
|
|
||||||
for (Entry<Integer,Long> entry : src.normGen.entrySet()) {
|
|
||||||
normGen.put(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isCompoundFile = src.isCompoundFile;
|
|
||||||
delCount = src.delCount;
|
|
||||||
codec = src.codec;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDiagnostics(Map<String, String> diagnostics) {
|
void setDiagnostics(Map<String, String> diagnostics) {
|
||||||
this.diagnostics = diagnostics;
|
this.diagnostics = diagnostics;
|
||||||
}
|
}
|
||||||
|
@ -246,6 +217,14 @@ public final class SegmentInfo implements Cloneable {
|
||||||
clearFilesCache();
|
clearFilesCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getNextDelGen() {
|
||||||
|
if (delGen == NO) {
|
||||||
|
return YES;
|
||||||
|
} else {
|
||||||
|
return delGen + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void clearDelGen() {
|
void clearDelGen() {
|
||||||
delGen = NO;
|
delGen = NO;
|
||||||
clearFilesCache();
|
clearFilesCache();
|
||||||
|
|
Loading…
Reference in New Issue