Search code examples
hbasecounterbigtable

HBase schema row key design - increment counter?


I am struggling to find any documents about increment counter in HBase. Any one knows any?

I am designing a Hbase table schema for my application. My row_key can't guarantee 100% uniqueness. So the question is that when my row_key starts having duplicates, I would like to have an increment counter as part of the row key to distinguish them. thoughts?


Solution

  • you can do one thing just add time stamp with your row key so it will be always unique

    as

    info:aaa#timestamp
    info:bbb#timestamp
    info:ccc#timestamp
    info:aaa#timestamp
    info:bbb#timestamp
    info:ccc#timestamp
    info:aaa#timestamp
    info:bbb#timestamp
    info:ccc#timestamp
    

    os if you do like this the row key will always unique

    one more thing you can try

    uidgen

    It's usually found in /usr/bin/

    nyancat ~ # uuidgen 488bc393-a4f5-4a83-8df8-8c15e737dcc5

    if you are using java then

    public class GenerateUUID {
    
      public static final void main(String... aArgs){
        UUID idOne = UUID.randomUUID();
        UUID idTwo = UUID.randomUUID();
        log("UUID One: " + idOne);
        log("UUID Two: " + idTwo);
      }
    
      private static void log(Object aObject){
        System.out.println( String.valueOf(aObject) );
      }
    } 
    

    and then you can attach this as your key