文档简介:
写MOB表
功能介绍
HBase MOB数据读出与普通HBase数据的读出没有什么区别,对客户来说是透明的。
为了使用HBase MOB功能需要在web控制台配置管理添加HBase MOB相关的配置项,
除此之外还需要在表可视化选定对应的表指定columnfamily上开启MOB功能。
以下代码片段在cn.chinatelecom.hbase.sample包的“MOBSample”类的
createMOBTable方法中。
public void createMOBTable() {
log.info("Entering createMOBTable.");
try (Admin admin = conn.getAdmin()) {
ColumnFamilyDescriptor columnFamily = ColumnFamilyDescriptorBuilder
.newBuilder(CF.getBytes())
.setMobEnabled(true)
.setMobThreshold(10L).build();
TableDescriptor tableDescriptor = TableDescriptorBuilder
.newBuilder(tableName)
.setColumnFamily(columnFamily)
.build();
admin.createTable(tableDescriptor);
log.info("MOB Table is created successfully.");
} catch (Exception e) {
log.error("MOB Table is created failed ", e);
}
log.info("Exiting createMOBTable.");
}
样例:用Put接口写入MOB数据
public void insertMOBData(byte[] value) {
log.info("Entering insertMOBData.");
try {
Put p = new Put(Bytes.toBytes("row"));
p.addColumn(Bytes.toBytes(CF), Bytes.toBytes("c1"), value);
Table table = conn.getTable(tableName);
table.put(p);
log.info("MOB data inserted successfully.");
} catch (Exception e) {
log.error("MOB data inserted failed ", e);
}
log.info("Exiting insertMOBData.");
}