hbase-admin表操作源码跟踪

简介

habse表相关操作,命名空间操作,region操作等涉及到元信息修改的ddl操作全等部都是通过HMaster角色进行。
我们可以通过java hbase-client模块或linux hbase-shell和HMaster打交道进行相关ddl操作。

通信原理

hbase client(hbase-shell)和HMaster(HRegionServer)之间使用rpc进行通信,相关接口通信协议
定义在hbase-protocol模块src/main/protobuf下的.proto文件中。
我们重点需要关注其中的 service ** rpc关键字。我们常见的ddl和dql操作
主要分布在 Master.proto 的 service MasterServiceClient.proto 的service ClientService

关于rpc和protobuf

推荐看一下grpc入门目前,能跑通helloworld即可。

几个关键概念:

  • 注意: hbase rpc使用google protobuf语法定义协议,使用thrift框架实现通信底层,并没有使用grpc框架作为底层
  • 注意一般一个proto中只有一个 service定义,每个rpc定义的方法表示一个接口方法
  • protobuf协议文件.proto会在编译时生成相应java源码文件。service定义会在源码文件生成相应接口,比如BlockingInterface接口。
  • BlockingInterface是同步阻塞接口。

服务端service

Master.proto 的 service MasterService定义会在编译时自动生成 MasterProtos.MasterService.BlockingInterface接口和其源码文件
Client.proto 的service ClientService定义会在编译时自动生成ClientProtos.ClientService.BlockingInterface接口。

MasterProtos.MasterService.BlockingInterface接口类实现类只有MasterRpcServices一个。所有对HMaster 的rpc调用都会经过MasterRpcServices处理。
ClientProtos.ClientService.BlockingInterface接口的实现类为RSRpcServices。和数据相关的所有操作。

调用链分析-元数据操作

hbase的所有ddl操作都定义在Admin接口中。该接口只有一个唯一实现类HBaseAdmin。
以createTable操作为例,客户端code如下:

        try (Admin admin = connection.getAdmin()) {
            HTableDescriptor hbaseTable = new HTableDescriptor(TableName.valueOf(table));
            for (HColumnDescriptor family : familys) {
                hbaseTable.addFamily(family);
            }
            admin.createTable(hbaseTable);
        }

客户端底层整个调用过程如下:
Admin(HBaseAdmin).createTable(…) -> HBaseAdmin.createTableAsyncV2(…)->
executeCallable(call->{master.createTable() 这里的master就是MasterProtos.MasterService.BlockingInterface})->new CreateTableFuture->
-> waitOperationResult同步阻塞校验 -> waitForTableEnabled(调用isTableAvailable)等待表激活->waitForAllRegionsOnline等待所有Region上线->MetaScanner.MetaScan通过scan扫描表元数据判断所有Region是否上线。

服务器端:
MasterRpcServices(MasterProtos.MasterService.BlockingInterface) 相当与Controller接收请求。请求的数据被封装在: CreateTableRequest这里并没有体现出权限相关内容
MasterRpcServices.createTable -> HMaster.createTable->

相关文章

超详细的记录了HBase 集群搭建的整个过程,以及搭建过程出现...
头歌 HBase(相关的五个实验)
1.创建一个学生信息表,用来存储学生的姓名(姓名作为行键,...
大数据课程综合实验案例1 案例简介1.1 案例目的1.2 适用对象...
HBase从浅入深,(初级)什么是HBase,模型,NOSQL,架构,n...
Hadoop之Hbase安装和配置