Search in sources :

Example 1 with HFileBlockDefaultEncodingContext

use of org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext in project hbase by apache.

the class TestHFileDataBlockEncoder method writeBlock.

private void writeBlock(List<Cell> kvs, HFileContext fileContext, boolean useTags) throws IOException {
    HFileBlockEncodingContext context = new HFileBlockDefaultEncodingContext(blockEncoder.getDataBlockEncoding(), HConstants.HFILEBLOCK_DUMMY_HEADER, fileContext);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(HConstants.HFILEBLOCK_DUMMY_HEADER);
    DataOutputStream dos = new DataOutputStream(baos);
    blockEncoder.startBlockEncoding(context, dos);
    for (Cell kv : kvs) {
        blockEncoder.encode(kv, context, dos);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) HFileBlockDefaultEncodingContext(org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext) HFileBlockEncodingContext(org.apache.hadoop.hbase.io.encoding.HFileBlockEncodingContext) ByteArrayOutputStream(org.apache.hadoop.hbase.io.ByteArrayOutputStream) Cell(org.apache.hadoop.hbase.Cell)

Example 2 with HFileBlockDefaultEncodingContext

use of org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext in project hbase by apache.

the class TestHFileDataBlockEncoder method createBlockOnDisk.

private HFileBlock createBlockOnDisk(List<KeyValue> kvs, HFileBlock block, boolean useTags) throws IOException {
    int size;
    HFileBlockEncodingContext context = new HFileBlockDefaultEncodingContext(blockEncoder.getDataBlockEncoding(), HConstants.HFILEBLOCK_DUMMY_HEADER, block.getHFileContext());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(block.getDummyHeaderForVersion());
    DataOutputStream dos = new DataOutputStream(baos);
    blockEncoder.startBlockEncoding(context, dos);
    for (KeyValue kv : kvs) {
        blockEncoder.encode(kv, context, dos);
    }
    blockEncoder.endBlockEncoding(context, dos, baos.getBuffer(), BlockType.DATA);
    byte[] encodedBytes = baos.toByteArray();
    size = encodedBytes.length - block.getDummyHeaderForVersion().length;
    return new HFileBlock(context.getBlockType(), size, size, -1, ByteBuffer.wrap(encodedBytes), HFileBlock.FILL_HEADER, 0, block.getOnDiskDataSizeWithHeader(), -1, block.getHFileContext());
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) DataOutputStream(java.io.DataOutputStream) HFileBlockDefaultEncodingContext(org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext) HFileBlockEncodingContext(org.apache.hadoop.hbase.io.encoding.HFileBlockEncodingContext) ByteArrayOutputStream(org.apache.hadoop.hbase.io.ByteArrayOutputStream)

Example 3 with HFileBlockDefaultEncodingContext

use of org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext in project hbase by apache.

the class TestHFileDataBlockEncoder method writeBlock.

private void writeBlock(Configuration conf, List<Cell> kvs, HFileContext fileContext, boolean useTags) throws IOException {
    HFileBlockEncodingContext context = new HFileBlockDefaultEncodingContext(conf, blockEncoder.getDataBlockEncoding(), HConstants.HFILEBLOCK_DUMMY_HEADER, fileContext);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(HConstants.HFILEBLOCK_DUMMY_HEADER);
    DataOutputStream dos = new DataOutputStream(baos);
    blockEncoder.startBlockEncoding(context, dos);
    for (Cell kv : kvs) {
        blockEncoder.encode(kv, context, dos);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) HFileBlockDefaultEncodingContext(org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext) HFileBlockEncodingContext(org.apache.hadoop.hbase.io.encoding.HFileBlockEncodingContext) ByteArrayOutputStream(org.apache.hadoop.hbase.io.ByteArrayOutputStream) Cell(org.apache.hadoop.hbase.Cell)

Example 4 with HFileBlockDefaultEncodingContext

use of org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext in project hbase by apache.

the class PrefixTreeCodec method startBlockEncoding.

@Override
public void startBlockEncoding(HFileBlockEncodingContext blkEncodingCtx, DataOutputStream out) throws IOException {
    if (blkEncodingCtx.getClass() != HFileBlockDefaultEncodingContext.class) {
        throw new IOException(this.getClass().getName() + " only accepts " + HFileBlockDefaultEncodingContext.class.getName() + " as the " + "encoding context.");
    }
    HFileBlockDefaultEncodingContext encodingCtx = (HFileBlockDefaultEncodingContext) blkEncodingCtx;
    encodingCtx.prepareEncoding(out);
    PrefixTreeEncoder builder = EncoderFactory.checkOut(out, encodingCtx.getHFileContext().isIncludesMvcc());
    PrefixTreeEncodingState state = new PrefixTreeEncodingState();
    state.builder = builder;
    blkEncodingCtx.setEncodingState(state);
}
Also used : PrefixTreeEncoder(org.apache.hadoop.hbase.codec.prefixtree.encode.PrefixTreeEncoder) HFileBlockDefaultEncodingContext(org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext) IOException(java.io.IOException)

Example 5 with HFileBlockDefaultEncodingContext

use of org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext in project hbase by apache.

the class NoOpDataBlockEncoder method startBlockEncoding.

@Override
public void startBlockEncoding(HFileBlockEncodingContext blkEncodingCtx, DataOutputStream out) throws IOException {
    if (blkEncodingCtx.getClass() != HFileBlockDefaultEncodingContext.class) {
        throw new IOException(this.getClass().getName() + " only accepts " + HFileBlockDefaultEncodingContext.class.getName() + " as the " + "encoding context.");
    }
    HFileBlockDefaultEncodingContext encodingCtx = (HFileBlockDefaultEncodingContext) blkEncodingCtx;
    encodingCtx.prepareEncoding(out);
    NoneEncoder encoder = new NoneEncoder(out, encodingCtx);
    NoneEncodingState state = new NoneEncodingState();
    state.encoder = encoder;
    blkEncodingCtx.setEncodingState(state);
}
Also used : HFileBlockDefaultEncodingContext(org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext) IOException(java.io.IOException) NoneEncoder(org.apache.hadoop.hbase.io.encoding.NoneEncoder)

Aggregations

HFileBlockDefaultEncodingContext (org.apache.hadoop.hbase.io.encoding.HFileBlockDefaultEncodingContext)6 DataOutputStream (java.io.DataOutputStream)4 ByteArrayOutputStream (org.apache.hadoop.hbase.io.ByteArrayOutputStream)4 HFileBlockEncodingContext (org.apache.hadoop.hbase.io.encoding.HFileBlockEncodingContext)4 IOException (java.io.IOException)2 Cell (org.apache.hadoop.hbase.Cell)2 KeyValue (org.apache.hadoop.hbase.KeyValue)2 PrefixTreeEncoder (org.apache.hadoop.hbase.codec.prefixtree.encode.PrefixTreeEncoder)1 NoneEncoder (org.apache.hadoop.hbase.io.encoding.NoneEncoder)1