hbase-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Corgan (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HBASE-10771) Primitive type put/get APIs in ByteRange
Date Thu, 01 May 2014 05:09:33 GMT

    [ https://issues.apache.org/jira/browse/HBASE-10771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13986353#comment-13986353
] 

Matt Corgan commented on HBASE-10771:
-------------------------------------

Looks good to me.  It looks like the encoding matches the LittleEndian representation from
Bits.java, so a ByteBuffer implementation should be able to call straight through to its internal
putInt method if we deem that's faster than writing 4 individual bytes to the ByteBuffer.

putInt from java.io.Bits.java{code}
    private static byte int3(int x) { return (byte)(x >> 24); }
    private static byte int2(int x) { return (byte)(x >> 16); }
    private static byte int1(int x) { return (byte)(x >>  8); }
    private static byte int0(int x) { return (byte)(x      ); }

    static void putIntL(ByteBuffer bb, int bi, int x) {
        bb._put(bi + 3, int3(x));
        bb._put(bi + 2, int2(x));
        bb._put(bi + 1, int1(x));
        bb._put(bi    , int0(x));
    }
{code}

putInt from hbase's Bytes.java{code}
  public static int putInt(byte[] bytes, int offset, int val) {
    if (bytes.length - offset < SIZEOF_INT) {
      throw new IllegalArgumentException("Not enough room to put an int at"
          + " offset " + offset + " in a " + bytes.length + " byte array");
    }
    for(int i= offset + 3; i > offset; i--) {
      bytes[i] = (byte) val;
      val >>>= 8;
    }
    bytes[offset] = (byte) val;
    return offset + SIZEOF_INT;
  }{code}

Might be interesting to add a test to confirm that.  You could write to an array using a ByteRange
and then ByteBuffer.wrap(br.getArray()) and read the values back.

> Primitive type put/get APIs in ByteRange 
> -----------------------------------------
>
>                 Key: HBASE-10771
>                 URL: https://issues.apache.org/jira/browse/HBASE-10771
>             Project: HBase
>          Issue Type: Improvement
>            Reporter: Anoop Sam John
>            Assignee: Anoop Sam John
>             Fix For: 0.99.0
>
>         Attachments: HBASE-10771.patch, HBASE-10771_V2.patch, HBASE-10771_V3.patch
>
>
> While doing HBASE-10713 I came across the need to write int/long (and read also) from
a ByteRange.  CellBlocks are backed by ByteRange. So we can add such APIs.
> Also as per HBASE-10750  we return a ByteRange from MSLAB and also discussion under HBASE-10191
suggest we can have BR backed HFileBlocks etc.  



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message