连接HBase
|
private HTable table; @Before public void setUp() throws IOException { Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum", "192.168.0.100"); conf.set("hbase.zookeeper.property.clientPort", "2181"); conf.set("mapred.task.timeout", "0"); table = new HTable(conf, "pigstore"); } |
Create
|
@Test public void testPut() throws IOException { //rowKey = 100 Put put = new Put(Bytes.toBytes("100")); //添加列cf:one, 值为10101 put.add(Bytes.toBytes("cf"),Bytes.toBytes("one"),Bytes.toBytes("10101")); //添加列cf:two,值为cdf put.add(Bytes.toBytes("cf"),Bytes.toBytes("two"),Bytes.toBytes("cdf")); table.put(put); } |
进入HBase Shell,scan一下:
|
hbase(main):003:0> scan 'pigstore' 100 column=cf:one, timestamp=1402391810630, value=10101 100 column=cf:two, timestamp=1402391810630, value=cdf |
HBase写过程
- client向region server提交写请求
- region server找到目标region
- region检查数据是否与schema一致
- 如果客户端没有指定版本,则获取当前系统时间作为数据版本
- 将更新写入WAL log
- 将更新写入Memstore
- 判断Memstore的是否需要flush为Store文件
阅读全文>>