0

I am keeping a counter in bigtable, and want to put some data in when the counter reaches X. I am Currently doing it like this:

Put put = new Put(EXAMPLE_ROW_KEY);
put.addColumn(EXAMPLE_COLUMN_FAMILY, NEW_QUALIFIER, NEW_VALUE);

boolean success = table.checkAndPut(EXAMPLE_ROW_KEY, 
                                    INFO_COLUMN_FAMILY_NAME,
                                    SIZE_COLUMN,
                                    CompareFilter.CompareOp.LESS, 
                                    Bytes.toBytes(10000L), put);

The issue is, that success is always true and new value is always put, even though the size exceeds 10000L. I tried to use CompareFilter.CompareOp.GREATER_OR_EQUAL with the exact same values and it was still true.

Is the checkAndPut not supported by bigtable, or am I doing something wrong?

safyia
  • 190
  • 2
  • 11

2 Answers2

1

We do support the table.checkAndPut operation in Cloud Bigtable.

However in general it isn't a great practice to try and use the CompareFilter this way since it is performing lexical comparison on the bytes, not a logical integer comparison.

For more information and context see:

As far as the main HBase API, there are plans to handle this better in future HBase versions, e.g. in the proposed HBase 2.0 which incorporates a new OrderedBytes datatype inspired by the orderly project:

In the meantime you might be able to incorporate orderly somehow, or perhaps use an HBase counter and the increment operation.

Ramesh Dharan
  • 895
  • 4
  • 14
  • 2
    Thanks, for the clarification. I modified the code to only check for equality on a string, but unfortunately I get the same incorrect results. The check succeeds even though the values are different. – safyia May 26 '17 at 06:29
  • 3
    You can track progress on this issue here: https://github.com/GoogleCloudPlatform/cloud-bigtable-client/issues/1348. – Solomon Duskis May 26 '17 at 20:44
1

The issue was, that I was using the dependency bigtable-hbase-1.2:0.9.6.2, which probably collided with another dependency. This, I assume, caused an incorrect CheckAndMutateRequest to be sent silently and the check in checkAndPut to always pass. I switched to bigtable-hbase-1.2:0.9.2 and everything is evaluted correctly.

safyia
  • 190
  • 2
  • 11
  • 1
    Interesting, thanks for the update. I'm glad you are unblocked but it does seems like that might also indicate a regression so the Cloud Bigtable engineering team will investigate this further. – Ramesh Dharan May 26 '17 at 15:30