mirror of https://github.com/apache/lucene.git
LUCENE-3661: bitvector->mutablebits in indexwriter
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3661@1233507 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
da3dbb0e0c
commit
e2a4b86260
|
@ -68,7 +68,7 @@ public final class BitVector implements Cloneable, MutableBits {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
public BitVector clone() {
|
||||
byte[] copyBits = new byte[bits.length];
|
||||
System.arraycopy(bits, 0, copyBits, 0, bits.length);
|
||||
BitVector clone = new BitVector(copyBits, size);
|
||||
|
|
|
@ -34,7 +34,6 @@ import java.util.regex.Pattern;
|
|||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.codecs.Codec;
|
||||
import org.apache.lucene.codecs.lucene40.BitVector;
|
||||
import org.apache.lucene.index.DocumentsWriterPerThread.FlushedSegment;
|
||||
import org.apache.lucene.index.FieldInfos.FieldNumberBiMap;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
|
@ -52,6 +51,7 @@ import org.apache.lucene.store.MergeInfo;
|
|||
import org.apache.lucene.util.Constants;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.apache.lucene.util.InfoStream;
|
||||
import org.apache.lucene.util.MutableBits;
|
||||
import org.apache.lucene.util.ThreadInterruptedException;
|
||||
import org.apache.lucene.util.TwoPhaseCommit;
|
||||
|
||||
|
@ -416,7 +416,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
|||
// docs, and it's copy-on-write (cloned whenever we need
|
||||
// to change it but it's been shared to an external NRT
|
||||
// reader).
|
||||
public BitVector liveDocs;
|
||||
public MutableBits liveDocs;
|
||||
|
||||
// How many further deletions we've done against
|
||||
// liveDocs vs when we loaded it or last wrote it:
|
||||
|
@ -486,7 +486,8 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
|||
if (reader == null) {
|
||||
reader = new SegmentReader(info, config.getReaderTermsIndexDivisor(), context);
|
||||
if (liveDocs == null) {
|
||||
liveDocs = (BitVector) reader.getLiveDocs();
|
||||
// nocommit: nuke cast
|
||||
liveDocs = (MutableBits) reader.getLiveDocs();
|
||||
}
|
||||
//System.out.println("ADD seg=" + rld.info + " isMerge=" + isMerge + " " + readerMap.size() + " in pool");
|
||||
}
|
||||
|
@ -513,7 +514,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
|||
} else {
|
||||
mergeReader = new SegmentReader(info, -1, context);
|
||||
if (liveDocs == null) {
|
||||
liveDocs = (BitVector) mergeReader.getLiveDocs();
|
||||
liveDocs = (MutableBits) mergeReader.getLiveDocs();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -567,7 +568,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void initWritableLiveDocs() {
|
||||
public synchronized void initWritableLiveDocs() throws IOException {
|
||||
assert Thread.holdsLock(IndexWriter.this);
|
||||
//System.out.println("initWritableLivedocs seg=" + info + " liveDocs=" + liveDocs + " shared=" + shared);
|
||||
if (shared) {
|
||||
|
@ -577,10 +578,9 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
|||
// change it:
|
||||
if (liveDocs == null) {
|
||||
//System.out.println("create BV seg=" + info);
|
||||
liveDocs = new BitVector(info.docCount);
|
||||
liveDocs.setAll();
|
||||
liveDocs = info.getCodec().liveDocsFormat().newLiveDocs(info.docCount);
|
||||
} else {
|
||||
liveDocs = (BitVector) liveDocs.clone();
|
||||
liveDocs = liveDocs.clone();
|
||||
}
|
||||
shared = false;
|
||||
} else {
|
||||
|
@ -588,7 +588,8 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized BitVector getReadOnlyLiveDocs() {
|
||||
// nocommit: if this is read-only live docs, why doesn't it return Bits?!
|
||||
public synchronized MutableBits getReadOnlyLiveDocs() {
|
||||
//System.out.println("getROLiveDocs seg=" + info);
|
||||
assert Thread.holdsLock(IndexWriter.this);
|
||||
shared = true;
|
||||
|
@ -618,7 +619,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
|||
final String delFileName = info.getDelFileName();
|
||||
boolean success = false;
|
||||
try {
|
||||
liveDocs.write(dir, delFileName, IOContext.DEFAULT);
|
||||
info.getCodec().liveDocsFormat().writeLiveDocs(liveDocs, dir, info, IOContext.DEFAULT);
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
|
@ -3035,8 +3036,8 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
|||
SegmentInfo info = sourceSegments.get(i);
|
||||
minGen = Math.min(info.getBufferedDeletesGen(), minGen);
|
||||
final int docCount = info.docCount;
|
||||
final BitVector prevLiveDocs = merge.readerLiveDocs.get(i);
|
||||
final BitVector currentLiveDocs;
|
||||
final MutableBits prevLiveDocs = merge.readerLiveDocs.get(i);
|
||||
final MutableBits currentLiveDocs;
|
||||
ReadersAndLiveDocs rld = readerPool.get(info, false);
|
||||
// We enrolled in mergeInit:
|
||||
assert rld != null;
|
||||
|
@ -3576,7 +3577,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
|||
}
|
||||
|
||||
merge.readers = new ArrayList<SegmentReader>();
|
||||
merge.readerLiveDocs = new ArrayList<BitVector>();
|
||||
merge.readerLiveDocs = new ArrayList<MutableBits>();
|
||||
|
||||
// This is try/finally to make sure merger's readers are
|
||||
// closed:
|
||||
|
@ -3595,7 +3596,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
|
|||
assert reader != null;
|
||||
|
||||
// Carefully pull the most recent live docs:
|
||||
final BitVector liveDocs;
|
||||
final MutableBits liveDocs;
|
||||
synchronized(this) {
|
||||
// Must sync to ensure BufferedDeletesStream
|
||||
// cannot change liveDocs/pendingDeleteCount while
|
||||
|
|
|
@ -22,9 +22,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.codecs.lucene40.BitVector;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.MergeInfo;
|
||||
import org.apache.lucene.util.MutableBits;
|
||||
import org.apache.lucene.util.SetOnce.AlreadySetException;
|
||||
import org.apache.lucene.util.SetOnce;
|
||||
|
||||
|
@ -74,7 +74,7 @@ public abstract class MergePolicy implements java.io.Closeable {
|
|||
int maxNumSegments = -1; // used by IndexWriter
|
||||
public long estimatedMergeBytes; // used by IndexWriter
|
||||
List<SegmentReader> readers; // used by IndexWriter
|
||||
List<BitVector> readerLiveDocs; // used by IndexWriter
|
||||
List<MutableBits> readerLiveDocs; // used by IndexWriter
|
||||
public final List<SegmentInfo> segments;
|
||||
public final int totalDocCount;
|
||||
boolean aborted;
|
||||
|
|
|
@ -23,10 +23,11 @@ import org.apache.lucene.store.Directory;
|
|||
import org.apache.lucene.codecs.PerDocProducer;
|
||||
import org.apache.lucene.codecs.StoredFieldsReader;
|
||||
import org.apache.lucene.codecs.TermVectorsReader;
|
||||
import org.apache.lucene.codecs.lucene40.BitVector;
|
||||
import org.apache.lucene.codecs.lucene40.BitVector; // nocommit: move asserts/checks to codec
|
||||
import org.apache.lucene.search.FieldCache; // javadocs
|
||||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.util.Bits;
|
||||
import org.apache.lucene.util.MutableBits;
|
||||
|
||||
/**
|
||||
* @lucene.experimental
|
||||
|
@ -92,7 +93,7 @@ public final class SegmentReader extends IndexReader {
|
|||
assert si.hasDeletions();
|
||||
|
||||
// ... but load our own deleted docs:
|
||||
liveDocs = new BitVector(si.dir, si.getDelFileName(), context);
|
||||
liveDocs = si.getCodec().liveDocsFormat().readLiveDocs(si.dir, si, context);
|
||||
numDocs = si.docCount - si.getDelCount();
|
||||
assert checkLiveCounts(false);
|
||||
|
||||
|
@ -105,7 +106,7 @@ public final class SegmentReader extends IndexReader {
|
|||
// SegmentReader and using the provided in-memory
|
||||
// liveDocs. Used by IndexWriter to provide a new NRT
|
||||
// reader:
|
||||
SegmentReader(SegmentReader parent, BitVector liveDocs, int numDocs) throws IOException {
|
||||
SegmentReader(SegmentReader parent, MutableBits liveDocs, int numDocs) throws IOException {
|
||||
this.si = parent.si;
|
||||
parent.core.incRef();
|
||||
this.core = parent.core;
|
||||
|
|
|
@ -17,8 +17,13 @@ package org.apache.lucene.util;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
public interface MutableBits extends Bits {
|
||||
public interface MutableBits extends Bits,Cloneable {
|
||||
public void clear(int bit);
|
||||
// nocommit: remove this from this interface somehow? (used by DWPT infostream at least)
|
||||
public int count();
|
||||
|
||||
// nocommit: are these truly necessary?
|
||||
public boolean getAndSet(int bit);
|
||||
public boolean getAndClear(int bit);
|
||||
public MutableBits clone();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue