为 Hbase 设计复合行键
Designing composite rowkey for Hbase
我正在尝试创建具有以下结构的 hbase table。
**rowkey** |**CF1**
(customerid,txtimestamp)|customerid,amount
- 我想查询某个时期范围内使用customerid的记录。
- 我的 rowkey 以相反的顺序使用客户 ID 和交易时间戳。
Long customerid=Long.valueOf(new StringBuilder(customerid).reverse().toString());
byte[] rowKey = Bytes.add(Bytes.toBytes(customerid),Bytes.toBytes(txtimestamp.getTime()));
- 如何设计行键以便将其拆分为 4 个区域服务器?
- 有什么高效的row key设计方法吗?
不需要反推customer_id,没有意义
如果要将所有数据拆分到 4 个区域,可以在所有键前加上值 0-3,例如:
int partition = customer_id % 4;
byte[] rowKey = Bytes.add(
Bytes.toBytes(String.valueOf(partition)),
Bytes.toBytes(String.valueOf(customer_id)),
Bytes.toBytes(txTimestamp.getTime())
);
在这种情况下,您需要使用此 HBaseAdmin 方法
创建带有拆分密钥的 table
public void createTable(final HTableDescriptor desc, byte [][] splitKeys)
拆分键为:
byte[][] splitKeys = new byte[3][];
splitKeys[0] = "1".getBytes();
splitKeys[1] = "2".getBytes();
splitKeys[2] = "3".getBytes();
因此所有以 0 开头的键都转到第一个区域,以 1 开头的键转到第二个区域,依此类推
我正在尝试创建具有以下结构的 hbase table。
**rowkey** |**CF1**
(customerid,txtimestamp)|customerid,amount
- 我想查询某个时期范围内使用customerid的记录。
- 我的 rowkey 以相反的顺序使用客户 ID 和交易时间戳。
Long customerid=Long.valueOf(new StringBuilder(customerid).reverse().toString());
byte[] rowKey = Bytes.add(Bytes.toBytes(customerid),Bytes.toBytes(txtimestamp.getTime()));
- 如何设计行键以便将其拆分为 4 个区域服务器?
- 有什么高效的row key设计方法吗?
不需要反推customer_id,没有意义
如果要将所有数据拆分到 4 个区域,可以在所有键前加上值 0-3,例如:
int partition = customer_id % 4;
byte[] rowKey = Bytes.add(
Bytes.toBytes(String.valueOf(partition)),
Bytes.toBytes(String.valueOf(customer_id)),
Bytes.toBytes(txTimestamp.getTime())
);
在这种情况下,您需要使用此 HBaseAdmin 方法
创建带有拆分密钥的 tablepublic void createTable(final HTableDescriptor desc, byte [][] splitKeys)
拆分键为:
byte[][] splitKeys = new byte[3][];
splitKeys[0] = "1".getBytes();
splitKeys[1] = "2".getBytes();
splitKeys[2] = "3".getBytes();
因此所有以 0 开头的键都转到第一个区域,以 1 开头的键转到第二个区域,依此类推