Search in sources :

Example 1 with MutableBits

use of org.apache.lucene.util.MutableBits in project lucene-solr by apache.

the class DocumentsWriterPerThread method sealFlushedSegment.

/**
   * Seals the {@link SegmentInfo} for the new flushed segment and persists
   * the deleted documents {@link MutableBits}.
   */
void sealFlushedSegment(FlushedSegment flushedSegment, Sorter.DocMap sortMap) throws IOException {
    assert flushedSegment != null;
    SegmentCommitInfo newSegment = flushedSegment.segmentInfo;
    IndexWriter.setDiagnostics(newSegment.info, IndexWriter.SOURCE_FLUSH);
    IOContext context = new IOContext(new FlushInfo(newSegment.info.maxDoc(), newSegment.sizeInBytes()));
    boolean success = false;
    try {
        if (indexWriterConfig.getUseCompoundFile()) {
            Set<String> originalFiles = newSegment.info.files();
            // TODO: like addIndexes, we are relying on createCompoundFile to successfully cleanup...
            indexWriter.createCompoundFile(infoStream, new TrackingDirectoryWrapper(directory), newSegment.info, context);
            filesToDelete.addAll(originalFiles);
            newSegment.info.setUseCompoundFile(true);
        }
        // Have codec write SegmentInfo.  Must do this after
        // creating CFS so that 1) .si isn't slurped into CFS,
        // and 2) .si reflects useCompoundFile=true change
        // above:
        codec.segmentInfoFormat().write(directory, newSegment.info, context);
        // slurp the del file into CFS:
        if (flushedSegment.liveDocs != null) {
            final int delCount = flushedSegment.delCount;
            assert delCount > 0;
            if (infoStream.isEnabled("DWPT")) {
                infoStream.message("DWPT", "flush: write " + delCount + " deletes gen=" + flushedSegment.segmentInfo.getDelGen());
            }
            // TODO: we should prune the segment if it's 100%
            // deleted... but merge will also catch it.
            // 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.
            SegmentCommitInfo info = flushedSegment.segmentInfo;
            Codec codec = info.info.getCodec();
            final MutableBits bits;
            if (sortMap == null) {
                bits = flushedSegment.liveDocs;
            } else {
                bits = sortLiveDocs(flushedSegment.liveDocs, sortMap);
            }
            codec.liveDocsFormat().writeLiveDocs(bits, directory, info, delCount, context);
            newSegment.setDelCount(delCount);
            newSegment.advanceDelGen();
        }
        success = true;
    } finally {
        if (!success) {
            if (infoStream.isEnabled("DWPT")) {
                infoStream.message("DWPT", "hit exception creating compound file for newly flushed segment " + newSegment.info.name);
            }
        }
    }
}
Also used : Codec(org.apache.lucene.codecs.Codec) MutableBits(org.apache.lucene.util.MutableBits) IOContext(org.apache.lucene.store.IOContext) FlushInfo(org.apache.lucene.store.FlushInfo) TrackingDirectoryWrapper(org.apache.lucene.store.TrackingDirectoryWrapper)

Example 2 with MutableBits

use of org.apache.lucene.util.MutableBits in project lucene-solr by apache.

the class AssertingLiveDocsFormat method newLiveDocs.

@Override
public MutableBits newLiveDocs(Bits existing) throws IOException {
    assert existing instanceof AssertingBits;
    Bits rawExisting = ((AssertingBits) existing).in;
    MutableBits raw = in.newLiveDocs(rawExisting);
    assert raw != null;
    assert raw.length() == rawExisting.length();
    for (int i = 0; i < raw.length(); i++) {
        assert rawExisting.get(i) == raw.get(i);
    }
    return new AssertingMutableBits(raw);
}
Also used : MutableBits(org.apache.lucene.util.MutableBits) MutableBits(org.apache.lucene.util.MutableBits) Bits(org.apache.lucene.util.Bits)

Example 3 with MutableBits

use of org.apache.lucene.util.MutableBits in project lucene-solr by apache.

the class AssertingLiveDocsFormat method writeLiveDocs.

@Override
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount, IOContext context) throws IOException {
    assert bits instanceof AssertingMutableBits;
    MutableBits raw = (MutableBits) ((AssertingMutableBits) bits).in;
    check(raw, info.info.maxDoc(), info.getDelCount() + newDelCount);
    in.writeLiveDocs(raw, dir, info, newDelCount, context);
}
Also used : MutableBits(org.apache.lucene.util.MutableBits)

Aggregations

MutableBits (org.apache.lucene.util.MutableBits)3 Codec (org.apache.lucene.codecs.Codec)1 FlushInfo (org.apache.lucene.store.FlushInfo)1 IOContext (org.apache.lucene.store.IOContext)1 TrackingDirectoryWrapper (org.apache.lucene.store.TrackingDirectoryWrapper)1 Bits (org.apache.lucene.util.Bits)1