Hbase|Hbase 预分区建表
![](https://upload-images.jianshu.io/upload_images/9028759-735db08803d91f7c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
```
private static Admin admin = null;
private static final String user = "admin/admin@DEMO.COM";
private static final String keyPath = "/etc/security/keytabs/admin.keytab";
static {
System.setProperty("java.security.krb5.conf", "/etc/krb5.conf");
System.setProperty("sun.security.krb5.debug", "false");
Configuration conf = new Configuration();
conf.addResource("hbase-site.xml");
【Hbase|Hbase 预分区建表】conf.set("hbase.zookeeper.quorum", "storm4.demo.com,storm2.demo.com,storm3.demo.com");
conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, "2181");
conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/hbase-secure");
conf.set("hbase.security.authentication", "kerberos");
conf.set("hadoop.security.authentication", "kerberos");
UserGroupInformation.setConfiguration(conf);
try {
UserGroupInformation.loginUserFromKeytab(user, keyPath);
} catch (IOException e) {
e.printStackTrace();
}
Connection connection= null;
try {
connection = ConnectionFactory.createConnection(conf);
} catch (IOException e) {
e.printStackTrace();
}
try {
admin = connection.getAdmin();
} catch (IOException e) {
e.printStackTrace();
}
}
public synchronized static Table getTable(String tableName) {
try {
return TABLE_MAP.get(tableName);
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
public synchronized static void createTable(String tableName) throws HBaseException {
TableName table = TableName.valueOf(tableName);
TableDescriptorBuilder tableDesc = TableDescriptorBuilder.newBuilder(table)
tableDesc.setValue(TableDescriptorBuilder.SPLIT_POLICY, classOf[DelimitedKeyPrefixRegionSplitPolicy].getName)
tableDesc.setValue(DelimitedKeyPrefixRegionSplitPolicy.DELIMITER_KEY, "|") //以|作为分区前缀
ColumnFamilyDescriptor extCF = ColumnFamilyDescriptorBuilder.newBuilder("ext".getBytes()).setTimeToLive("90 DAYS").build();
ColumnFamilyDescriptor deviceCF = ColumnFamilyDescriptorBuilder.newBuilder("device".getBytes()).setTimeToLive("90 DAYS").build();
ColumnFamilyDescriptor locationCF = ColumnFamilyDescriptorBuilder.newBuilder("location".getBytes()).setTimeToLive("90 DAYS").build();
tableDesc.setColumnFamilies(Arrays.asList(extCF, locationCF, deviceCF));
try {
val regionServers = 8
val splitKeys = (0 until 256 by regionServers).map(Integer.toHexString).map(i => s"0$i".takeRight(2)).map(Bytes.toBytes).toArray
admin.createTable(tableDesc.build(), splitKeys);
//预分区
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
createTable("DSP_LOG_TABLE");
} catch (HBaseException e) {
e.printStackTrace();
}
}
```
推荐阅读
- 肛门疼痛预示着哪些肛肠疾病?
- 人工智能|干货!人体姿态估计与运动预测
- 推荐系统论文进阶|CTR预估 论文精读(十一)--Deep Interest Evolution Network(DIEN)
- “身体健康”不如“身心健康”——预防老年痴呆
- D206清明第一天
- Spring|Spring 框架之 AOP 原理剖析已经出炉!!!预定的童鞋可以识别下发二维码去看了
- 在外琐事?9
- 预见人力资源
- 病理预测
- mvcc原理和hbase实现