HBase-1.2.1之查找Region位置的源码学习

首先需要清楚的是:

zookeeper上存放的是meta表在region的地址

真正的meta表数据是存放在region上的,和其他普通的数据表是一样的。

以get操作为例:

在HTable中的get方法中的
return rpcCallerFactory.<Result>newCaller().callWithRetries(callable,this.operationTimeout);

--->RpcRetryingCaller.java中的callWithRetries()方法

--->callable.prepare(tries !=0)

  --->RegionServerCallable.java中的prepare(finalBoolean reload)

    --->this.location= regionLocator.getRegionLocation(row,reload);

     --->connection.getRegionLocation(tableName,row,reload);//获得Region的位置

       --->…….

          --->ConnectionManager中的

               locateRegionInMeta(tableName,row,useCache,retry,replicaid);

                  --->regionInfoRow = rcs.next();1230

                      --->

                         --->ClientSmallReversedScanner.loadCache();(Meta表中查到位置)

       --->setStub(getConnection.getClient(this.location.getServerName()));

           --->getClient(finalServerName serverName);//建立到该regionserver的连接

 --->callable.call(getRemainingTime(callTimeout));

   --->HTable中的get方法中重写了该call方法:826行。

      --->ClientProtos.GetRequest request =RequestConverter.buildGetRequest(getLocation().getRegionInfo().getRegionName(), getReq);//注意此时已经得到了region的位置信息(在哪个regionserver上,且建好了连接)
        --->ClientProtos.GetResponse response = getStub().get(controller, request);
          --->RSRpcService中的get(final RpcController controller,
           final GetRequest request)
 
在找到region之后,调用callable的call方法中,给request传过去的是getLoaction().getRegionInfo().getRegionName();即传过去的是regionName。
RegionName的构成:看HRegionInfo中的createRegionName()方法。由此可见,在RegionName中包含的信息有表名tableName。
/**
 * Make a region name of passed parameters.
 * @param tableName
 * @param startKey Can be null
 * @param id Region id (Usually timestamp from when region was created).
 * @param replicaId
 * @param newFormat should we create the region name in the new format
 * @return Region name made of passed tableName, startKey, id and replicaId
 */
public static byte [] createRegionName(final TableName tableName,
    final byte [] startKey, final byte [] id, final int replicaId, boolean newFormat) 

猜你喜欢

转载自blog.csdn.net/mm_bit/article/details/52056808
今日推荐