-<h2 id="源码分析"><a href="#源码分析" class="headerlink" title="源码分析"></a>源码分析</h2><p>HConnectionImplementation的locateRegion方法:<br><code><br>private HRegionLocation locateRegion(final byte [] tableName,<br> final byte [] row, boolean useCache, boolean retry)<br> throws IOException {<br> if (this.closed) throw new IOException(toString() + “ closed”);<br> if (tableName == null || tableName.length == 0) {<br> throw new IllegalArgumentException(<br> “table name cannot be null or zero length”);<br> }<br> ensureZookeeperTrackers();<br> if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) {<br> try {<br> ServerName servername = this.rootRegionTracker.waitRootRegionLocation(this.rpcTimeout);<br> LOG.debug(“Looked up root region location, connection=” + this +<br> “; serverName=” + ((servername == null)? “”: servername.toString()));<br> if (servername == null) return null;<br> return new HRegionLocation(HRegionInfo.ROOT_REGIONINFO,<br> servername.getHostname(), servername.getPort());<br> } catch (InterruptedException e) {<br> Thread.currentThread().interrupt();<br> return null;<br> }<br> } else if (Bytes.equals(tableName, HConstants.META_TABLE_NAME)) {<br> return locateRegionInMeta(HConstants.ROOT_TABLE_NAME, tableName, row,<br> useCache, metaRegionLock, retry);<br> } else {<br> // Region not in the cache - have to go to the meta RS<br> return locateRegionInMeta(HConstants.META_TABLE_NAME, tableName, row,<br> useCache, userRegionLock, retry);<br> }<br> }<br></code></p>
0 commit comments