protected long size(SegmentInfo info) throws IOException { long byteSize = info.sizeInBytes(false); float delRatio = (info.docCount <= 0 ? 0.0f : ((float)info.getDelCount() / (float)info.docCount)); return (info.docCount <= 0 ? byteSize : (long)((float)byteSize * (1.0f - delRatio))); }
@Override protected long size(SegmentInfo info) throws IOException { long byteSize = info.sizeInBytes(true); float delRatio = (info.docCount <= 0 ? 0.0f : ((float)info.getDelCount() / (float)info.docCount)); return (info.docCount <= 0 ? byteSize : (long)((1.0f - delRatio) * byteSize)); }
public static String getSegmentsInfo(Directory idx) { SegmentInfos infos=new SegmentInfos(); try { infos.read(idx); StringBuilder buf=new StringBuilder(); for(int i=0;i<infos.size(); i++) { SegmentInfo info = infos.info(i); buf.append("[").append(info.name).append(",numDoc:").append(info.docCount).append(",numDel:").append(info.getDelCount()).append("]"); } return buf.toString(); } catch (Exception e) { return e.toString(); } } }
private void loadDeletedDocs() throws IOException { // NOTE: the bitvector is stored using the regular directory, not cfs if (hasDeletions(si)) { deletedDocs = new BitVector(directory(), si.getDelFileName()); assert si.getDelCount() == deletedDocs.count() : "delete count mismatch: info=" + si.getDelCount() + " vs BitVector=" + deletedDocs.count(); // Verify # deletes does not exceed maxDoc for this // segment: assert si.getDelCount() <= maxDoc() : "delete count mismatch: " + deletedDocs.count() + ") exceeds max doc (" + maxDoc() + ") for segment " + si.name; } else assert si.getDelCount() == 0; }
private void loadDeletedDocs() throws IOException { // NOTE: the bitvector is stored using the regular directory, not cfs if (hasDeletions(si)) { deletedDocs = new BitVector(directory(), si.getDelFileName()); assert si.getDelCount() == deletedDocs.count() : "delete count mismatch: info=" + si.getDelCount() + " vs BitVector=" + deletedDocs.count(); // Verify # deletes does not exceed maxDoc for this // segment: assert si.getDelCount() <= maxDoc() : "delete count mismatch: " + deletedDocs.count() + ") exceeds max doc (" + maxDoc() + ") for segment " + si.name; } else assert si.getDelCount() == 0; }
private OneMerge findOneSegmentToExpunge(SegmentInfos infos, int maxNumSegments) throws IOException { int expungeCandidate = -1; int maxDelCount = 0; for(int i = maxNumSegments - 1; i >= 0; i--) { SegmentInfo info = infos.info(i); int delCount = info.getDelCount(); if (delCount > maxDelCount) { expungeCandidate = i; maxDelCount = delCount; } } if (maxDelCount > 0) { return new OneMerge(Collections.singletonList(infos.info(expungeCandidate))); } return null; }
private OneMerge findOneSegmentToExpunge(SegmentInfos infos, int maxNumSegments) throws IOException { int expungeCandidate = -1; int maxDelCount = 0; for(int i = maxNumSegments - 1; i >= 0; i--) { SegmentInfo info = infos.info(i); int delCount = info.getDelCount(); if(delCount > maxDelCount) { expungeCandidate = i; maxDelCount = delCount; } } if(maxDelCount > 0) { return new OneMerge(infos.asList().subList(expungeCandidate, expungeCandidate + 1)); } return null; }
/** 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() throws IOException { int count; if (docWriter != null) count = docWriter.getNumDocsInRAM(); else count = 0; for (int i = 0; i < segmentInfos.size(); i++) { final SegmentInfo info = segmentInfos.info(i); count += info.docCount - info.getDelCount(); } return count; }
/** 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() throws IOException { int count; if (docWriter != null) count = docWriter.getNumDocsInRAM(); else count = 0; for (int i = 0; i < segmentInfos.size(); i++) { final SegmentInfo info = segmentInfos.info(i); count += info.docCount - info.getDelCount(); } return count; }
protected void commitChanges() throws IOException { if (deletedDocsDirty) { // re-write deleted si.advanceDelGen(); // We can write directly to the actual name (vs to a // .tmp & renaming it) because the file is not live // until segments file is written: deletedDocs.write(directory(), si.getDelFileName()); si.setDelCount(si.getDelCount()+pendingDeleteCount); pendingDeleteCount = 0; } if (undeleteAll && si.hasDeletions()) { si.clearDelGen(); si.setDelCount(0); } if (normsDirty) { // re-write norms si.setNumFields(fieldInfos.size()); Iterator it = norms.values().iterator(); while (it.hasNext()) { Norm norm = (Norm) it.next(); if (norm.dirty) { norm.reWrite(si); } } } deletedDocsDirty = false; normsDirty = false; undeleteAll = false; }
protected void commitChanges() throws IOException { if (deletedDocsDirty) { // re-write deleted si.advanceDelGen(); // We can write directly to the actual name (vs to a // .tmp & renaming it) because the file is not live // until segments file is written: deletedDocs.write(directory(), si.getDelFileName()); si.setDelCount(si.getDelCount()+pendingDeleteCount); pendingDeleteCount = 0; } if (undeleteAll && si.hasDeletions()) { si.clearDelGen(); si.setDelCount(0); } if (normsDirty) { // re-write norms si.setNumFields(fieldInfos.size()); Iterator it = norms.values().iterator(); while (it.hasNext()) { Norm norm = (Norm) it.next(); if (norm.dirty) { norm.reWrite(si); } } } deletedDocsDirty = false; normsDirty = false; undeleteAll = false; }
if(partialExpunge) { SegmentInfo info = infos.info(mergeStart); int delCount = info.getDelCount(); if(delCount > maxDelCount) { expungeCandidate = mergeStart;
int delCount = info.getDelCount(); if(delCount > maxDelCount)
toLoseDocCount = numDocs; if (reader.hasDeletions()) { if (reader.deletedDocs.count() != info.getDelCount()) { throw new RuntimeException("delete count mismatch: info=" + info.getDelCount() + " vs deletedDocs.count()=" + reader.deletedDocs.count()); if (info.docCount - numDocs != info.getDelCount()){ throw new RuntimeException("delete count mismatch: info=" + info.getDelCount() + " vs reader=" + (info.docCount - numDocs)); if (info.getDelCount() != 0) { throw new RuntimeException("delete count mismatch: info=" + info.getDelCount() + " vs reader=" + (info.docCount - numDocs));
toLoseDocCount = numDocs; if (reader.hasDeletions()) { if (reader.deletedDocs.count() != info.getDelCount()) { throw new RuntimeException("delete count mismatch: info=" + info.getDelCount() + " vs deletedDocs.count()=" + reader.deletedDocs.count()); if (info.docCount - numDocs != info.getDelCount()){ throw new RuntimeException("delete count mismatch: info=" + info.getDelCount() + " vs reader=" + (info.docCount - numDocs)); if (info.getDelCount() != 0) { throw new RuntimeException("delete count mismatch: info=" + info.getDelCount() + " vs reader=" + (info.docCount - numDocs));