HBase change split policy on an existing table-爱分乐赚

爱分乐赚网站开发是一个面向开发者的知识分享社区。这里集合了网站开发所需要用到的各类网站开发教程。包括(JavaScript 入门教程,TypeScript 入门教程,Vue 入门教程,Ajax 入门教程,ES6-10 入门教程,Yarn 入门教程,ECharts 入门教程,CSS3 入门教程,雪碧图入门教程,移动端布局教程,Html5 入门教程,Sass 入门教程,HTML 入门教程,uni-app 入门教程,Nginx 入门教程,HTTP 入门教程,Docker 入门教程,Shell 入门教程,Linux 入门教程,Gradle 入门教程,Vim 编辑器教程,RESTful 规范教程,Dreamweaver 教程,Markdown 入门教程,Maven 入门教程,Eclipse 编辑器教程,GitHub 入门教程,Android Studio 编辑器教程,PyCharm 编辑器教程,Sublime Text 使用教程,Postman 教程,Python 原生爬虫教程)

hbase(main):006:0> create 'test_table_region', 'username'
0 row(s) in 1.2150 seconds

hbase(main):009:0> put 'test_table_region', '1', 'username:nick' ,'3'
0 row(s) in 0.0050 seconds

hbase(main):010:0> scan 'test_table_region'
ROW                                COLUMN+CELL                                                                                      
 1                                 column=username:nick, timestamp=1436859225880, value=3                                           
1 row(s) in 0.1370 seconds

hbase(main):011:0> describe 'test_table_region'
DESCRIPTION                                                                           ENABLED                                       
 {NAME => 'test_table_region', FAMILIES => [{NAME => 'username', DATA_BLOCK_ENCODING  true                                          
 => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSIONS => '3', COMPRES                                               
 SION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => 'fal                                               
 se', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCACH                                               
 E => 'true'}]}                                                                                                                     
1 row(s) in 0.4040 seconds


hbase(main):013:0> disable 'test_table_region'
0 row(s) in 3.1710 seconds

hbase(main):001:0> alter 'test_table_region', {METHOD => 'table_att', SPLIT_POLICY => 'org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy', MAX_FILESIZE => '5000000000'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 4.5130 seconds

hbase(main):003:0> enable 'test_table_region'
0 row(s) in 6.0330 seconds

hbase(main):046:0> describe 'test_table_region'
DESCRIPTION                                                                           ENABLED                                       
 {NAME => 'test_table_region', SPLIT_POLICY => 'org.apache.hadoop.hbase.regionserver. true                                          
 ConstantSizeRegionSplitPolicy', MAX_FILESIZE => '5000000000', FAMILIES => [{NAME =>                                                
 'username', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE                                                
 => '0', COMPRESSION => 'NONE', VERSIONS => '3', TTL => '2147483647', MIN_VERSIONS =>                                               
  '0', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', ENCODE_ON_DISK => 'true',                                               
  IN_MEMORY => 'false', BLOCKCACHE => 'true'}]}                                                                                     
1 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");
  }

 

本文转自:https://www.cnblogs.com/yanghuahui/p/4645878.html

----------------

微信扫一扫,分享到朋友圈

HBase change split policy on an existing table-爱分乐赚
返回顶部

显示

忘记密码?

显示

显示

获取验证码

Close