You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by John Beatty <jo...@gmail.com> on 2010/08/15 03:32:35 UTC

question about checkAndPut() expected value parameter when testing row nonexistence

There appears to be a disconnect between the API [1] and the
implementation [2] of checkAndPut() regarding the expected value
parameter when the caller wants to make the put conditional on the row
not existing. The javadoc states that the caller should use a null
expected value for this purpose, whereas the implementation is
checking for a 0-length byte[]. If a null expected value is given,
checkAndPut() will NPE; see HRegion.java:1520 in trunk.

I believe that null, rather than 0-length byte[], should be used for
requiring row non-existence in checkAndPut(). Besides seeming like the
right API, a 0-length byte[] is technically a valid row key (and least
for a little put/get test I did; I found this surprising).

Thoughts?

john

[1] http://hbase.apache.org/docs/r0.89.20100726/apidocs/org/apache/hadoop/hbase/ipc/HRegionInterface.html#checkAndPut(byte[],
byte[], byte[], byte[], byte[], org.apache.hadoop.hbase.client.Put)

[2] http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?view=markup
-- line 1520

Re: question about checkAndPut() expected value parameter when testing row nonexistence

Posted by John Beatty <jo...@gmail.com>.
J-D, thanks. I'll take a crack at submitting a patch containing a fix
plus the unit tests.

john

On Mon, Aug 16, 2010 at 10:28 AM, Jean-Daniel Cryans
<jd...@apache.org> wrote:
> John,
>
> Looks like its broken, moreover we don't have any unit tests for
> checkAndPut/Delete. We need to fix that, I opened
> https://issues.apache.org/jira/browse/HBASE-2920
>
> This could be a nice first contribution :)
>
> J-D
>
> On Sat, Aug 14, 2010 at 6:51 PM, John Beatty <jo...@gmail.com> wrote:
>> Thanks Ryan, but I seem to be missing something then. It NPEs for me.
>> When running against 0.89.20100726 and providing a null expected value
>> I get the below stack trace (and works like a champ when I provide a
>> byte[0]. I also don't see the transformation you're referring to in
>> HTable.
>>
>> (for reference,
>> http://svn.apache.org/viewvc/hbase/branches/0.89.20100726/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?view=markup)
>>
>> java.io.IOException: java.io.IOException: java.lang.NullPointerException
>>        at org.apache.hadoop.hbase.regionserver.HRegionServer.convertThrowableToIOE(HRegionServer.java:845)
>>        at org.apache.hadoop.hbase.regionserver.HRegionServer.convertThrowableToIOE(HRegionServer.java:835)
>>        at org.apache.hadoop.hbase.regionserver.HRegionServer.checkAndMutate(HRegionServer.java:1754)
>>        at org.apache.hadoop.hbase.regionserver.HRegionServer.checkAndPut(HRegionServer.java:1773)
>>        at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
>>        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>        at org.apache.hadoop.hbase.ipc.HBaseRPC$Server.call(HBaseRPC.java:576)
>>        at org.apache.hadoop.hbase.ipc.HBaseServer$Handler.run(HBaseServer.java:919)
>> Caused by: java.lang.NullPointerException
>>        at org.apache.hadoop.hbase.regionserver.HRegion.checkAndMutate(HRegion.java:1616)
>>        at org.apache.hadoop.hbase.regionserver.HRegionServer.checkAndMutate(HRegionServer.java:1751)
>>        ... 6 more
>>
>> On Sat, Aug 14, 2010 at 6:34 PM, Ryan Rawson <ry...@gmail.com> wrote:
>>> Nulls end up being transformed into byte[0] in HTable and all is well.
>>>
>>> On Aug 14, 2010 6:33 PM, "John Beatty" <jo...@gmail.com> wrote:
>>>> There appears to be a disconnect between the API [1] and the
>>>> implementation [2] of checkAndPut() regarding the expected value
>>>> parameter when the caller wants to make the put conditional on the row
>>>> not existing. The javadoc states that the caller should use a null
>>>> expected value for this purpose, whereas the implementation is
>>>> checking for a 0-length byte[]. If a null expected value is given,
>>>> checkAndPut() will NPE; see HRegion.java:1520 in trunk.
>>>>
>>>> I believe that null, rather than 0-length byte[], should be used for
>>>> requiring row non-existence in checkAndPut(). Besides seeming like the
>>>> right API, a 0-length byte[] is technically a valid row key (and least
>>>> for a little put/get test I did; I found this surprising).
>>>>
>>>> Thoughts?
>>>>
>>>> john
>>>>
>>>> [1]
>>> http://hbase.apache.org/docs/r0.89.20100726/apidocs/org/apache/hadoop/hbase/ipc/HRegionInterface.html#checkAndPut(byte[]
>>> ,
>>>> byte[], byte[], byte[], byte[], org.apache.hadoop.hbase.client.Put)
>>>>
>>>> [2]
>>> http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?view=markup
>>>> -- line 1520
>>>
>>
>

Re: question about checkAndPut() expected value parameter when testing row nonexistence

Posted by Jean-Daniel Cryans <jd...@apache.org>.
John,

Looks like its broken, moreover we don't have any unit tests for
checkAndPut/Delete. We need to fix that, I opened
https://issues.apache.org/jira/browse/HBASE-2920

This could be a nice first contribution :)

J-D

On Sat, Aug 14, 2010 at 6:51 PM, John Beatty <jo...@gmail.com> wrote:
> Thanks Ryan, but I seem to be missing something then. It NPEs for me.
> When running against 0.89.20100726 and providing a null expected value
> I get the below stack trace (and works like a champ when I provide a
> byte[0]. I also don't see the transformation you're referring to in
> HTable.
>
> (for reference,
> http://svn.apache.org/viewvc/hbase/branches/0.89.20100726/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?view=markup)
>
> java.io.IOException: java.io.IOException: java.lang.NullPointerException
>        at org.apache.hadoop.hbase.regionserver.HRegionServer.convertThrowableToIOE(HRegionServer.java:845)
>        at org.apache.hadoop.hbase.regionserver.HRegionServer.convertThrowableToIOE(HRegionServer.java:835)
>        at org.apache.hadoop.hbase.regionserver.HRegionServer.checkAndMutate(HRegionServer.java:1754)
>        at org.apache.hadoop.hbase.regionserver.HRegionServer.checkAndPut(HRegionServer.java:1773)
>        at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
>        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at org.apache.hadoop.hbase.ipc.HBaseRPC$Server.call(HBaseRPC.java:576)
>        at org.apache.hadoop.hbase.ipc.HBaseServer$Handler.run(HBaseServer.java:919)
> Caused by: java.lang.NullPointerException
>        at org.apache.hadoop.hbase.regionserver.HRegion.checkAndMutate(HRegion.java:1616)
>        at org.apache.hadoop.hbase.regionserver.HRegionServer.checkAndMutate(HRegionServer.java:1751)
>        ... 6 more
>
> On Sat, Aug 14, 2010 at 6:34 PM, Ryan Rawson <ry...@gmail.com> wrote:
>> Nulls end up being transformed into byte[0] in HTable and all is well.
>>
>> On Aug 14, 2010 6:33 PM, "John Beatty" <jo...@gmail.com> wrote:
>>> There appears to be a disconnect between the API [1] and the
>>> implementation [2] of checkAndPut() regarding the expected value
>>> parameter when the caller wants to make the put conditional on the row
>>> not existing. The javadoc states that the caller should use a null
>>> expected value for this purpose, whereas the implementation is
>>> checking for a 0-length byte[]. If a null expected value is given,
>>> checkAndPut() will NPE; see HRegion.java:1520 in trunk.
>>>
>>> I believe that null, rather than 0-length byte[], should be used for
>>> requiring row non-existence in checkAndPut(). Besides seeming like the
>>> right API, a 0-length byte[] is technically a valid row key (and least
>>> for a little put/get test I did; I found this surprising).
>>>
>>> Thoughts?
>>>
>>> john
>>>
>>> [1]
>> http://hbase.apache.org/docs/r0.89.20100726/apidocs/org/apache/hadoop/hbase/ipc/HRegionInterface.html#checkAndPut(byte[]
>> ,
>>> byte[], byte[], byte[], byte[], org.apache.hadoop.hbase.client.Put)
>>>
>>> [2]
>> http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?view=markup
>>> -- line 1520
>>
>

Re: question about checkAndPut() expected value parameter when testing row nonexistence

Posted by John Beatty <jo...@gmail.com>.
Thanks Ryan, but I seem to be missing something then. It NPEs for me.
When running against 0.89.20100726 and providing a null expected value
I get the below stack trace (and works like a champ when I provide a
byte[0]. I also don't see the transformation you're referring to in
HTable.

(for reference,
http://svn.apache.org/viewvc/hbase/branches/0.89.20100726/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?view=markup)

java.io.IOException: java.io.IOException: java.lang.NullPointerException
	at org.apache.hadoop.hbase.regionserver.HRegionServer.convertThrowableToIOE(HRegionServer.java:845)
	at org.apache.hadoop.hbase.regionserver.HRegionServer.convertThrowableToIOE(HRegionServer.java:835)
	at org.apache.hadoop.hbase.regionserver.HRegionServer.checkAndMutate(HRegionServer.java:1754)
	at org.apache.hadoop.hbase.regionserver.HRegionServer.checkAndPut(HRegionServer.java:1773)
	at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at org.apache.hadoop.hbase.ipc.HBaseRPC$Server.call(HBaseRPC.java:576)
	at org.apache.hadoop.hbase.ipc.HBaseServer$Handler.run(HBaseServer.java:919)
Caused by: java.lang.NullPointerException
	at org.apache.hadoop.hbase.regionserver.HRegion.checkAndMutate(HRegion.java:1616)
	at org.apache.hadoop.hbase.regionserver.HRegionServer.checkAndMutate(HRegionServer.java:1751)
	... 6 more

On Sat, Aug 14, 2010 at 6:34 PM, Ryan Rawson <ry...@gmail.com> wrote:
> Nulls end up being transformed into byte[0] in HTable and all is well.
>
> On Aug 14, 2010 6:33 PM, "John Beatty" <jo...@gmail.com> wrote:
>> There appears to be a disconnect between the API [1] and the
>> implementation [2] of checkAndPut() regarding the expected value
>> parameter when the caller wants to make the put conditional on the row
>> not existing. The javadoc states that the caller should use a null
>> expected value for this purpose, whereas the implementation is
>> checking for a 0-length byte[]. If a null expected value is given,
>> checkAndPut() will NPE; see HRegion.java:1520 in trunk.
>>
>> I believe that null, rather than 0-length byte[], should be used for
>> requiring row non-existence in checkAndPut(). Besides seeming like the
>> right API, a 0-length byte[] is technically a valid row key (and least
>> for a little put/get test I did; I found this surprising).
>>
>> Thoughts?
>>
>> john
>>
>> [1]
> http://hbase.apache.org/docs/r0.89.20100726/apidocs/org/apache/hadoop/hbase/ipc/HRegionInterface.html#checkAndPut(byte[]
> ,
>> byte[], byte[], byte[], byte[], org.apache.hadoop.hbase.client.Put)
>>
>> [2]
> http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?view=markup
>> -- line 1520
>

Re: question about checkAndPut() expected value parameter when testing row nonexistence

Posted by Ryan Rawson <ry...@gmail.com>.
Nulls end up being transformed into byte[0] in HTable and all is well.

On Aug 14, 2010 6:33 PM, "John Beatty" <jo...@gmail.com> wrote:
> There appears to be a disconnect between the API [1] and the
> implementation [2] of checkAndPut() regarding the expected value
> parameter when the caller wants to make the put conditional on the row
> not existing. The javadoc states that the caller should use a null
> expected value for this purpose, whereas the implementation is
> checking for a 0-length byte[]. If a null expected value is given,
> checkAndPut() will NPE; see HRegion.java:1520 in trunk.
>
> I believe that null, rather than 0-length byte[], should be used for
> requiring row non-existence in checkAndPut(). Besides seeming like the
> right API, a 0-length byte[] is technically a valid row key (and least
> for a little put/get test I did; I found this surprising).
>
> Thoughts?
>
> john
>
> [1]
http://hbase.apache.org/docs/r0.89.20100726/apidocs/org/apache/hadoop/hbase/ipc/HRegionInterface.html#checkAndPut(byte[]
,
> byte[], byte[], byte[], byte[], org.apache.hadoop.hbase.client.Put)
>
> [2]
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?view=markup
> -- line 1520