未完待更新
1)
ZooKeeper中/hbase/root-region-server保存了-ROOT-表所在的服务器地址
2)hbase采用两张系统表来支持分片数据查找
-ROOT-表 (.META.表所在的服务器地址, 一般系统只有一行记录 ) 5) 代码入口: HRegionLocation getRegionLocation(byte [] tableName, byte [] row, boolean reload)
6) HBase Definitive Guide : Region Lookups 图
1)retry connect : withRetries
public Result get(final Get get) throws IOException { return new ServerCallable<Result>(connection, tableName, get.getRow(), operationTimeout) { public Result call() throws IOException { return server.get(location.getRegionInfo().getRegionName(), get); } }.withRetries(); }
/** * Connect to the server hosting region with row from tablename. * @param reload Set this to true if connection should re-find the region * @throws IOException e */ public void connect(final boolean reload) throws IOException { this.location = connection.getRegionLocation(tableName, row, reload); this.server = connection.getHRegionConnection(location.getHostname(), location.getPort()); }
private HRegionLocation locateRegion(final byte [] tableName, final byte [] row, boolean useCache) throws IOException { .... if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) { ... ServerName servername = this.rootRegionTracker.getRootRegionLocation(); ... } ... } else { // Region not in the cache - have to go to the meta RS return locateRegionInMeta(HConstants.META_TABLE_NAME, tableName, row, useCache, userRegionLock); } }
/* * Search one of the meta tables (-ROOT- or .META.) for the HRegionLocation * info that contains the table and row we're seeking. */ private HRegionLocation locateRegionInMeta(final byte [] parentTable, final byte [] tableName, final byte [] row, boolean useCache, Object regionLockObject) throws IOException { ...... // This block guards against two threads trying to load the meta // region at the same time. The first will load the meta region and // the second will use the value that the first one found. synchronized (regionLockObject) { // If the parent table is META, we may want to pre-fetch some // region info into the global region cache for this table. if (Bytes.equals(parentTable, HConstants.META_TABLE_NAME) && (getRegionCachePrefetch(tableName)) ) { prefetchRegionCache(tableName, row); } ...... } ...... } }
private HRegionLocation locateRegion(final byte [] tableName, final byte [] row, boolean useCache) throws IOException { .... if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) { ... ServerName servername = this.rootRegionTracker.getRootRegionLocation(); ... } ... } else { // Region not in the cache - have to go to the meta RS return locateRegionInMeta(HConstants.META_TABLE_NAME, tableName, row, useCache, userRegionLock); } }
public synchronized byte [] getData(boolean refresh) { if (refresh) { try { this.data = ZKUtil.getDataAndWatch(watcher, node); } catch(KeeperException e) { abortable.abort("Unexpected exception handling getData", e); } } return this.data; }
private synchronized void ensureZookeeperTrackers() throws ZooKeeperConnectionException { ... if (rootRegionTracker == null) { rootRegionTracker = new RootRegionTracker(zooKeeper, this); rootRegionTracker.start(); } }