在多租戶的HBase環(huán)境中,通常給一個(gè)租戶分配一個(gè)namespace,因此namespace的容量管理是多租戶管理必不可少的一部分.目前namespace支持三種容量的管理,table的最大數(shù)目,region的最大數(shù)目和namespace占用的文件系統(tǒng)空間.本文給出了通過hbase shell和JAVA API兩種方式設(shè)置namespace quota的方法.
Number-of-Tables Quotas和Number-of-Regions Quotas
設(shè)置namespace quota之前,必須要在hbase-site里加一項(xiàng)配置,否則不會(huì)生效.
hbase.quota.enable=true
hbase shell設(shè)置Quota
創(chuàng)建namespace時(shí)設(shè)置quota
create_namespace 'myns', {'hbase.namespace.quota.maxtables'=>'2'}
增加或修改namespace quota
alter_namespace 'myns', {METHOD => 'set', 'hbase.namespace.quota.maxregions' => '5'}
刪除namespace quota
alter_namespace 'myns', {METHOD => 'unset', NAME => 'hbase.namespace.quota.maxtables'}
如果創(chuàng)建表的操作超過了maxregions閾值,HBase shell會(huì)給出錯(cuò)誤提示:
hbase(main):001:0> create 'myns:t1','f1'
ERROR: The table myns:t1 is not allowed to have 1 regions. The total number of regions permitted is only 5, while current region count is 5. This may be transient, please retry later if there are any ongoing split operations in the namespace.
JAVA API設(shè)置Quota
connection = ConnectionFactory.createConnection(conf);
Admin admin = this.connection.getAdmin();
NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create("myns").build();
namespaceDescriptor.setConfiguration(
"hbase.namespace.quota.maxtables", "10");
namespaceDescriptor.setConfiguration(
"hbase.namespace.quota.maxregions", "100");
admin.createNamespace(namespaceDescriptor);
admin.close();
注: 以上兩種quota管理從HDP2.4開始就支持,更早之前的HDP版本沒有調(diào)研是否支持.
Namespace Storage Quota
HDP2.6加入了新的feature,支持給namespace設(shè)置文件系統(tǒng)空間容量,并且提供了多種策略定義當(dāng)容量超過閾值之后的行為. 具體命令可以參考 Hortonworks官方文檔: HBase Quota Management
在此之前的版本,要想限制namespace占用的空間大小,只能利用hdfs給namespace所在的目錄設(shè)置容量限制.