HBase change split policy on an existing table

hbase(main)::> create 'test_table_region', 'username'
row(s) in 1.2150 seconds hbase(main)::> put 'test_table_region', '', 'username:nick' ,''
row(s) in 0.0050 seconds hbase(main)::> scan 'test_table_region'
ROW COLUMN+CELL
column=username:nick, timestamp=, value=
row(s) in 0.1370 seconds hbase(main)::> describe 'test_table_region'
DESCRIPTION ENABLED
{NAME => 'test_table_region', FAMILIES => [{NAME => 'username', DATA_BLOCK_ENCODING true
=> 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '', VERSIONS => '', COMPRES
SION => 'NONE', MIN_VERSIONS => '', TTL => '', KEEP_DELETED_CELLS => 'fal
se', BLOCKSIZE => '', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCACH
E => 'true'}]}
row(s) in 0.4040 seconds hbase(main)::> disable 'test_table_region'
row(s) in 3.1710 seconds hbase(main)::> alter 'test_table_region', {METHOD => 'table_att', SPLIT_POLICY => 'org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy', MAX_FILESIZE => ''}
Updating all regions with the new schema...
/ regions updated.
Done.
row(s) in 4.5130 seconds hbase(main)::> enable 'test_table_region'
row(s) in 6.0330 seconds hbase(main)::> describe 'test_table_region'
DESCRIPTION ENABLED
{NAME => 'test_table_region', SPLIT_POLICY => 'org.apache.hadoop.hbase.regionserver. true
ConstantSizeRegionSplitPolicy', MAX_FILESIZE => '', FAMILIES => [{NAME =>
'username', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE
=> '', COMPRESSION => 'NONE', VERSIONS => '', TTL => '', MIN_VERSIONS =>
'', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '', ENCODE_ON_DISK => 'true',
IN_MEMORY => 'false', BLOCKCACHE => 'true'}]}
row(s) in 0.4610 seconds

the alter split_policy does not work for hbase before version 0.94

we need to use java code to change the split policy of an existing table

 protected void changeSplitPolicy(String tableName, Configuration conf) throws IOException, IllegalAccessException, InstantiationException {
HBaseAdmin admin = new HBaseAdmin(conf);
HTable hTable = new HTable(conf, tableName);
HTableDescriptor htd = hTable.getTableDescriptor();
HTableDescriptor tableDesc = new HTableDescriptor(htd); tableDesc.setValue(HTableDescriptor.SPLIT_POLICY, ConstantSizeRegionSplitPolicy.class.getName());
tableDesc.setValue(HTableDescriptor.MAX_FILESIZE, "5000000000"); if(admin.isTableEnabled(tableName)) {
admin.disableTable(tableName);
}
admin.modifyTable(Bytes.toBytes(tableName), tableDesc);
hTable.close();
admin.close();
System.out.println("change split policy over");
}
上一篇:【转】android加载大量图片内存溢出的三种解决办法


下一篇:遇到的好玩的mvc路由