@Override public Bits readLiveDocs(Directory dir, SegmentInfoPerCommit info, IOContext context) throws IOException { assert info.hasDeletions(); BytesRef scratch = new BytesRef(); CharsRef scratchUTF16 = new CharsRef(); String fileName = IndexFileNames.fileNameFromGeneration(info.info.name, LIVEDOCS_EXTENSION, info.getDelGen()); IndexInput in = null; boolean success = false; try { in = dir.openInput(fileName, context); SimpleTextUtil.readLine(in, scratch); assert StringHelper.startsWith(scratch, SIZE); int size = parseIntAt(scratch, SIZE.length, scratchUTF16); BitSet bits = new BitSet(size); SimpleTextUtil.readLine(in, scratch); while (!scratch.equals(END)) { assert StringHelper.startsWith(scratch, DOC); int docid = parseIntAt(scratch, DOC.length, scratchUTF16); bits.set(docid); SimpleTextUtil.readLine(in, scratch); } success = true; return new SimpleTextBits(bits, size); } finally { if (success) { IOUtils.close(in); } else { IOUtils.closeWhileHandlingException(in); } } }
@Override public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfoPerCommit info, int newDelCount, IOContext context) throws IOException { BitSet set = ((SimpleTextBits) bits).bits; int size = bits.length(); BytesRef scratch = new BytesRef(); String fileName = IndexFileNames.fileNameFromGeneration(info.info.name, LIVEDOCS_EXTENSION, info.getNextDelGen()); IndexOutput out = null; boolean success = false; try { out = dir.createOutput(fileName, context); SimpleTextUtil.write(out, SIZE); SimpleTextUtil.write(out, Integer.toString(size), scratch); SimpleTextUtil.writeNewline(out); for (int i = set.nextSetBit(0); i >= 0; i=set.nextSetBit(i + 1)) { SimpleTextUtil.write(out, DOC); SimpleTextUtil.write(out, Integer.toString(i), scratch); SimpleTextUtil.writeNewline(out); } SimpleTextUtil.write(out, END); SimpleTextUtil.writeNewline(out); success = true; } finally { if (success) { IOUtils.close(out); } else { IOUtils.closeWhileHandlingException(out); } } }
@Override public Bits readLiveDocs(Directory dir, SegmentInfoPerCommit info, IOContext context) throws IOException { String filename = IndexFileNames.fileNameFromGeneration(info.info.name, DELETES_EXTENSION, info.getDelGen()); final BitVector liveDocs = new BitVector(dir, filename, context); assert liveDocs.count() == info.info.getDocCount() - info.getDelCount(): "liveDocs.count()=" + liveDocs.count() + " info.docCount=" + info.info.getDocCount() + " info.getDelCount()=" + info.getDelCount(); assert liveDocs.length() == info.info.getDocCount(); return liveDocs; }
@Override public void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfoPerCommit info, int newDelCount, IOContext context) throws IOException { String filename = IndexFileNames.fileNameFromGeneration(info.info.name, DELETES_EXTENSION, info.getNextDelGen()); final BitVector liveDocs = (BitVector) bits; assert liveDocs.count() == info.info.getDocCount() - info.getDelCount() - newDelCount; assert liveDocs.length() == info.info.getDocCount(); liveDocs.write(dir, filename, context); }
private Collection<SegmentKey> getSegmentKeys() throws IOException { List<SegmentKey> keys = new ArrayList<SegmentKey>(); SegmentInfos segmentInfos = new SegmentInfos(); segmentInfos.read(_directory, _indexCommit.getSegmentsFileName()); for (SegmentInfoPerCommit segmentInfoPerCommit : segmentInfos) { String name = segmentInfoPerCommit.info.name; String id = getId(segmentInfoPerCommit.info); keys.add(new SegmentKey(name, id)); } return keys; }
MergeStatus(OneMerge oneMerge, Directory directory, long size, List<SegmentInfoPerCommit> segments) { _id = UUID.randomUUID().toString(); _directory = directory; _start = System.nanoTime(); _size = size; _oneMerge = oneMerge; _segments = segments; }
public void initialize(BlurInputSplit blurInputSplit, Configuration configuration) throws IOException { if (_setup) { return; } _setup = true; _table = blurInputSplit.getTable(); Path localCachePath = BlurInputFormat.getLocalCachePath(configuration); LOG.info("Local cache path [{0}]", localCachePath); _directory = BlurInputFormat.getDirectory(configuration, _table.toString(), blurInputSplit.getDir()); SegmentInfoPerCommit commit = segmentInfosRead(_directory, blurInputSplit.getSegmentsName(), blurInputSplit.getSegmentInfoName()); SegmentInfo segmentInfo = commit.info; if (localCachePath != null) { _readingDirectory = copyFilesLocally(configuration, _directory, _table.toString(), blurInputSplit.getDir(), localCachePath, commit.files(), blurInputSplit.getSegmentInfoName()); } else { _readingDirectory = _directory; } Blur024Codec blur024Codec = new Blur024Codec(); IOContext iocontext = IOContext.READ; String segmentName = segmentInfo.name; FieldInfos fieldInfos = blur024Codec.fieldInfosFormat().getFieldInfosReader() .read(_readingDirectory, segmentName, iocontext); if (commit.getDelCount() > 0) { _liveDocs = blur024Codec.liveDocsFormat().readLiveDocs(_readingDirectory, commit, iocontext); } _fieldsReader = blur024Codec.storedFieldsFormat().fieldsReader(_readingDirectory, segmentInfo, fieldInfos, iocontext); _maxDoc = commit.info.getDocCount(); }
@Override public MergeSpecification findForcedMerges(SegmentInfos segmentInfos, int maxSegmentCount, Map<SegmentInfoPerCommit,Boolean> segmentsToOptimize) throws CorruptIndexException, IOException { System.err.println("findForcedMerges"); return null; }
/** Read live docs bits. */ public abstract Bits readLiveDocs(Directory dir, SegmentInfoPerCommit info, IOContext context) throws IOException;
private SegmentInfoPerCommit segmentInfosRead(Directory directory, String segmentFileName, String segmentInfoName) throws IOException { boolean success = false; ChecksumIndexInput input = new ChecksumIndexInput(directory.openInput(segmentFileName, IOContext.READ)); try { final int format = input.readInt(); if (format == CodecUtil.CODEC_MAGIC) { // 4.0+ CodecUtil.checkHeaderNoMagic(input, "segments", SegmentInfos.VERSION_40, SegmentInfos.VERSION_40); input.readLong();// read version input.readInt(); // read counter int numSegments = input.readInt(); if (numSegments < 0) { throw new CorruptIndexException("invalid segment count: " + numSegments + " (resource: " + input + ")"); } for (int seg = 0; seg < numSegments; seg++) { String segName = input.readString(); Codec codec = Codec.forName(input.readString()); SegmentInfo info = codec.segmentInfoFormat().getSegmentInfoReader().read(directory, segName, IOContext.READ); info.setCodec(codec); long delGen = input.readLong(); int delCount = input.readInt(); if (delCount < 0 || delCount > info.getDocCount()) { throw new CorruptIndexException("invalid deletion count: " + delCount + " (resource: " + input + ")"); } if (segName.equals(segmentInfoName)) { success = true; return new SegmentInfoPerCommit(info, delCount, delGen); } } } else { throw new IOException("Legacy Infos not supported for dir [" + directory + "]."); } throw new IOException("Segment [" + segmentInfoName + "] nout found in dir [" + directory + "]"); } finally { if (!success) { IOUtils.closeWhileHandlingException(input); } else { input.close(); } } }
@Override public boolean useCompoundFile(SegmentInfos segments, SegmentInfoPerCommit newSegment) { return useCompoundFile; }
/** Persist live docs bits. Use {@link * SegmentInfoPerCommit#getNextDelGen} to determine the * generation of the deletes file you should write to. */ public abstract void writeLiveDocs(MutableBits bits, Directory dir, SegmentInfoPerCommit info, int newDelCount, IOContext context) throws IOException;