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:
Robert Muir 2012-01-19 18:10:51 +00:00
parent da3dbb0e0c
commit e2a4b86260
5 changed files with 28 additions and 21 deletions

View File

@ -68,7 +68,7 @@ public final class BitVector implements Cloneable, MutableBits {
} }
@Override @Override
public Object clone() { public BitVector clone() {
byte[] copyBits = new byte[bits.length]; byte[] copyBits = new byte[bits.length];
System.arraycopy(bits, 0, copyBits, 0, bits.length); System.arraycopy(bits, 0, copyBits, 0, bits.length);
BitVector clone = new BitVector(copyBits, size); BitVector clone = new BitVector(copyBits, size);

View File

@ -34,7 +34,6 @@ import java.util.regex.Pattern;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.codecs.Codec; 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.DocumentsWriterPerThread.FlushedSegment;
import org.apache.lucene.index.FieldInfos.FieldNumberBiMap; import org.apache.lucene.index.FieldInfos.FieldNumberBiMap;
import org.apache.lucene.index.IndexWriterConfig.OpenMode; 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.Constants;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.InfoStream; import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.MutableBits;
import org.apache.lucene.util.ThreadInterruptedException; import org.apache.lucene.util.ThreadInterruptedException;
import org.apache.lucene.util.TwoPhaseCommit; 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 // docs, and it's copy-on-write (cloned whenever we need
// to change it but it's been shared to an external NRT // to change it but it's been shared to an external NRT
// reader). // reader).
public BitVector liveDocs; public MutableBits liveDocs;
// How many further deletions we've done against // How many further deletions we've done against
// liveDocs vs when we loaded it or last wrote it: // liveDocs vs when we loaded it or last wrote it:
@ -486,7 +486,8 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
if (reader == null) { if (reader == null) {
reader = new SegmentReader(info, config.getReaderTermsIndexDivisor(), context); reader = new SegmentReader(info, config.getReaderTermsIndexDivisor(), context);
if (liveDocs == null) { 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"); //System.out.println("ADD seg=" + rld.info + " isMerge=" + isMerge + " " + readerMap.size() + " in pool");
} }
@ -513,7 +514,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
} else { } else {
mergeReader = new SegmentReader(info, -1, context); mergeReader = new SegmentReader(info, -1, context);
if (liveDocs == null) { 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); assert Thread.holdsLock(IndexWriter.this);
//System.out.println("initWritableLivedocs seg=" + info + " liveDocs=" + liveDocs + " shared=" + shared); //System.out.println("initWritableLivedocs seg=" + info + " liveDocs=" + liveDocs + " shared=" + shared);
if (shared) { if (shared) {
@ -577,10 +578,9 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
// change it: // change it:
if (liveDocs == null) { if (liveDocs == null) {
//System.out.println("create BV seg=" + info); //System.out.println("create BV seg=" + info);
liveDocs = new BitVector(info.docCount); liveDocs = info.getCodec().liveDocsFormat().newLiveDocs(info.docCount);
liveDocs.setAll();
} else { } else {
liveDocs = (BitVector) liveDocs.clone(); liveDocs = liveDocs.clone();
} }
shared = false; shared = false;
} else { } 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); //System.out.println("getROLiveDocs seg=" + info);
assert Thread.holdsLock(IndexWriter.this); assert Thread.holdsLock(IndexWriter.this);
shared = true; shared = true;
@ -618,7 +619,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
final String delFileName = info.getDelFileName(); final String delFileName = info.getDelFileName();
boolean success = false; boolean success = false;
try { try {
liveDocs.write(dir, delFileName, IOContext.DEFAULT); info.getCodec().liveDocsFormat().writeLiveDocs(liveDocs, dir, info, IOContext.DEFAULT);
success = true; success = true;
} finally { } finally {
if (!success) { if (!success) {
@ -3035,8 +3036,8 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
SegmentInfo info = sourceSegments.get(i); SegmentInfo info = sourceSegments.get(i);
minGen = Math.min(info.getBufferedDeletesGen(), minGen); minGen = Math.min(info.getBufferedDeletesGen(), minGen);
final int docCount = info.docCount; final int docCount = info.docCount;
final BitVector prevLiveDocs = merge.readerLiveDocs.get(i); final MutableBits prevLiveDocs = merge.readerLiveDocs.get(i);
final BitVector currentLiveDocs; final MutableBits currentLiveDocs;
ReadersAndLiveDocs rld = readerPool.get(info, false); ReadersAndLiveDocs rld = readerPool.get(info, false);
// We enrolled in mergeInit: // We enrolled in mergeInit:
assert rld != null; assert rld != null;
@ -3576,7 +3577,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
} }
merge.readers = new ArrayList<SegmentReader>(); 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 // This is try/finally to make sure merger's readers are
// closed: // closed:
@ -3595,7 +3596,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
assert reader != null; assert reader != null;
// Carefully pull the most recent live docs: // Carefully pull the most recent live docs:
final BitVector liveDocs; final MutableBits liveDocs;
synchronized(this) { synchronized(this) {
// Must sync to ensure BufferedDeletesStream // Must sync to ensure BufferedDeletesStream
// cannot change liveDocs/pendingDeleteCount while // cannot change liveDocs/pendingDeleteCount while

View File

@ -22,9 +22,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.lucene.codecs.lucene40.BitVector;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MergeInfo; 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.AlreadySetException;
import org.apache.lucene.util.SetOnce; import org.apache.lucene.util.SetOnce;
@ -74,7 +74,7 @@ public abstract class MergePolicy implements java.io.Closeable {
int maxNumSegments = -1; // used by IndexWriter int maxNumSegments = -1; // used by IndexWriter
public long estimatedMergeBytes; // used by IndexWriter public long estimatedMergeBytes; // used by IndexWriter
List<SegmentReader> readers; // 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 List<SegmentInfo> segments;
public final int totalDocCount; public final int totalDocCount;
boolean aborted; boolean aborted;

View File

@ -23,10 +23,11 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.codecs.PerDocProducer; import org.apache.lucene.codecs.PerDocProducer;
import org.apache.lucene.codecs.StoredFieldsReader; import org.apache.lucene.codecs.StoredFieldsReader;
import org.apache.lucene.codecs.TermVectorsReader; 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.search.FieldCache; // javadocs
import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IOContext;
import org.apache.lucene.util.Bits; import org.apache.lucene.util.Bits;
import org.apache.lucene.util.MutableBits;
/** /**
* @lucene.experimental * @lucene.experimental
@ -92,7 +93,7 @@ public final class SegmentReader extends IndexReader {
assert si.hasDeletions(); assert si.hasDeletions();
// ... but load our own deleted docs: // ... 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(); numDocs = si.docCount - si.getDelCount();
assert checkLiveCounts(false); assert checkLiveCounts(false);
@ -105,7 +106,7 @@ public final class SegmentReader extends IndexReader {
// SegmentReader and using the provided in-memory // SegmentReader and using the provided in-memory
// liveDocs. Used by IndexWriter to provide a new NRT // liveDocs. Used by IndexWriter to provide a new NRT
// reader: // reader:
SegmentReader(SegmentReader parent, BitVector liveDocs, int numDocs) throws IOException { SegmentReader(SegmentReader parent, MutableBits liveDocs, int numDocs) throws IOException {
this.si = parent.si; this.si = parent.si;
parent.core.incRef(); parent.core.incRef();
this.core = parent.core; this.core = parent.core;

View File

@ -17,8 +17,13 @@ package org.apache.lucene.util;
* limitations under the License. * limitations under the License.
*/ */
public interface MutableBits extends Bits { public interface MutableBits extends Bits,Cloneable {
public void clear(int bit); public void clear(int bit);
// nocommit: remove this from this interface somehow? (used by DWPT infostream at least) // nocommit: remove this from this interface somehow? (used by DWPT infostream at least)
public int count(); public int count();
// nocommit: are these truly necessary?
public boolean getAndSet(int bit);
public boolean getAndClear(int bit);
public MutableBits clone();
} }