Search in sources :

Example 1 with CellSearcher

use of org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher in project hbase by apache.

the class PrefixTreeCodec method decodeKeyValues.

/**
   * I don't think this method is called during normal HBase operation, so efficiency is not
   * important.
   */
public ByteBuffer decodeKeyValues(DataInputStream source, int allocateHeaderLength, int skipLastBytes, HFileBlockDecodingContext decodingCtx) throws IOException {
    // waste
    ByteBuffer sourceAsBuffer = ByteBufferUtils.drainInputStreamToBuffer(source);
    sourceAsBuffer.mark();
    PrefixTreeBlockMeta blockMeta = new PrefixTreeBlockMeta(new SingleByteBuff(sourceAsBuffer));
    sourceAsBuffer.rewind();
    int numV1BytesWithHeader = allocateHeaderLength + blockMeta.getNumKeyValueBytes();
    byte[] keyValueBytesWithHeader = new byte[numV1BytesWithHeader];
    ByteBuffer result = ByteBuffer.wrap(keyValueBytesWithHeader);
    result.rewind();
    CellSearcher searcher = null;
    try {
        boolean includesMvcc = decodingCtx.getHFileContext().isIncludesMvcc();
        searcher = DecoderFactory.checkOut(new SingleByteBuff(sourceAsBuffer), includesMvcc);
        while (searcher.advance()) {
            KeyValue currentCell = KeyValueUtil.copyToNewKeyValue(searcher.current());
            // needs to be modified for DirectByteBuffers. no existing methods to
            // write VLongs to byte[]
            int offset = result.arrayOffset() + result.position();
            System.arraycopy(currentCell.getBuffer(), currentCell.getOffset(), result.array(), offset, currentCell.getLength());
            int keyValueLength = KeyValueUtil.length(currentCell);
            ByteBufferUtils.skip(result, keyValueLength);
            offset += keyValueLength;
            if (includesMvcc) {
                ByteBufferUtils.writeVLong(result, currentCell.getSequenceId());
            }
        }
        //make it appear as if we were appending
        result.position(result.limit());
        return result;
    } finally {
        DecoderFactory.checkIn(searcher);
    }
}
Also used : CellSearcher(org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher) KeyValue(org.apache.hadoop.hbase.KeyValue) SingleByteBuff(org.apache.hadoop.hbase.nio.SingleByteBuff) ByteBuffer(java.nio.ByteBuffer)

Example 2 with CellSearcher

use of org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher in project hbase by apache.

the class TestPrefixTreeSearcher method testRandomSeekMisses.

@Test
public void testRandomSeekMisses() throws IOException {
    CellSearcher searcher = null;
    List<Integer> rowStartIndexes = rows.getRowStartIndexes();
    try {
        searcher = DecoderFactory.checkOut(block, true);
        //test both the positionAtOrBefore and positionAtOrAfter methods
        for (boolean beforeVsAfterOnMiss : new boolean[] { true, false }) {
            for (int i = 0; i < rows.getInputs().size(); ++i) {
                KeyValue kv = rows.getInputs().get(i);
                //nextRow
                Cell inputNextRow = CellUtil.createFirstOnNextRow(kv);
                CellScannerPosition position = beforeVsAfterOnMiss ? searcher.positionAtOrBefore(inputNextRow) : searcher.positionAtOrAfter(inputNextRow);
                boolean isFirstInRow = rowStartIndexes.contains(i);
                if (isFirstInRow) {
                    int rowIndex = rowStartIndexes.indexOf(i);
                    if (rowIndex < rowStartIndexes.size() - 1) {
                        if (beforeVsAfterOnMiss) {
                            Assert.assertEquals(CellScannerPosition.BEFORE, position);
                        } else {
                            Assert.assertEquals(CellScannerPosition.AFTER, position);
                        }
                        int expectedInputIndex = beforeVsAfterOnMiss ? rowStartIndexes.get(rowIndex + 1) - 1 : rowStartIndexes.get(rowIndex + 1);
                        Assert.assertEquals(rows.getInputs().get(expectedInputIndex), searcher.current());
                    }
                }
                //previous KV
                KeyValue inputPreviousKv = KeyValueUtil.previousKey(kv);
                boolean hit = searcher.positionAt(inputPreviousKv);
                Assert.assertFalse(hit);
                position = searcher.positionAtOrAfter(inputPreviousKv);
                if (CollectionUtils.isLastIndex(rows.getInputs(), i)) {
                    Assert.assertTrue(CellScannerPosition.AFTER_LAST == position);
                } else {
                    Assert.assertTrue(CellScannerPosition.AFTER == position);
                    /*
             * TODO: why i+1 instead of i?
             */
                    Assert.assertEquals(rows.getInputs().get(i + 1), searcher.current());
                }
            }
        }
    } finally {
        DecoderFactory.checkIn(searcher);
    }
}
Also used : CellSearcher(org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher) KeyValue(org.apache.hadoop.hbase.KeyValue) CellScannerPosition(org.apache.hadoop.hbase.codec.prefixtree.scanner.CellScannerPosition) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 3 with CellSearcher

use of org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher in project hbase by apache.

the class TestPrefixTreeSearcher method testRandomSeekIndividualAssertions.

@Test
public void testRandomSeekIndividualAssertions() throws IOException {
    CellSearcher searcher = null;
    try {
        searcher = DecoderFactory.checkOut(block, true);
        rows.individualSearcherAssertions(searcher);
    } finally {
        DecoderFactory.checkIn(searcher);
    }
}
Also used : CellSearcher(org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher) Test(org.junit.Test)

Example 4 with CellSearcher

use of org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher in project hbase by apache.

the class TestPrefixTreeSearcher method testRandomSeekHits.

@Test
public void testRandomSeekHits() throws IOException {
    CellSearcher searcher = null;
    try {
        searcher = DecoderFactory.checkOut(block, true);
        for (KeyValue kv : rows.getInputs()) {
            boolean hit = searcher.positionAt(kv);
            Assert.assertTrue(hit);
            Cell foundKv = searcher.current();
            Assert.assertTrue(CellUtil.equals(kv, foundKv));
        }
    } finally {
        DecoderFactory.checkIn(searcher);
    }
}
Also used : CellSearcher(org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher) KeyValue(org.apache.hadoop.hbase.KeyValue) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 5 with CellSearcher

use of org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher in project hbase by apache.

the class TestPrefixTreeSearcher method testScanBackwards.

@Test
public void testScanBackwards() throws IOException {
    CellSearcher searcher = null;
    try {
        searcher = DecoderFactory.checkOut(block, true);
        searcher.positionAfterLastCell();
        int i = -1;
        while (searcher.previous()) {
            ++i;
            int oppositeIndex = rows.getInputs().size() - i - 1;
            KeyValue inputKv = rows.getInputs().get(oppositeIndex);
            KeyValue outputKv = KeyValueUtil.copyToNewKeyValue(searcher.current());
            Assert.assertEquals(inputKv, outputKv);
        }
        Assert.assertEquals(rows.getInputs().size(), i + 1);
    } finally {
        DecoderFactory.checkIn(searcher);
    }
}
Also used : CellSearcher(org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher) KeyValue(org.apache.hadoop.hbase.KeyValue) Test(org.junit.Test)

Aggregations

CellSearcher (org.apache.hadoop.hbase.codec.prefixtree.scanner.CellSearcher)7 KeyValue (org.apache.hadoop.hbase.KeyValue)6 Test (org.junit.Test)6 Cell (org.apache.hadoop.hbase.Cell)3 CellScannerPosition (org.apache.hadoop.hbase.codec.prefixtree.scanner.CellScannerPosition)2 ByteBuffer (java.nio.ByteBuffer)1 TestRowDataSearchWithPrefix (org.apache.hadoop.hbase.codec.prefixtree.row.data.TestRowDataSearchWithPrefix)1 SingleByteBuff (org.apache.hadoop.hbase.nio.SingleByteBuff)1