首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Hbase region split源代码翻阅笔记

2012-06-26 
Hbase region split源代码阅读笔记客户端1. HbaseAdmin.split(final byte [] tableNameOrRegionName,final

Hbase region split源代码阅读笔记
客户端
1. HbaseAdmin.split(final byte [] tableNameOrRegionName,
      final byte [] splitPoint)

这个方法首先判断参数是regionName还是tableName;如果是regionName则只分裂该region,如果是tableName则分裂该表下的所有region

if (isRegionName(tableNameOrRegionName)) {//如果是regionName
        // Its a possible region name.
        Pair<HRegionInfo, HServerAddress> pair =
          MetaReader.getRegion(ct, tableNameOrRegionName);//读出regionInfo和RegionServerAddress
        if (pair == null || pair.getSecond() == null) {
          LOG.info("No server in .META. for " +
            Bytes.toStringBinary(tableNameOrRegionName) + "; pair=" + pair);
        } else {
          split(pair.getSecond(), pair.getFirst(), splitPoint);//调用方法分裂该region
        }
      } else {{//如果是tableName
        List<Pair<HRegionInfo, HServerAddress>> pairs =
          MetaReader.getTableRegionsAndLocations(ct,
              Bytes.toString(tableNameOrRegionName));//读出table下的一批region
        for (Pair<HRegionInfo, HServerAddress> pair: pairs) {
          // May not be a server for a particular row
          if (pair.getSecond() == null) continue;
          HRegionInfo r = pair.getFirst();
          // check for parents
          if (r.isSplitParent()) continue;
          if (splitPoint != null) {
            // if a split point given, only split that particular region
            if (!r.containsRow(splitPoint)) continue;
          }
          split(pair.getSecond(), pair.getFirst(), splitPoint);调用方法分裂这批region

        }

2. HbaseAdmin.split(final HServerAddress hsa, final HRegionInfo hri,
      byte[] splitPoint)

这只是个代理方法,调起regionserver的远程接口
    HRegionInterface rs = this.connection.getHRegionConnection(hsa);
    rs.splitRegion(hri, splitPoint);

RegionServer服务端
3.HRegionServer.splitRegion(HRegionInfo regionInfo, byte[] splitPoint)

    checkOpen();//检查regionserver是否停止
    HRegion region = getRegion(regionInfo.getRegionName());//拿到在线region
    region.flushcache();//写memstore到hfile
    region.forceSplit(splitPoint);//设置了两个值this.splitRequest=true    和 splitPoint = sp
    // force a compaction, split will be side-effect
    // TODO: flush/compact/split refactor will make it trivial to do this
    // sync/async (and won't require us to do a compaction to split!)
    compactSplitThread.requestCompaction(region, "User-triggered split",
        CompactSplitThread.PRIORITY_USER);//异步发起一个region的compact操作

热点排行