You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by anil gupta <an...@gmail.com> on 2013/10/10 08:56:55 UTC

Thread safety of Bytes.compareTo(byte[] left, byte[] right)

Hi All,

I have to use
 *Bytes.compareTo<http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/util/Bytes.html#compareTo%28byte[],%20byte[]%29>
*(byte[] left, byte[] right) method in one of my coprocessor(HBASE-7474)
stuff. Basically, i want to do comparison on the basis of Lexicographical
order of byte[] of cell value. Similar to BinaryComparator in HBase.

Since, *Bytes.compareTo<http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/util/Bytes.html#compareTo%28byte[],%20byte[]%29>
*(byte[] left, byte[] right) is static method and it doesnt have any
synchronization. How do we guarantee that this method is thread safe? I am
curious to know is it safe to use the static method on
RegionServer(multithreaded environment)?

Please correct me if i stated something wrong above.

-- 
Thanks & Regards,
Anil Gupta

Re: Thread safety of Bytes.compareTo(byte[] left, byte[] right)

Posted by anil gupta <an...@gmail.com>.
@Adrien,
Ok, got it. So, it seems like every read requests is a separated thread in
itself. Right?
Thanks for your reply.


On Thu, Oct 10, 2013 at 5:59 AM, Adrien Mogenet <ad...@gmail.com>wrote:

> Hi,
>
> A static method does not necessary mean that this could lead to a
> thread-safety issue. In that case, there is no shared resources between
> threads and thus... nothing to protect.
>
>
> On Thu, Oct 10, 2013 at 8:56 AM, anil gupta <an...@gmail.com> wrote:
>
> > Hi All,
> >
> > I have to use
> >  *Bytes.compareTo<
> >
> http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/util/Bytes.html#compareTo%28byte[],%20byte[]%29
> > >
> > *(byte[] left, byte[] right) method in one of my coprocessor(HBASE-7474)
> > stuff. Basically, i want to do comparison on the basis of Lexicographical
> > order of byte[] of cell value. Similar to BinaryComparator in HBase.
> >
> > Since, *Bytes.compareTo<
> >
> http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/util/Bytes.html#compareTo%28byte[],%20byte[]%29
> > >
> > *(byte[] left, byte[] right) is static method and it doesnt have any
> > synchronization. How do we guarantee that this method is thread safe? I
> am
> > curious to know is it safe to use the static method on
> > RegionServer(multithreaded environment)?
> >
> > Please correct me if i stated something wrong above.
> >
> > --
> > Thanks & Regards,
> > Anil Gupta
> >
>
>
>
> --
> Adrien Mogenet
> http://www.borntosegfault.com
>



-- 
Thanks & Regards,
Anil Gupta

Re: Thread safety of Bytes.compareTo(byte[] left, byte[] right)

Posted by Adrien Mogenet <ad...@gmail.com>.
Hi,

A static method does not necessary mean that this could lead to a
thread-safety issue. In that case, there is no shared resources between
threads and thus... nothing to protect.


On Thu, Oct 10, 2013 at 8:56 AM, anil gupta <an...@gmail.com> wrote:

> Hi All,
>
> I have to use
>  *Bytes.compareTo<
> http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/util/Bytes.html#compareTo%28byte[],%20byte[]%29
> >
> *(byte[] left, byte[] right) method in one of my coprocessor(HBASE-7474)
> stuff. Basically, i want to do comparison on the basis of Lexicographical
> order of byte[] of cell value. Similar to BinaryComparator in HBase.
>
> Since, *Bytes.compareTo<
> http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/util/Bytes.html#compareTo%28byte[],%20byte[]%29
> >
> *(byte[] left, byte[] right) is static method and it doesnt have any
> synchronization. How do we guarantee that this method is thread safe? I am
> curious to know is it safe to use the static method on
> RegionServer(multithreaded environment)?
>
> Please correct me if i stated something wrong above.
>
> --
> Thanks & Regards,
> Anil Gupta
>



-- 
Adrien Mogenet
http://www.borntosegfault.com