您当前的位置: 首页 >  hbase

宝哥大数据

暂无认证

  • 0浏览

    0关注

    1029博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

HBase split 源码分析

宝哥大数据 发布时间:2019-07-19 14:28:47 ,浏览量:0

基于HBase-2.1.5 1.1、HbaseAdmin 发起split 1.1.1、split
  @Override
  public void split(final TableName tableName, final byte[] splitPoint) throws IOException {
    checkTableExists(tableName);
    for (HRegionLocation loc : connection.locateRegions(tableName, false, false)) {
      ServerName sn = loc.getServerName();
      if (sn == null) {
        continue;
      }
      RegionInfo r = loc.getRegion();
      // check for parents
      if (r.isSplitParent()) { // 父region正在split, 则不进行分裂
        continue;
      }
      // if a split point given, only split that particular region
      // 只分裂指定分裂点的region
      if (r.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID ||
          (splitPoint != null && !r.containsRow(splitPoint))) {
        continue;
      }
      // call out to master to do split now
      splitRegionAsync(r, splitPoint); // 发送split request 异步
    }
  }
1.1.2、splitRegionAsync
  Future splitRegionAsync(RegionInfo hri, byte[] splitPoint) throws IOException {
    TableName tableName = hri.getTable();
    if (hri.getStartKey() != null && splitPoint != null &&
        Bytes.compareTo(hri.getStartKey(), splitPoint) == 0) {
      throw new IOException("should not give a splitkey which equals to startkey!");
    }
     
     // 构建了一个MasterCallable类型的匿名对象,其复写的rpcCall方法真正的处理客户端的请求
    SplitTableRegionResponse response = executeCallable(
        new MasterCallable(getConnection(), getRpcControllerFactory()) {
          Long nonceGroup = ng.getNonceGroup();
          Long nonce = ng.newNonce();
          @Override
          protected SplitTableRegionResponse rpcCall() throws Exception {
            setPriority(tableName);
            SplitTableRegionRequest request = RequestConverter
                .buildSplitTableRegionRequest(hri, splitPoint, nonceGroup, nonce);
            // split对应的region, 并返回响应
            return master.splitRegion(getRpcController(), request);
          }
        });
    // 创建SplitTableRegionFuture   
    return new SplitTableRegionFuture(this, tableName, response);
  }

  private static class SplitTableRegionFuture extends TableFuture {
    public SplitTableRegionFuture(final HBaseAdmin admin,
        final TableName tableName,
        final SplitTableRegionResponse response) {
      super(admin, tableName,
          (response != null && response.hasProcId()) ? response.getProcId() : null);
    }

    public SplitTableRegionFuture(
        final HBaseAdmin admin,
        final TableName tableName,
        final Long procId) {
      super(admin, tableName, procId);
    }

    @Override
    public String getOperationType() {
      return "SPLIT_REGION";
    }
  }
关注
打赏
1587549273
查看更多评论
立即登录/注册

微信扫码登录

0.0414s