/**
* 通过Adminc.create(HTableDescriptor , byte[][] splits)创建多个空的region
* @param admin
* @param table
* @param splits
* @return
* @throws IOException
*/
public static boolean createTable(Admin admin, HTableDescriptor table, byte[][] splits)
throws IOException {
try {
admin.createTable(table, splits);
return true;
} catch (TableExistsException e) {
System.out.println("table " + table.getNameAsString() + " already exists");
// the table already exists...
return false;
}
}
/**
* 获取拆分间splitkeys
* @param startKey
* @param endKey
* @param numRegions
* @return
*/
public static byte[][] getHexSplits(String startKey, String endKey, int numRegions) {
//start:001,endkey:100,10region [001,010] [011,020]
byte[][] splits = new byte[numRegions-1][];
BigInteger lowestKey = new BigInteger(startKey, 16);
BigInteger highestKey = new BigInteger(endKey, 16);
BigInteger range = highestKey.subtract(lowestKey);
BigInteger regionIncrement = range.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;
}
? 通过单个row key访问:即按照某个row key键值进行get操作;
? 通过row key的range进行scan:即通过设置startRowKey和endRowKey,在这个范围内进行扫描;
? 全表扫描:即直接扫描整张表中所有行记录。
HColumnDescriptor.setInMemory(true)
HColumnDescriptor.setMaxVersions(int maxVersions)
setMaxVersions(1)
。HColumnDescriptor.setTimeToLive(int timeToLive)
setTimeToLive(2 * 24 * 60 * 60)
。 hbase.hregion.majoucompaction 默认为24 小时、
//默认值为0.2 防止region server 在同一时间进行major compaction)。
hbase.hregion.majorcompaction.jetter
//参数的作用是:对参数hbase.hregion.majoucompaction 规定的值起到浮动的作用,假如两个参数都为默认值24和0,2,那么major compact最终使用的数值为:19.2~28.8 这个范围。
//表示至少需要三个满足条件的store file时,minor compaction才会启动
hbase.hstore.compaction.min :默认值为 3,
//表示一次minor compaction中最多选取10个store file
hbase.hstore.compaction.max 默认值为10,
//表示文件大小小于该值的store file 一定会加入到minor compaction的store file中
hbase.hstore.compaction.min.size
//表示文件大小大于该值的store file 一定会被minor compaction排除
hbase.hstore.compaction.max.size
//将store file 按照文件年龄排序(older to younger),minor compaction总是从older store file开始选择
hbase.hstore.compaction.ratio
HTable.put(List<Put>)
方法可以将指定的row key列表,批量写入多行记录,这样做的好处是批量执行,只需要一次网络I/O开销,这对于对数据实时性要求高,网络传输RTT高的情景下可能带来明显的性能提升。HTable.setWriteBufferSize(writeBufferSize)
方法可以设置HTable客户端的写buffer大小,如果新设置的buffer小于当前写buffer中的数据时,buffer将会被flush到服务端。其中,writeBufferSize的单位是byte字节数,可以根据实际写入数据量的多少来设置该值。Put/Delete
操作),首先会先写WAL(Write Ahead Log)日志(即HLog,一个RegionServer上的所有Region共享一个HLog),只有当WAL日志写成功后,再接着写MemStore,然后客户端被通知提交数据成功;如果写WAL日志失败,客户端则被通知提交失败。这样做的好处是可以做到RegionServer宕机后的数据恢复。Put.setWriteToWAL(false)
或Delete.setWriteToWAL(false)
函数,HTable.get(List<Get>)
`hbase.client.scanner.caching
配置项可以设置HBase scanner一次从服务端抓取的数据条数,默认情况下一次一条。通过将其设置成一个合理的值,可以减少scan过程中next()的时间开销,代价是scanner需要通过客户端的内存来维持这些被cache的行记录。(heapsize * hbase.regionserver.global.memstore.upperLimit * 0.9)
,(heapsize * hfile.block.cache.size * 0.85)
后,会启动淘汰机制,淘汰掉最老的一批数据。heapsize * 0.8
,否则HBase不能启动。默认BlockCache为0.2,而Memstore为0.4。对于注重读响应时间的系统,可以将 BlockCache设大些,比如设置BlockCache=0.4,Memstore=0.39,以加大缓存的命中率。原文:http://blog.csdn.net/wuxintdrh/article/details/69070543