HBase优化之—在建表时预先分regions 代码
来源:互联网 发布:如何注销淘宝账号 编辑:程序博客网 时间:2024/06/05 09:59
import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.HColumnDescriptor;import org.apache.hadoop.hbase.HTableDescriptor;import org.apache.hadoop.hbase.client.HBaseAdmin;import org.apache.hadoop.hbase.client.HTable;import org.apache.hadoop.hbase.client.Put;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import java.io.IOException;import java.math.BigInteger;/** * */public class TestCreateHBase { private static final Logger LOG = LoggerFactory.getLogger(TestCreateHBase.class); public static void main(String[] args) throws IOException { Configuration configuration = HBaseConfiguration.create(); configuration.set("hbase.zookeeper.quorum", "10.100.2.92,10.100.2.93"); HBaseAdmin hBaseAdmin = new HBaseAdmin(configuration); HTableDescriptor tableDescriptor = new HTableDescriptor("rt_user_tags_test"); tableDescriptor.addFamily(new HColumnDescriptor("tags")); byte[][] splits = getHexSplits("1", "100", 10); createTable(hBaseAdmin, tableDescriptor, splits); for (int i = 0; i < 100; i++) { insertData("rt_user_tags_test", configuration, String.valueOf(i), "tags"); } } public static boolean createTable(HBaseAdmin hBaseAdmin, HTableDescriptor tableDescriptor, byte[][] splits) throws IOException { try { hBaseAdmin.createTable(tableDescriptor, splits); return true; } catch (Exception e) { LOG.info("table" + tableDescriptor.getNameAsString() + "already exists!"); return false; } } public static byte[][] getHexSplits(String startKey, String endKey, int numRegions) { //startKey:001, endKey:100, 10regions[001, 010], [011, 020],... byte[][] splits = new byte[numRegions - 1][]; BigInteger lowestKey = new BigInteger(startKey, 16); BigInteger highestKey = new BigInteger(endKey, 16); BigInteger rangge = highestKey.subtract(lowestKey); BigInteger regionIncrement = rangge.divide(BigInteger.valueOf(numRegions)); lowestKey = lowestKey.add(regionIncrement); for (int i = 0; i < numRegions - 1; i++) { BigInteger key = lowestKey.add(regionIncrement.multiply(BigInteger.valueOf(i))); byte[] b = String.format("%016x", key).getBytes(); splits[i] = b; } return splits; } public static void insertData(String tableName, Configuration configuration, String rowkey, String columnFamily) throws IOException { System.out.println("start insert data ......"); HTable table = new HTable(configuration, "rt_user_tags_test"); Put put = new Put(rowkey.getBytes()); put.add(columnFamily.getBytes(), null, "Java".getBytes()); try { table.put(put); } catch (IOException e) { e.printStackTrace(); } System.out.println("end insert data ......"); }}
阅读全文
0 0
- HBase优化之—在建表时预先分regions 代码
- HBASE预先分配regions的实现
- HBASE预先分配regions的实现
- HBASE通过预先创建regions,来平衡数据的负载
- Hbase代码优化总结
- HBase Merging Regions
- hbase merge regions
- Hbase优化之二
- Hbase优化之三
- Hbase优化之四
- Hbase优化之五
- Hbase优化之六
- Hbase优化之七
- Hbase优化之八
- Hbase优化之九
- Hbase优化之十
- 级联删除更新在建表时的定义
- hibernate之预先加载
- Java远程连接Redis却返回timed out
- STM32初识——中断初始化过程(by woody)
- 模拟实现简单Mystring
- 多态 多态中的成员(成员变量、构造方法、成员方法、静态方法)访问特点
- markdown
- HBase优化之—在建表时预先分regions 代码
- 水题 第五站 HDU Ignatius and the Princess IV
- LINUX网络命令
- mongoose
- oracle ebs应用产品安全性-交叉验证规则
- 大型网站服务器的架构
- IBMMQ 带用户密码验证的发送和接收消息
- vue 商品星级评价
- hdu 1754 I Hate It (线段树)(第一部分 单点更新)