[
https://issues.apache.org/jira/browse/HBASE-10771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13951738#comment-13951738
]
Matt Corgan commented on HBASE-10771:
-------------------------------------
I'm not sure what the best solution is either. I introduced ByteRange to
* wrap cumbersome/fragile array/offset/length logic into a single place for
byte[] as String does to char[]
* give us native unsigned comparison (it's kinda wild that hbase doesn't have a
unified abstraction for this)
* add a potentially faster .equals implementation via cached hashCode comparison
* make this wrapper object reusable object for highest performance (unlike
ByteBuffer)
I only intended it to stay simple and am a little worried that creating too
many subclasses could hurt its performance in critical paths, but we started
talking about using it for more things. I hadn't envisioned adding many
methods to the interface, but still thinking on it and having a hard time
coming up with negatives. While a hasArray() method could probably be replaced
with "instanceof" and casting by implementations and utilities, it probably
wouldn't hurt to put it in the interface.
It wasn't the original intention, but ByteRange could be a nice abstraction for
moving (or avoiding moving) bytes between ByteBuffers and byte[]'s. Like in
the seek method when you want to compare a byte[] key to some bytes in the
block cache, the BR implementation can decide whether to do a byte-by-byte
comparison behind the scenes (for off-heap blocks) or to use Unsafe to do full
word comparisons when both BRs hasArray(), or even copy the off-heap bytes on
heap for a comparison. Seems like we should have this layer of abstraction -
it gains us really clean code without much of a performance hit. I agree it
feels weird to add such basic functionality, but maybe it's just weird that
it's not there already.
> 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
>
>
> 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)