hbase namespace命名空间

张映 发表于 2019-09-24

分类目录: hadoop/spark/scala

标签:, ,

在HBase中,namespace命名空间指对一组表的逻辑分组,类似关系型数据库中的database,方便对表在业务上划分。Apache HBase从0.98.0, 0.95.2两个版本开始支持namespace级别的授权操作,HBase全局管理员可以创建、修改和回收namespace的授权。

1,命名空间的概念为即将到来的多租户特性打下基础:

配额管理(Quota Management (HBASE-8410)):限制一个namespace可以使用的资源,资源包括region和table等;

命名空间安全管理(Namespace Security Administration (HBASE-9206)):提供了另一个层面的多租户安全管理

Region服务器组(Region server groups (HBASE-6721)):一个命名空间或一张表,可以被固定到一组regionservers上,从而保证了数据隔离性。

2,hbase自带namespace介绍

hbase:系统内建表,包括namespace和meta表
default:用户建表时未指定namespace的表都创建在此

3,表和命名空间的隶属关系在在创建表时决定,通过以下格式指定: <namespace>:<table>

4,创建namespace

hbase(main):005:0> create_namespace 'test_ns'
0 row(s) in 1.3790 seconds

hbase(main):008:0> create_namespace 'tank_ns'
0 row(s) in 1.1740 seconds

5,查看单个namespace

hbase(main):006:0> describe_namespace 'test_ns'
DESCRIPTION
{NAME => 'test_ns'}
1 row(s) in 0.0180 seconds

6,查看namespace列表

hbase(main):009:0> list_namespace
NAMESPACE
default
hbase
tank_ns
test_ns
4 row(s) in 0.0150 seconds

7,创建测试表

hbase(main):010:0> create 'test_ns:user','name'
0 row(s) in 2.3560 seconds

=> Hbase::Table - test_ns:user

hbase(main):011:0> list_namespace_tables 'test_ns'
TABLE
user
1 row(s) in 0.0280 seconds

8,删除namespace

hbase(main):012:0> drop_namespace 'tank_ns'
0 row(s) in 1.1990 seconds

hbase(main):013:0> drop_namespace 'test_ns'  //有表不能删除

ERROR: org.apache.hadoop.hbase.constraint.ConstraintException: Only empty namespaces can be removed. Namespace test_ns has 1 tables
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:106)
 at org.apache.hadoop.ipc.RemoteException.unwrapRemoteException(RemoteException.java:95)
 at org.apache.hadoop.hbase.util.ForeignExceptionUtil.toIOException(ForeignExceptionUtil.java:45)
 at org.apache.hadoop.hbase.procedure2.RemoteProcedureException.fromProto(RemoteProcedureException.java:114)
 at org.apache.hadoop.hbase.master.procedure.ProcedureSyncWait.waitForProcedureToComplete(ProcedureSyncWait.java:85)
 at org.apache.hadoop.hbase.master.HMaster$15.run(HMaster.java:2941)
 at org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil.submitProcedure(MasterProcedureUtil.java:133)
 at org.apache.hadoop.hbase.master.HMaster.deleteNamespace(HMaster.java:2929)
 at org.apache.hadoop.hbase.master.MasterRpcServices.deleteNamespace(MasterRpcServices.java:508)
 at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$2.callBlockingMethod(MasterProtos.java:63460)
 at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:2380)
 at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:124)
 at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:297)
 at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:277)
Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hbase.constraint.ConstraintException): Only empty namespaces can be removed. Namespace test_ns has 1 tables
 at org.apache.hadoop.hbase.master.procedure.DeleteNamespaceProcedure.prepareDelete(DeleteNamespaceProcedure.java:256)
 at org.apache.hadoop.hbase.master.procedure.DeleteNamespaceProcedure.executeFromState(DeleteNamespaceProcedure.java:83)
 at org.apache.hadoop.hbase.master.procedure.DeleteNamespaceProcedure.executeFromState(DeleteNamespaceProcedure.java:49)
 at org.apache.hadoop.hbase.procedure2.StateMachineProcedure.execute(StateMachineProcedure.java:139)
 at org.apache.hadoop.hbase.procedure2.Procedure.doExecute(Procedure.java:506)
 at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execProcedure(ProcedureExecutor.java:1167)
 at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execLoop(ProcedureExecutor.java:955)
 at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execLoop(ProcedureExecutor.java:908)
 at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.access$400(ProcedureExecutor.java:77)
 at org.apache.hadoop.hbase.procedure2.ProcedureExecutor$2.run(ProcedureExecutor.java:482)

Here is some help for this command:
Drop the named namespace. The namespace must be empty.

9,禁用表后,删除表,在删除namespace

hbase(main):014:0> disable 'test_ns:user'
0 row(s) in 2.3140 seconds

hbase(main):015:0> drop 'test_ns:user'
0 row(s) in 1.5870 seconds

hbase(main):016:0> drop_namespace 'test_ns'
0 row(s) in 1.1750 seconds

 



转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/hadoop/2185.html

留下评论

留下评论
  • (必需)
  • (必需) (will not be published)
  • (必需)   4X3=?