You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Harjit Singh (Jira)" <ji...@apache.org> on 2021/08/27 21:45:00 UTC

[jira] [Commented] (HBASE-25576) Should not use a byte array as a key of HashMap or an element of HashSet

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

Harjit Singh commented on HBASE-25576:
--------------------------------------

Is somebody working on this ? I can work on this.

 

> Should not use a byte array as a key of HashMap or an element of HashSet
> ------------------------------------------------------------------------
>
>                 Key: HBASE-25576
>                 URL: https://issues.apache.org/jira/browse/HBASE-25576
>             Project: HBase
>          Issue Type: Bug
>            Reporter: Toshihiro Suzuki
>            Priority: Major
>              Labels: beginner
>
> I sometimes face the code where we use a byte array as a key of HashMap (ConcurrentHashMap) or an element of HashSet, which could cause very confusing bugs.
> The following code is an example where we use a byte array as a key of HashMap:
> https://github.com/apache/hbase/blob/326835e8372cc83092e0ec127650438ff153476a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceIdAccounting.java#L94
> In Java, we can't use a byte array as a key of HashMap or an element of HashSet directly. One solution for it is to use TreeMap (ConcurrentSkipListMap) or TreeSet (ConcurrentSkipListSet) with Bytes.BYTES_COMPARATOR instead of HashMap and HashSet as follows:
> {code}
> Map<byte[], String> map1 = new TreeMap<>(Bytes.BYTES_COMPARATOR);
> Map<byte[], String> map2 = new ConcurrentSkipListMap<>(Bytes.BYTES_COMPARATOR);
> Set<byte[]> set1 = new TreeSet<>(Bytes.BYTES_COMPARATOR);
> Set<byte[]> set2 = new ConcurrentSkipListSet<>(Bytes.BYTES_COMPARATOR);
> {code}
> We should fix the existing ones in this Jira.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)