return dup.slice(); } else { RowIndexSeekerV1 seeker = new RowIndexSeekerV1(CellComparatorImpl.COMPARATOR, decodingCtx); seeker.setCurrentBuffer(new SingleByteBuff(sourceAsBuffer)); List<Cell> kvs = new ArrayList<>(); kvs.add(seeker.getCell()); while (seeker.next()) { kvs.add(seeker.getCell());
@Override public int seekToKeyInBlock(Cell seekCell, boolean seekBefore) { previous.invalidate(); int index = binarySearch(seekCell, seekBefore); if (index < 0) { return HConstants.INDEX_KEY_MAGIC; // using optimized index key int offset = rowOffsets.getIntAfterPosition(index * Bytes.SIZEOF_INT); if (offset != 0) { decodeAtPosition(offset); + Bytes.toStringBinary(seekCell.getRowArray())); moveToPrevious(); return 1; moveToPrevious(); } else { return HConstants.INDEX_KEY_MAGIC; // using optimized index key decodeNext(); } else { break;
private int binarySearch(Cell seekCell, boolean seekBefore) { int low = 0; int high = rowNumber - 1; int mid = low + ((high - low) >> 1); int comp = 0; while (low <= high) { mid = low + ((high - low) >> 1); ByteBuffer row = getRow(mid); comp = compareRows(row, seekCell); if (comp < 0) { low = mid + 1; } else if (comp > 0) { high = mid - 1; } else { // key found if (seekBefore) { return mid - 1; } else { return mid; } } } // key not found. if (comp > 0) { return mid - 1; } else { return mid; } }
protected void decodeNext() { current.startOffset = currentBuffer.position(); long ll = currentBuffer.getLongAfterPosition(0); // Read top half as an int of key length and bottom int as value length current.keyLength = (int) (ll >> Integer.SIZE); current.valueLength = (int) (Bytes.MASK_FOR_LOWER_INT_IN_LONG ^ ll); currentBuffer.skip(Bytes.SIZEOF_LONG); // key part currentBuffer.asSubByteBuffer(currentBuffer.position(), current.keyLength, tmpPair); ByteBuffer key = tmpPair.getFirst().duplicate(); key.position(tmpPair.getSecond()).limit( tmpPair.getSecond() + current.keyLength); current.keyBuffer = key; currentBuffer.skip(current.keyLength); // value part current.valueOffset = currentBuffer.position(); currentBuffer.skip(current.valueLength); if (includesTags()) { decodeTags(); } if (includesMvcc()) { current.memstoreTS = ByteBuff.readVLong(currentBuffer); } else { current.memstoreTS = 0; } current.nextKvOffset = currentBuffer.position(); current.currentKey.setKey(current.keyBuffer, tmpPair.getSecond(), current.keyLength); }
protected void decodeFirst() { decodeNext(); previous.invalidate(); }
@Override public void rewind() { currentBuffer.rewind(); decodeFirst(); }
@Override public EncodedSeeker createSeeker(CellComparator comparator, HFileBlockDecodingContext decodingCtx) { return new RowIndexSeekerV1(comparator, decodingCtx); }
int cellBufSize = getCellBufSize(); long seqId = 0L; if (includesMvcc()) { seqId = memstoreTS;
protected void decodeNext() { current.startOffset = currentBuffer.position(); long ll = currentBuffer.getLongAfterPosition(0); // Read top half as an int of key length and bottom int as value length current.keyLength = (int) (ll >> Integer.SIZE); current.valueLength = (int) (Bytes.MASK_FOR_LOWER_INT_IN_LONG ^ ll); currentBuffer.skip(Bytes.SIZEOF_LONG); // key part currentBuffer.asSubByteBuffer(currentBuffer.position(), current.keyLength, tmpPair); ByteBuffer key = tmpPair.getFirst().duplicate(); key.position(tmpPair.getSecond()).limit( tmpPair.getSecond() + current.keyLength); current.keyBuffer = key; currentBuffer.skip(current.keyLength); // value part current.valueOffset = currentBuffer.position(); currentBuffer.skip(current.valueLength); if (includesTags()) { decodeTags(); } if (includesMvcc()) { current.memstoreTS = ByteBuff.readVLong(currentBuffer); } else { current.memstoreTS = 0; } current.nextKvOffset = currentBuffer.position(); current.currentKey.setKey(current.keyBuffer, tmpPair.getSecond(), current.keyLength); }
@Override public boolean next() { if (!currentBuffer.hasRemaining()) { return false; } decodeNext(); previous.invalidate(); return true; }
@Override public void setCurrentBuffer(ByteBuff buffer) { int onDiskSize = buffer.getInt(buffer.limit() - Bytes.SIZEOF_INT); // Data part ByteBuff dup = buffer.duplicate(); dup.position(buffer.position()); dup.limit(buffer.position() + onDiskSize); currentBuffer = dup.slice(); current.currentBuffer = currentBuffer; buffer.skip(onDiskSize); // Row offset rowNumber = buffer.getInt(); int totalRowOffsetsLength = Bytes.SIZEOF_INT * rowNumber; ByteBuff rowDup = buffer.duplicate(); rowDup.position(buffer.position()); rowDup.limit(buffer.position() + totalRowOffsetsLength); rowOffsets = rowDup.slice(); decodeFirst(); }
@Override public EncodedSeeker createSeeker(CellComparator comparator, HFileBlockDecodingContext decodingCtx) { return new RowIndexSeekerV1(comparator, decodingCtx); }
int cellBufSize = getCellBufSize(); long seqId = 0L; if (includesMvcc()) { seqId = memstoreTS;
return dup.slice(); } else { RowIndexSeekerV1 seeker = new RowIndexSeekerV1(CellComparatorImpl.COMPARATOR, decodingCtx); seeker.setCurrentBuffer(new SingleByteBuff(sourceAsBuffer)); List<Cell> kvs = new ArrayList<>(); kvs.add(seeker.getCell()); while (seeker.next()) { kvs.add(seeker.getCell());
@Override public int seekToKeyInBlock(Cell seekCell, boolean seekBefore) { previous.invalidate(); int index = binarySearch(seekCell, seekBefore); if (index < 0) { return HConstants.INDEX_KEY_MAGIC; // using optimized index key int offset = rowOffsets.getIntAfterPosition(index * Bytes.SIZEOF_INT); if (offset != 0) { decodeAtPosition(offset); + Bytes.toStringBinary(seekCell.getRowArray())); moveToPrevious(); return 1; moveToPrevious(); } else { return HConstants.INDEX_KEY_MAGIC; // using optimized index key decodeNext(); } else { break;
protected void decodeNext() { current.startOffset = currentBuffer.position(); long ll = currentBuffer.getLongAfterPosition(0); // Read top half as an int of key length and bottom int as value length current.keyLength = (int) (ll >> Integer.SIZE); current.valueLength = (int) (Bytes.MASK_FOR_LOWER_INT_IN_LONG ^ ll); currentBuffer.skip(Bytes.SIZEOF_LONG); // key part currentBuffer.asSubByteBuffer(currentBuffer.position(), current.keyLength, tmpPair); ByteBuffer key = tmpPair.getFirst().duplicate(); key.position(tmpPair.getSecond()).limit( tmpPair.getSecond() + current.keyLength); current.keyBuffer = key; currentBuffer.skip(current.keyLength); // value part current.valueOffset = currentBuffer.position(); currentBuffer.skip(current.valueLength); if (includesTags()) { decodeTags(); } if (includesMvcc()) { current.memstoreTS = ByteBuff.readVLong(currentBuffer); } else { current.memstoreTS = 0; } current.nextKvOffset = currentBuffer.position(); current.currentKey.setKey(current.keyBuffer, tmpPair.getSecond(), current.keyLength); }
private int binarySearch(Cell seekCell, boolean seekBefore) { int low = 0; int high = rowNumber - 1; int mid = (low + high) >>> 1; int comp = 0; while (low <= high) { mid = (low + high) >>> 1; ByteBuffer row = getRow(mid); comp = compareRows(row, seekCell); if (comp < 0) { low = mid + 1; } else if (comp > 0) { high = mid - 1; } else { // key found if (seekBefore) { return mid - 1; } else { return mid; } } } // key not found. if (comp > 0) { return mid - 1; } else { return mid; } }
protected void decodeAtPosition(int position) { currentBuffer.position(position); decodeNext(); previous.invalidate(); }
@Override public void rewind() { currentBuffer.rewind(); decodeFirst(); }
@Override public EncodedSeeker createSeeker(CellComparator comparator, HFileBlockDecodingContext decodingCtx) { return new RowIndexSeekerV1(comparator, decodingCtx); }