From da3dbb0e0c3903ae408b7dff68454fcab7aae800 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 19 Jan 2012 17:41:14 +0000 Subject: [PATCH] move some bitvector -> mutablebits git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3661@1233498 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/DocumentsWriterPerThread.java | 9 ++++----- .../apache/lucene/index/FreqProxTermsWriterPerField.java | 6 +++--- lucene/src/java/org/apache/lucene/index/IndexWriter.java | 5 ++++- .../java/org/apache/lucene/index/SegmentWriteState.java | 4 ++-- lucene/src/java/org/apache/lucene/util/MutableBits.java | 4 +++- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java index f4b5b9c0e9e..dd413da75f4 100644 --- a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java +++ b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java @@ -25,7 +25,6 @@ import java.text.NumberFormat; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.codecs.Codec; -import org.apache.lucene.codecs.lucene40.BitVector; import org.apache.lucene.index.DocumentsWriterDeleteQueue.DeleteSlice; import org.apache.lucene.search.similarities.SimilarityProvider; import org.apache.lucene.store.Directory; @@ -36,6 +35,7 @@ import org.apache.lucene.util.ByteBlockPool.Allocator; import org.apache.lucene.util.ByteBlockPool.DirectTrackingAllocator; import org.apache.lucene.util.InfoStream; import org.apache.lucene.util.RamUsageEstimator; +import org.apache.lucene.util.MutableBits; public class DocumentsWriterPerThread { @@ -114,10 +114,10 @@ public class DocumentsWriterPerThread { static class FlushedSegment { final SegmentInfo segmentInfo; final BufferedDeletes segmentDeletes; - final BitVector liveDocs; + final MutableBits liveDocs; private FlushedSegment(SegmentInfo segmentInfo, - BufferedDeletes segmentDeletes, BitVector liveDocs) { + BufferedDeletes segmentDeletes, MutableBits liveDocs) { this.segmentInfo = segmentInfo; this.segmentDeletes = segmentDeletes; this.liveDocs = liveDocs; @@ -448,8 +448,7 @@ public class DocumentsWriterPerThread { // happens when an exception is hit processing that // doc, eg if analyzer has some problem w/ the text): if (pendingDeletes.docIDs.size() > 0) { - flushState.liveDocs = new BitVector(numDocsInRAM); - flushState.liveDocs.invertAll(); + flushState.liveDocs = codec.liveDocsFormat().newLiveDocs(numDocsInRAM); for(int delDocID : pendingDeletes.docIDs) { flushState.liveDocs.clear(delDocID); } diff --git a/lucene/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java b/lucene/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java index 802d11f35bc..ad3502d409d 100644 --- a/lucene/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java +++ b/lucene/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java @@ -27,7 +27,6 @@ import org.apache.lucene.codecs.FieldsConsumer; import org.apache.lucene.codecs.PostingsConsumer; import org.apache.lucene.codecs.TermStats; import org.apache.lucene.codecs.TermsConsumer; -import org.apache.lucene.codecs.lucene40.BitVector; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FixedBitSet; @@ -461,9 +460,10 @@ final class FreqProxTermsWriterPerField extends TermsHashConsumerPerField implem // Mark it deleted. TODO: we could also skip // writing its postings; this would be // deterministic (just for this Term's docs). + + // nocommit: totally wrong to do this reach-around here, and this way if (state.liveDocs == null) { - state.liveDocs = new BitVector(state.numDocs); - state.liveDocs.invertAll(); + state.liveDocs = docState.docWriter.codec.liveDocsFormat().newLiveDocs(state.numDocs); } state.liveDocs.clear(docID); } diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.java index 6d6ec3166dc..43a686f9b38 100644 --- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java @@ -2267,7 +2267,10 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { // shortly-to-be-opened SegmentReader and let it // carry the changes; there's no reason to use // filesystem as intermediary here. - flushedSegment.liveDocs.write(directory, delFileName, context); + + SegmentInfo info = flushedSegment.segmentInfo; + Codec codec = info.getCodec(); + codec.liveDocsFormat().writeLiveDocs(flushedSegment.liveDocs, directory, info, context); success2 = true; } finally { if (!success2) { diff --git a/lucene/src/java/org/apache/lucene/index/SegmentWriteState.java b/lucene/src/java/org/apache/lucene/index/SegmentWriteState.java index 358124ccb93..04211a5b6f0 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentWriteState.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentWriteState.java @@ -18,10 +18,10 @@ package org.apache.lucene.index; */ import org.apache.lucene.codecs.Codec; -import org.apache.lucene.codecs.lucene40.BitVector; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.util.InfoStream; +import org.apache.lucene.util.MutableBits; /** * @lucene.experimental @@ -41,7 +41,7 @@ public class SegmentWriteState { public final BufferedDeletes segDeletes; // Lazily created: - public BitVector liveDocs; + public MutableBits liveDocs; public final Codec codec; public final String segmentSuffix; diff --git a/lucene/src/java/org/apache/lucene/util/MutableBits.java b/lucene/src/java/org/apache/lucene/util/MutableBits.java index 6f5cb96fe44..6dd3efad21a 100644 --- a/lucene/src/java/org/apache/lucene/util/MutableBits.java +++ b/lucene/src/java/org/apache/lucene/util/MutableBits.java @@ -18,5 +18,7 @@ package org.apache.lucene.util; */ public interface MutableBits extends Bits { - + public void clear(int bit); + // nocommit: remove this from this interface somehow? (used by DWPT infostream at least) + public int count(); }