0
votes

I am trying to create a hbase table with following structure.

**rowkey**                  |**CF1**
(customerid,txtimestamp)|customerid,amount
  1. I want to query records using customerid for certain period range.
  2. My rowkey uses customer id in reverse order and transaction timestamp.

Long customerid=Long.valueOf(new StringBuilder(customerid).reverse().toString());

byte[] rowKey = Bytes.add(Bytes.toBytes(customerid),Bytes.toBytes(txtimestamp.getTime()));

  1. How do I desige row key so that it gets split into 4 region server?
  2. Is there any efficient row key design method?
1

1 Answers

1
votes

You don't need to reverse customer_id, it makes no sense

If you want to split all data across 4 regions, you can prefix all keys with values 0-3, for example:

int partition = customer_id % 4;
byte[] rowKey = Bytes.add(
                   Bytes.toBytes(String.valueOf(partition)),
                   Bytes.toBytes(String.valueOf(customer_id)),
                   Bytes.toBytes(txTimestamp.getTime())
                );

In this case you need to create your table with split keys using this HBaseAdmin method

public void createTable(final HTableDescriptor desc, byte [][] splitKeys)

Split keys would be :

byte[][] splitKeys = new byte[3][];
splitKeys[0] = "1".getBytes();
splitKeys[1] = "2".getBytes();
splitKeys[2] = "3".getBytes();

so all keys starting with 0 go to first region, keys starting with 1 goes to second region and so on