目录
namespace 基本概念
在HBase中,namespace命名空间指对一组表的逻辑分组,类似RDBMS中的database,方便对表在业务上划分。Apache HBase从0.98.0, 0.95.2两个版本开始支持namespace级别的授权操作,HBase全局管理员可以创建、修改和回收namespace的授权。
HBase系统默认定义了两个缺省的namespace
hbase:系统内建表,包括namespace和meta表
default:用户建表时未指定namespace的表都创建在此
namespace 基本操作
namespace 相关的创建操作
创建namespace
hbase>create_namespace 'nametest'
在namespace下创建表
hbase>create 'nametest:testtable', 'fm1'
---------------------------
namespace 相关的删除操作
删除namespace
hbase>drop_namespace 'nametest'
注意要删除的namespace必须是空的,其下没有表,否则会删除失败:
hbase(main):051:0> create_namespace "test_drop_namespace"
Took 0.2376 seconds
hbase(main):052:0> create "test_drop_namespace:t1", "cf1"
Created table test_drop_namespace:t1
Took 2.2312 seconds
=> Hbase::Table - test_drop_namespace:t1
hbase(main):053:0> drop_namespace "test_drop_namespace"
ERROR: org.apache.hadoop.hbase.constraint.ConstraintException: Only empty namespaces can be removed. Namespace test_drop_namespace has 1 tables
at org.apache.hadoop.hbase.master.procedure.DeleteNamespaceProcedure.prepareDelete(DeleteNamespaceProcedure.java:217)
at org.apache.hadoop.hbase.master.procedure.DeleteNamespaceProcedure.executeFromState(DeleteNamespaceProcedure.java:78)
at org.apache.hadoop.hbase.master.procedure.DeleteNamespaceProcedure.executeFromState(DeleteNamespaceProcedure.java:45)
at org.apache.hadoop.hbase.procedure2.StateMachineProcedure.execute(StateMachineProcedure.java:189)
at org.apache.hadoop.hbase.procedure2.Procedure.doExecute(Procedure.java:850)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execProcedure(ProcedureExecutor.java:1473)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.executeProcedure(ProcedureExecutor.java:1241)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.access$800(ProcedureExecutor.java:75)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor$WorkerThread.run(ProcedureExecutor.java:1761)
For usage try 'help "drop_namespace"'
Took 0.1217 seconds
hbase(main):054:0> disable "test_drop_namespace:t1"
Took 0.4357 seconds
hbase(main):055:0> drop "test_drop_namespace:t1"
Took 0.2351 seconds
hbase(main):056:0> drop_namespace "test_drop_namespace"
Took 0.2172 seconds
---------------------------------
namespace相关的查询操作
查看某个 namespace
hbase>describe_namespace 'nametest'
列出所有namespace
hbase>list_namespace
查看某个namespace下的表
hbase>list_namespace_tables 'nametest'
查看非默认namespace的表
hbase(main):013:0> describe 'hbase:meta'
hbase(main):013:0> describe 'hbase:meta'
Table hbase:meta is ENABLED
hbase:meta, {TABLE_ATTRIBUTES => {IS_META => 'true', REGION_REPLICATION => '1', coprocessor$1 => '|org.ap
ache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint|536870911|'}
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', VERSIONS => '3', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP
_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER
', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'NONE', CACHE_INDEX_ON_WRITE => 'false',
IN_MEMORY => 'true', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION =
> 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '8192'}
{NAME => 'table', VERSIONS => '3', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEE
P_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVE
R', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'NONE', CACHE_INDEX_ON_WRITE => 'false'
, IN_MEMORY => 'true', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION
=> 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '8192'}
2 row(s)
Took 0.0406 seconds
-------------------------------------
namespace 相关的修改操作
添加或修改属性:
alter_namespace 'ns1', {METHOD => 'set', 'PROPERTY_NAME' => 'PROPERTY_VALUE'}
删除属性:
alter_namespace 'ns1', {METHOD => 'unset', NAME=>'PROPERTY_NAME'}
相关案例
查看附加信息发现作者写错了,需要修改:
hbase(main):014:0> alter_namespace "test002", {METHOD=>"set", "author"=>"ChenEr"}
Took 0.2458 seconds
hbase(main):015:0> describe_namespace "test002"
DESCRIPTION
{NAME => 'test002', author => 'ChenEr', create_time => '2018-11-4 17:51:53'}
Took 0.0056 seconds
=> 1
改完发现还漏了一项,需要追加自己的联系方式:
hbase(main):016:0> alter_namespace "test002", {METHOD=>"set", "email"=>"CC11001100@qq.com"}
Took 0.2313 seconds
hbase(main):017:0> describe_namespace "test002"
DESCRIPTION
{NAME => 'test002', author => 'ChenEr', create_time => '2018-11-4 17:51:53', email => 'CC11001100@qq.com'}
Took 0.0038 seconds
=> 1
想了下放上去自己的联系方式搞不好会被不断骚扰,还是去掉此项属性:
hbase(main):010:0> alter_namespace "test002", {METHOD=>"unset", NAME=>"email"}
Took 0.2419 seconds
hbase(main):011:0> describe_namespace "test002"
DESCRIPTION
{NAME => 'test002', author => 'ChenEr', create_time => '2018-11-4 17:51:53'}
Took 0.0056 seconds
=> 1