SegmentSizeAndDocs(SegmentCommitInfo info, final long sizeInBytes, final int segDelCount) throws IOException { segInfo = info; this.name = info.info.name; this.sizeInBytes = sizeInBytes; this.delCount = segDelCount; this.maxDoc = info.info.maxDoc(); } }
/** * Returns the total number of documents that are included with this merge. * Note that this does not indicate the number of documents after the merge. * */ public int totalNumDocs() { int total = 0; for (SegmentCommitInfo info : segments) { total += info.info.maxDoc(); } return total; }
/** * Asserts that the delCount for this SegmentCommitInfo is valid */ protected final boolean assertDelCount(int delCount, SegmentCommitInfo info) { assert delCount >= 0: "delCount must be positive: " + delCount; assert delCount <= info.info.maxDoc() : "delCount: " + delCount + " must be leq than maxDoc: " + info.info.maxDoc(); return true; }
@Override public int maxDoc() { // Don't call ensureOpen() here (it could affect performance) return si.info.maxDoc(); }
/** True if any merging should happen */ boolean shouldMerge() { return mergeState.segmentInfo.maxDoc() > 0; }
void setDelCount(int delCount) { if (delCount < 0 || delCount > info.maxDoc()) { throw new IllegalArgumentException("invalid delCount=" + delCount + " (maxDoc=" + info.maxDoc() + ")"); } assert softDelCount + delCount <= info.maxDoc() : "maxDoc=" + info.maxDoc() + ",delCount=" + delCount + ",softDelCount=" + softDelCount; this.delCount = delCount; }
void setSoftDelCount(int softDelCount) { if (softDelCount < 0 || softDelCount > info.maxDoc()) { throw new IllegalArgumentException("invalid softDelCount=" + softDelCount + " (maxDoc=" + info.maxDoc() + ")"); } assert softDelCount + delCount <= info.maxDoc() : "maxDoc=" + info.maxDoc() + ",delCount=" + delCount + ",softDelCount=" + softDelCount; this.softDelCount = softDelCount; }
/** * Returns the number of live documents in this segment */ final int numDocs() { return info.info.maxDoc() - getDelCount(); }
/** Returns sum of all segment's maxDocs. Note that * this does not include deletions */ public int totalMaxDoc() { long count = 0; for(SegmentCommitInfo info : this) { count += info.info.maxDoc(); } // we should never hit this, checks should happen elsewhere... assert count <= IndexWriter.getActualMaxDocs(); return Math.toIntExact(count); }
/** Return the byte size of the provided {@link * SegmentCommitInfo}, pro-rated by percentage of * non-deleted documents is set. */ protected long size(SegmentCommitInfo info, MergeContext mergeContext) throws IOException { long byteSize = info.sizeInBytes(); int delCount = mergeContext.numDeletesToMerge(info); assert assertDelCount(delCount, info); double delRatio = info.info.maxDoc() <= 0 ? 0.0f : (float) delCount / (float) info.info.maxDoc(); assert delRatio <= 1.0; return (info.info.maxDoc() <= 0 ? byteSize : (long) (byteSize * (1.0 - delRatio))); }
/** * Returns <code>true</code> iff the segment represented by this {@link PendingDeletes} is fully deleted */ boolean isFullyDeleted(IOSupplier<CodecReader> readerIOSupplier) throws IOException { return getDelCount() == info.info.maxDoc(); }
/** Return the number of documents in the provided {@link * SegmentCommitInfo}, pro-rated by percentage of * non-deleted documents if {@link * #setCalibrateSizeByDeletes} is set. */ protected long sizeDocs(SegmentCommitInfo info, MergeContext mergeContext) throws IOException { if (calibrateSizeByDeletes) { int delCount = mergeContext.numDeletesToMerge(info); assert assertDelCount(delCount, info); return (info.info.maxDoc() - (long)delCount); } else { return info.info.maxDoc(); } }
/** Sole constructor. * @param segments List of {@link SegmentCommitInfo}s * to be merged. */ public OneMerge(List<SegmentCommitInfo> segments) { if (0 == segments.size()) { throw new RuntimeException("segments must include at least one segment"); } // clone the list, as the in list may be based off original SegmentInfos and may be modified this.segments = new ArrayList<>(segments); int count = 0; for(SegmentCommitInfo info : segments) { count += info.info.maxDoc(); } totalMaxDoc = count; mergeProgress = new OneMergeProgress(); }
void flush(SegmentWriteState state, Sorter.DocMap sortMap) throws IOException { try { writer.finish(state.fieldInfos, state.segmentInfo.maxDoc()); } finally { IOUtils.close(writer); writer = null; } }
final synchronized int maxDoc(int i) { if (i >= 0 && i < segmentInfos.size()) { return segmentInfos.info(i).info.maxDoc(); } else { return -1; } }
@Override public String toString() { // SegmentInfo.toString takes dir and number of // *pending* deletions; so we reverse compute that here: return si.toString(si.info.maxDoc() - numDocs - si.getDelCount()); }
private boolean assertPendingDeletes() { assert pendingDeleteCount + info.getSoftDelCount() >= 0 : " illegal pending delete count: " + pendingDeleteCount + info.getSoftDelCount(); assert info.info.maxDoc() >= getDelCount(); return true; }
/** * Marks a document as deleted in this segment and return true if a document got actually deleted or * if the document was already deleted. */ boolean delete(int docID) throws IOException { assert info.info.maxDoc() > 0; FixedBitSet mutableBits = getMutableBits(); assert mutableBits != null; assert docID >= 0 && docID < mutableBits.length() : "out of bounds: docid=" + docID + " liveDocsLength=" + mutableBits.length() + " seg=" + info.info.name + " maxDoc=" + info.info.maxDoc(); final boolean didDelete = mutableBits.get(docID); if (didDelete) { mutableBits.clear(docID); pendingDeleteCount++; } return didDelete; }
/** Returns total number of docs in this index, including * docs not yet flushed (still in the RAM buffer), and * including deletions. <b>NOTE:</b> buffered deletions * are not counted. If you really need these to be * counted you should call {@link #commit()} first. * @see #numDocs */ public synchronized int numDocs() { ensureOpen(); int count = docWriter.getNumDocs(); for (final SegmentCommitInfo info : segmentInfos) { count += info.info.maxDoc() - numDeletedDocs(info); } return count; }
private synchronized Set<String> writeFieldInfosGen(FieldInfos fieldInfos, Directory dir, FieldInfosFormat infosFormat) throws IOException { final long nextFieldInfosGen = info.getNextFieldInfosGen(); final String segmentSuffix = Long.toString(nextFieldInfosGen, Character.MAX_RADIX); // we write approximately that many bytes (based on Lucene46DVF): // HEADER + FOOTER: 40 // 90 bytes per-field (over estimating long name and attributes map) final long estInfosSize = 40 + 90 * fieldInfos.size(); final IOContext infosContext = new IOContext(new FlushInfo(info.info.maxDoc(), estInfosSize)); // separately also track which files were created for this gen final TrackingDirectoryWrapper trackingDir = new TrackingDirectoryWrapper(dir); infosFormat.write(trackingDir, info.info, segmentSuffix, fieldInfos, infosContext); info.advanceFieldInfosGen(); return trackingDir.getCreatedFiles(); }