1

TL;DR: Is it possible to update a row timestamp if it exists?

Is it possible to make HBase act in an LRU fashion? What I mean by that is that if a row exists in HBase I want to update its timestamp

I know I can invoke a create data if it doesn't exist (like this) but I'm looking for the opposite, updating data (specifically the timestamp) if the data does exist

The reason for wanting to do this is that I'm working on a component which uses HBase as a cache for URLs and their content, this way when a new request for a URL arrives I want to check if the content already exists and if it does I want to update its timestamp, otherwise the content doesn't exist and I want to go and actually fetch it. The reason I need the timestamp is for the other side of this program where I have a component that reads all the URLs that arrived in the last day, that's the reason why I also need to update this timestamp

Thanks in advance

Community
  • 1
  • 1
Gideon
  • 2,211
  • 5
  • 29
  • 47
  • Sounds like a case for [`checkAndMutate`](https://hbase.apache.org/devapidocs/org/apache/hadoop/hbase/client/HTable.html#checkAndMutate(byte[],%20byte[],%20byte[],%20org.apache.hadoop.hbase.filter.CompareFilter.CompareOp,%20byte[],%20org.apache.hadoop.hbase.client.RowMutations)). It should be available in `hbase` 0.98.7+ – Shyam Feb 26 '16 at 05:18
  • @Shyam is there a way to update the timestamp without first using a get to get the values and then using another put? – Gideon Feb 28 '16 at 08:13
  • Also checkAndMutate checks for a specific value in a row while I just want to know if the row exists or not – Gideon Feb 28 '16 at 09:06
  • Quoting from javadoc _"If the passed value is null, the check is for the lack of column (ie: non-existence)"_ . Couldn't you rely the opposite condition of it. i.e pass some dummy/sentinel condition and value to the `checkAndMutate` method, Such that it will hold true if the column exists. (Existence check in a not so straight forward way). *EDIT: * Did I understand the case correctly, `if(exists) "update ts" else "do something else and then update row"`? – Shyam Feb 29 '16 at 01:08
  • The problem is that if the row exists I have no way of knowing what its value will contain so negating the condition is not possible - I can probably add a dummy value that I can check for it but I don't feel like adding extra info to my data. You got it almost right `if (exists) "update ts" else "do a lot of other things that will eventually create the row"` - I'm sort of trying to use it as LRU cache (with the timestamp). Should I edit my question if it's not clear enough? – Gideon Feb 29 '16 at 07:47
  • I think I get it. I agree that using `checkAndMutate` would be abusing the api in this case. ( There is a discussion about it's behaviour [here](https://issues.apache.org/jira/browse/HBASE-15260) ). There was a proposal to have better 'AtomicOps' api, which didn't really go through. I think it's better to settle for `if(table.exists(Get)) { new Put; }` for the time being. – Shyam Mar 02 '16 at 01:33
  • Thanks for the information. I did go for the table exists and put :). I was just wondering if there's more to the API than what I'm familiar with – Gideon Mar 02 '16 at 09:08

1 Answers1

0

It's been so long since I posted this question but I figured I'll at least accept what I ended up using (even though it was not what I was hoping to use)

I ended up just sending a get and then put so the timestamp is automatically increased

Gideon
  • 2,211
  • 5
  • 29
  • 47