You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Kristoffer Sjögren <st...@gmail.com> on 2013/08/29 00:14:59 UTC

RowLocks

Hi

About the internals of locking a row in hbase.

Does hbase row locks map one-to-one with a locks in zookeeper or are there
any optimizations based on the fact that a row only exist on a single
machine?

Cheers,
-Kristoffer

Re: RowLocks

Posted by Jean-Marc Spaggiari <je...@spaggiari.org>.
Worst case you can use ZK to do the same if you only need that from time to
time?
Le 2013-08-28 18:19, "Ted Yu" <yu...@gmail.com> a écrit :

> RowLock API has been removed in 0.96.
>
> Can you tell us your use case ?
>
>
> On Wed, Aug 28, 2013 at 3:14 PM, Kristoffer Sjögren <stoffe@gmail.com
> >wrote:
>
> > Hi
> >
> > About the internals of locking a row in hbase.
> >
> > Does hbase row locks map one-to-one with a locks in zookeeper or are
> there
> > any optimizations based on the fact that a row only exist on a single
> > machine?
> >
> > Cheers,
> > -Kristoffer
> >
>

Re: RowLocks

Posted by Chris Perluss <tr...@gmail.com>.
You could add an "isLocked" column to your row. When you want to lock or
update your row then use checkAndPut and check that "isLocked"=0.  When
unlocking your row then checkAndPut that "isLocked"=1.  You will have
effectively locked the row for the purposes of your application without
affecting HBase internal workings like performing a region split.

Chris
I want a distributed lock condition for doing certain operations that may
or may not be unrelated to hbase.


On Thu, Aug 29, 2013 at 12:18 AM, Ted Yu <yu...@gmail.com> wrote:

> RowLock API has been removed in 0.96.
>
> Can you tell us your use case ?
>
>
> On Wed, Aug 28, 2013 at 3:14 PM, Kristoffer Sjögren <stoffe@gmail.com
> >wrote:
>
> > Hi
> >
> > About the internals of locking a row in hbase.
> >
> > Does hbase row locks map one-to-one with a locks in zookeeper or are
> there
> > any optimizations based on the fact that a row only exist on a single
> > machine?
> >
> > Cheers,
> > -Kristoffer
> >
>

Re: RowLocks

Posted by Kristoffer Sjögren <st...@gmail.com>.
I want a distributed lock condition for doing certain operations that may
or may not be unrelated to hbase.


On Thu, Aug 29, 2013 at 12:18 AM, Ted Yu <yu...@gmail.com> wrote:

> RowLock API has been removed in 0.96.
>
> Can you tell us your use case ?
>
>
> On Wed, Aug 28, 2013 at 3:14 PM, Kristoffer Sjögren <stoffe@gmail.com
> >wrote:
>
> > Hi
> >
> > About the internals of locking a row in hbase.
> >
> > Does hbase row locks map one-to-one with a locks in zookeeper or are
> there
> > any optimizations based on the fact that a row only exist on a single
> > machine?
> >
> > Cheers,
> > -Kristoffer
> >
>

Re: RowLocks

Posted by Michael Segel <mi...@hotmail.com>.
Thanks for the update. 

Actually they worked ok for what they were.  IMHO they should never had been made public because they aren't RLL that people think of as part of transactions and isolation levels found in RDBMSs.

Had me worried there for a sec... 

Thx
On Aug 28, 2013, at 11:22 PM, lars hofhansl <la...@apache.org> wrote:

> Specifically the API has been removed because it had never actually worked correctly.
> 
> 
> Rowlocks are used by RegionServers for intra-region operations.
> As such they are ephemeral, in-memory constructs, that cannot reliably outlive a single RPC request.
> The HTable rowlock API allowed you to create a rowlocks and hold it over multiple RPCs, which would break if f.e. a region is moved or split.
> 
> -- Lars
> ________________________________
> From: Ted Yu <yu...@gmail.com>
> To: "user@hbase.apache.org" <us...@hbase.apache.org> 
> Sent: Wednesday, August 28, 2013 8:01 PM
> Subject: Re: RowLocks
> 
> 
> The API is no longer a public API
> 
> Thanks
> 
> 
> On Wed, Aug 28, 2013 at 7:58 PM, Michael Segel <mi...@hotmail.com>wrote:
> 
>> Ted,
>> Can you clarify...
>> Do you mean the API is no longer a public API, or do you mean no more RLL
>> for atomic writes?
>> 
>> On Aug 28, 2013, at 5:18 PM, Ted Yu <yu...@gmail.com> wrote:
>> 
>>> RowLock API has been removed in 0.96.
>>> 
>>> Can you tell us your use case ?
>>> 
>>> 
>>> On Wed, Aug 28, 2013 at 3:14 PM, Kristoffer Sjögren <stoffe@gmail.com
>>> wrote:
>>> 
>>>> Hi
>>>> 
>>>> About the internals of locking a row in hbase.
>>>> 
>>>> Does hbase row locks map one-to-one with a locks in zookeeper or are
>> there
>>>> any optimizations based on the fact that a row only exist on a single
>>>> machine?
>>>> 
>>>> Cheers,
>>>> -Kristoffer
>>>> 
>> 
>> The opinions expressed here are mine, while they may reflect a cognitive
>> thought, that is purely accidental.
>> Use at your own risk.
>> Michael Segel
>> michael_segel (AT) hotmail.com
>> 
>> 
>> 
>> 
>> 
>> 
> 

The opinions expressed here are mine, while they may reflect a cognitive thought, that is purely accidental. 
Use at your own risk. 
Michael Segel
michael_segel (AT) hotmail.com






Re: RowLocks

Posted by Kristoffer Sjögren <st...@gmail.com>.
Maybe I should illustrate with a specific usecase.

I want to create a unique row with a rowkey that look like this:
id+timestamp

The timestamp (in millis) is provided by the user. It is ONLY the id that
dictate uniqueness, not the timestamp. So there is a race condition here.

My reasoning is as follows.

1) Lock the id (without the timestamp).

2.1) If the lock was aquired. Scan for the row.
2.2) If the row was not found, create it and set a counter on the
id+timestamp row to 0.
2.3) If the row is found, increase a counter on the id+timestamp row.
2.4) Release the lock.

If the lock was NOT aquired.

3.1) Not really sure how to proceed here. The easiest way is probably to
wait until the lock is released (like a SELECT FOR UPDATE). Retries would
also work.

It is very important that we do not loose the increments or create multiple
rows with same id with different timestamps when there are race conditions.



On Thu, Aug 29, 2013 at 6:22 AM, lars hofhansl <la...@apache.org> wrote:

> Specifically the API has been removed because it had never actually worked
> correctly.
>
>
> Rowlocks are used by RegionServers for intra-region operations.
> As such they are ephemeral, in-memory constructs, that cannot reliably
> outlive a single RPC request.
> The HTable rowlock API allowed you to create a rowlocks and hold it over
> multiple RPCs, which would break if f.e. a region is moved or split.
>
> -- Lars
> ________________________________
> From: Ted Yu <yu...@gmail.com>
> To: "user@hbase.apache.org" <us...@hbase.apache.org>
> Sent: Wednesday, August 28, 2013 8:01 PM
> Subject: Re: RowLocks
>
>
> The API is no longer a public API
>
> Thanks
>
>
> On Wed, Aug 28, 2013 at 7:58 PM, Michael Segel <michael_segel@hotmail.com
> >wrote:
>
> > Ted,
> > Can you clarify...
> > Do you mean the API is no longer a public API, or do you mean no more RLL
> > for atomic writes?
> >
> > On Aug 28, 2013, at 5:18 PM, Ted Yu <yu...@gmail.com> wrote:
> >
> > > RowLock API has been removed in 0.96.
> > >
> > > Can you tell us your use case ?
> > >
> > >
> > > On Wed, Aug 28, 2013 at 3:14 PM, Kristoffer Sjögren <stoffe@gmail.com
> > >wrote:
> > >
> > >> Hi
> > >>
> > >> About the internals of locking a row in hbase.
> > >>
> > >> Does hbase row locks map one-to-one with a locks in zookeeper or are
> > there
> > >> any optimizations based on the fact that a row only exist on a single
> > >> machine?
> > >>
> > >> Cheers,
> > >> -Kristoffer
> > >>
> >
> > The opinions expressed here are mine, while they may reflect a cognitive
> > thought, that is purely accidental.
> > Use at your own risk.
> > Michael Segel
> > michael_segel (AT) hotmail.com
> >
> >
> >
> >
> >
> >
>

Re: RowLocks

Posted by lars hofhansl <la...@apache.org>.
Specifically the API has been removed because it had never actually worked correctly.


Rowlocks are used by RegionServers for intra-region operations.
As such they are ephemeral, in-memory constructs, that cannot reliably outlive a single RPC request.
The HTable rowlock API allowed you to create a rowlocks and hold it over multiple RPCs, which would break if f.e. a region is moved or split.

-- Lars
________________________________
From: Ted Yu <yu...@gmail.com>
To: "user@hbase.apache.org" <us...@hbase.apache.org> 
Sent: Wednesday, August 28, 2013 8:01 PM
Subject: Re: RowLocks


The API is no longer a public API

Thanks


On Wed, Aug 28, 2013 at 7:58 PM, Michael Segel <mi...@hotmail.com>wrote:

> Ted,
> Can you clarify...
> Do you mean the API is no longer a public API, or do you mean no more RLL
> for atomic writes?
>
> On Aug 28, 2013, at 5:18 PM, Ted Yu <yu...@gmail.com> wrote:
>
> > RowLock API has been removed in 0.96.
> >
> > Can you tell us your use case ?
> >
> >
> > On Wed, Aug 28, 2013 at 3:14 PM, Kristoffer Sjögren <stoffe@gmail.com
> >wrote:
> >
> >> Hi
> >>
> >> About the internals of locking a row in hbase.
> >>
> >> Does hbase row locks map one-to-one with a locks in zookeeper or are
> there
> >> any optimizations based on the fact that a row only exist on a single
> >> machine?
> >>
> >> Cheers,
> >> -Kristoffer
> >>
>
> The opinions expressed here are mine, while they may reflect a cognitive
> thought, that is purely accidental.
> Use at your own risk.
> Michael Segel
> michael_segel (AT) hotmail.com
>
>
>
>
>
>

Re: RowLocks

Posted by Ted Yu <yu...@gmail.com>.
The API is no longer a public API

Thanks


On Wed, Aug 28, 2013 at 7:58 PM, Michael Segel <mi...@hotmail.com>wrote:

> Ted,
> Can you clarify...
> Do you mean the API is no longer a public API, or do you mean no more RLL
> for atomic writes?
>
> On Aug 28, 2013, at 5:18 PM, Ted Yu <yu...@gmail.com> wrote:
>
> > RowLock API has been removed in 0.96.
> >
> > Can you tell us your use case ?
> >
> >
> > On Wed, Aug 28, 2013 at 3:14 PM, Kristoffer Sjögren <stoffe@gmail.com
> >wrote:
> >
> >> Hi
> >>
> >> About the internals of locking a row in hbase.
> >>
> >> Does hbase row locks map one-to-one with a locks in zookeeper or are
> there
> >> any optimizations based on the fact that a row only exist on a single
> >> machine?
> >>
> >> Cheers,
> >> -Kristoffer
> >>
>
> The opinions expressed here are mine, while they may reflect a cognitive
> thought, that is purely accidental.
> Use at your own risk.
> Michael Segel
> michael_segel (AT) hotmail.com
>
>
>
>
>
>

Re: RowLocks

Posted by Michael Segel <mi...@hotmail.com>.
Ted, 
Can you clarify... 
Do you mean the API is no longer a public API, or do you mean no more RLL for atomic writes?

On Aug 28, 2013, at 5:18 PM, Ted Yu <yu...@gmail.com> wrote:

> RowLock API has been removed in 0.96.
> 
> Can you tell us your use case ?
> 
> 
> On Wed, Aug 28, 2013 at 3:14 PM, Kristoffer Sjögren <st...@gmail.com>wrote:
> 
>> Hi
>> 
>> About the internals of locking a row in hbase.
>> 
>> Does hbase row locks map one-to-one with a locks in zookeeper or are there
>> any optimizations based on the fact that a row only exist on a single
>> machine?
>> 
>> Cheers,
>> -Kristoffer
>> 

The opinions expressed here are mine, while they may reflect a cognitive thought, that is purely accidental. 
Use at your own risk. 
Michael Segel
michael_segel (AT) hotmail.com






Re: RowLocks

Posted by Ted Yu <yu...@gmail.com>.
RowLock API has been removed in 0.96.

Can you tell us your use case ?


On Wed, Aug 28, 2013 at 3:14 PM, Kristoffer Sjögren <st...@gmail.com>wrote:

> Hi
>
> About the internals of locking a row in hbase.
>
> Does hbase row locks map one-to-one with a locks in zookeeper or are there
> any optimizations based on the fact that a row only exist on a single
> machine?
>
> Cheers,
> -Kristoffer
>