hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [18/51] [partial] hbase-site git commit: Published site at 2a2258656b2fcd92b967131b6c1f037363553bc4.
Date Tue, 27 Mar 2018 14:48:42 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/e0fb1fde/devapidocs/src-html/org/apache/hadoop/hbase/client/ConnectionImplementation.MasterServiceStubMaker.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/client/ConnectionImplementation.MasterServiceStubMaker.html b/devapidocs/src-html/org/apache/hadoop/hbase/client/ConnectionImplementation.MasterServiceStubMaker.html
index d7aa8b1..98a45a0 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/client/ConnectionImplementation.MasterServiceStubMaker.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/client/ConnectionImplementation.MasterServiceStubMaker.html
@@ -680,1330 +680,1333 @@
 <span class="sourceLineNo">672</span>    }<a name="line.672"></a>
 <span class="sourceLineNo">673</span>    List&lt;HRegionLocation&gt; locations = new ArrayList&lt;&gt;();<a name="line.673"></a>
 <span class="sourceLineNo">674</span>    for (RegionInfo regionInfo : regions) {<a name="line.674"></a>
-<span class="sourceLineNo">675</span>      RegionLocations list = locateRegion(tableName, regionInfo.getStartKey(), useCache, true);<a name="line.675"></a>
-<span class="sourceLineNo">676</span>      if (list != null) {<a name="line.676"></a>
-<span class="sourceLineNo">677</span>        for (HRegionLocation loc : list.getRegionLocations()) {<a name="line.677"></a>
-<span class="sourceLineNo">678</span>          if (loc != null) {<a name="line.678"></a>
-<span class="sourceLineNo">679</span>            locations.add(loc);<a name="line.679"></a>
-<span class="sourceLineNo">680</span>          }<a name="line.680"></a>
-<span class="sourceLineNo">681</span>        }<a name="line.681"></a>
-<span class="sourceLineNo">682</span>      }<a name="line.682"></a>
-<span class="sourceLineNo">683</span>    }<a name="line.683"></a>
-<span class="sourceLineNo">684</span>    return locations;<a name="line.684"></a>
-<span class="sourceLineNo">685</span>  }<a name="line.685"></a>
-<span class="sourceLineNo">686</span><a name="line.686"></a>
-<span class="sourceLineNo">687</span>  @Override<a name="line.687"></a>
-<span class="sourceLineNo">688</span>  public HRegionLocation locateRegion(final TableName tableName, final byte[] row)<a name="line.688"></a>
-<span class="sourceLineNo">689</span>      throws IOException {<a name="line.689"></a>
-<span class="sourceLineNo">690</span>    RegionLocations locations = locateRegion(tableName, row, true, true);<a name="line.690"></a>
-<span class="sourceLineNo">691</span>    return locations == null ? null : locations.getRegionLocation();<a name="line.691"></a>
-<span class="sourceLineNo">692</span>  }<a name="line.692"></a>
-<span class="sourceLineNo">693</span><a name="line.693"></a>
-<span class="sourceLineNo">694</span>  @Override<a name="line.694"></a>
-<span class="sourceLineNo">695</span>  public HRegionLocation relocateRegion(final TableName tableName, final byte[] row)<a name="line.695"></a>
-<span class="sourceLineNo">696</span>      throws IOException {<a name="line.696"></a>
-<span class="sourceLineNo">697</span>    RegionLocations locations =<a name="line.697"></a>
-<span class="sourceLineNo">698</span>      relocateRegion(tableName, row, RegionReplicaUtil.DEFAULT_REPLICA_ID);<a name="line.698"></a>
-<span class="sourceLineNo">699</span>    return locations == null ? null<a name="line.699"></a>
-<span class="sourceLineNo">700</span>      : locations.getRegionLocation(RegionReplicaUtil.DEFAULT_REPLICA_ID);<a name="line.700"></a>
-<span class="sourceLineNo">701</span>  }<a name="line.701"></a>
-<span class="sourceLineNo">702</span><a name="line.702"></a>
-<span class="sourceLineNo">703</span>  @Override<a name="line.703"></a>
-<span class="sourceLineNo">704</span>  public RegionLocations relocateRegion(final TableName tableName,<a name="line.704"></a>
-<span class="sourceLineNo">705</span>      final byte [] row, int replicaId) throws IOException{<a name="line.705"></a>
-<span class="sourceLineNo">706</span>    // Since this is an explicit request not to use any caching, finding<a name="line.706"></a>
-<span class="sourceLineNo">707</span>    // disabled tables should not be desirable.  This will ensure that an exception is thrown when<a name="line.707"></a>
-<span class="sourceLineNo">708</span>    // the first time a disabled table is interacted with.<a name="line.708"></a>
-<span class="sourceLineNo">709</span>    if (!tableName.equals(TableName.META_TABLE_NAME) &amp;&amp; isTableDisabled(tableName)) {<a name="line.709"></a>
-<span class="sourceLineNo">710</span>      throw new TableNotEnabledException(tableName.getNameAsString() + " is disabled.");<a name="line.710"></a>
-<span class="sourceLineNo">711</span>    }<a name="line.711"></a>
-<span class="sourceLineNo">712</span><a name="line.712"></a>
-<span class="sourceLineNo">713</span>    return locateRegion(tableName, row, false, true, replicaId);<a name="line.713"></a>
-<span class="sourceLineNo">714</span>  }<a name="line.714"></a>
+<span class="sourceLineNo">675</span>      if (!RegionReplicaUtil.isDefaultReplica(regionInfo)) {<a name="line.675"></a>
+<span class="sourceLineNo">676</span>        continue;<a name="line.676"></a>
+<span class="sourceLineNo">677</span>      }<a name="line.677"></a>
+<span class="sourceLineNo">678</span>      RegionLocations list = locateRegion(tableName, regionInfo.getStartKey(), useCache, true);<a name="line.678"></a>
+<span class="sourceLineNo">679</span>      if (list != null) {<a name="line.679"></a>
+<span class="sourceLineNo">680</span>        for (HRegionLocation loc : list.getRegionLocations()) {<a name="line.680"></a>
+<span class="sourceLineNo">681</span>          if (loc != null) {<a name="line.681"></a>
+<span class="sourceLineNo">682</span>            locations.add(loc);<a name="line.682"></a>
+<span class="sourceLineNo">683</span>          }<a name="line.683"></a>
+<span class="sourceLineNo">684</span>        }<a name="line.684"></a>
+<span class="sourceLineNo">685</span>      }<a name="line.685"></a>
+<span class="sourceLineNo">686</span>    }<a name="line.686"></a>
+<span class="sourceLineNo">687</span>    return locations;<a name="line.687"></a>
+<span class="sourceLineNo">688</span>  }<a name="line.688"></a>
+<span class="sourceLineNo">689</span><a name="line.689"></a>
+<span class="sourceLineNo">690</span>  @Override<a name="line.690"></a>
+<span class="sourceLineNo">691</span>  public HRegionLocation locateRegion(final TableName tableName, final byte[] row)<a name="line.691"></a>
+<span class="sourceLineNo">692</span>      throws IOException {<a name="line.692"></a>
+<span class="sourceLineNo">693</span>    RegionLocations locations = locateRegion(tableName, row, true, true);<a name="line.693"></a>
+<span class="sourceLineNo">694</span>    return locations == null ? null : locations.getRegionLocation();<a name="line.694"></a>
+<span class="sourceLineNo">695</span>  }<a name="line.695"></a>
+<span class="sourceLineNo">696</span><a name="line.696"></a>
+<span class="sourceLineNo">697</span>  @Override<a name="line.697"></a>
+<span class="sourceLineNo">698</span>  public HRegionLocation relocateRegion(final TableName tableName, final byte[] row)<a name="line.698"></a>
+<span class="sourceLineNo">699</span>      throws IOException {<a name="line.699"></a>
+<span class="sourceLineNo">700</span>    RegionLocations locations =<a name="line.700"></a>
+<span class="sourceLineNo">701</span>      relocateRegion(tableName, row, RegionReplicaUtil.DEFAULT_REPLICA_ID);<a name="line.701"></a>
+<span class="sourceLineNo">702</span>    return locations == null ? null<a name="line.702"></a>
+<span class="sourceLineNo">703</span>      : locations.getRegionLocation(RegionReplicaUtil.DEFAULT_REPLICA_ID);<a name="line.703"></a>
+<span class="sourceLineNo">704</span>  }<a name="line.704"></a>
+<span class="sourceLineNo">705</span><a name="line.705"></a>
+<span class="sourceLineNo">706</span>  @Override<a name="line.706"></a>
+<span class="sourceLineNo">707</span>  public RegionLocations relocateRegion(final TableName tableName,<a name="line.707"></a>
+<span class="sourceLineNo">708</span>      final byte [] row, int replicaId) throws IOException{<a name="line.708"></a>
+<span class="sourceLineNo">709</span>    // Since this is an explicit request not to use any caching, finding<a name="line.709"></a>
+<span class="sourceLineNo">710</span>    // disabled tables should not be desirable.  This will ensure that an exception is thrown when<a name="line.710"></a>
+<span class="sourceLineNo">711</span>    // the first time a disabled table is interacted with.<a name="line.711"></a>
+<span class="sourceLineNo">712</span>    if (!tableName.equals(TableName.META_TABLE_NAME) &amp;&amp; isTableDisabled(tableName)) {<a name="line.712"></a>
+<span class="sourceLineNo">713</span>      throw new TableNotEnabledException(tableName.getNameAsString() + " is disabled.");<a name="line.713"></a>
+<span class="sourceLineNo">714</span>    }<a name="line.714"></a>
 <span class="sourceLineNo">715</span><a name="line.715"></a>
-<span class="sourceLineNo">716</span>  @Override<a name="line.716"></a>
-<span class="sourceLineNo">717</span>  public RegionLocations locateRegion(final TableName tableName, final byte[] row, boolean useCache,<a name="line.717"></a>
-<span class="sourceLineNo">718</span>      boolean retry) throws IOException {<a name="line.718"></a>
-<span class="sourceLineNo">719</span>    return locateRegion(tableName, row, useCache, retry, RegionReplicaUtil.DEFAULT_REPLICA_ID);<a name="line.719"></a>
-<span class="sourceLineNo">720</span>  }<a name="line.720"></a>
-<span class="sourceLineNo">721</span><a name="line.721"></a>
-<span class="sourceLineNo">722</span>  @Override<a name="line.722"></a>
-<span class="sourceLineNo">723</span>  public RegionLocations locateRegion(final TableName tableName, final byte[] row, boolean useCache,<a name="line.723"></a>
-<span class="sourceLineNo">724</span>      boolean retry, int replicaId) throws IOException {<a name="line.724"></a>
-<span class="sourceLineNo">725</span>    checkClosed();<a name="line.725"></a>
-<span class="sourceLineNo">726</span>    if (tableName == null || tableName.getName().length == 0) {<a name="line.726"></a>
-<span class="sourceLineNo">727</span>      throw new IllegalArgumentException("table name cannot be null or zero length");<a name="line.727"></a>
-<span class="sourceLineNo">728</span>    }<a name="line.728"></a>
-<span class="sourceLineNo">729</span>    if (tableName.equals(TableName.META_TABLE_NAME)) {<a name="line.729"></a>
-<span class="sourceLineNo">730</span>      return locateMeta(tableName, useCache, replicaId);<a name="line.730"></a>
-<span class="sourceLineNo">731</span>    } else {<a name="line.731"></a>
-<span class="sourceLineNo">732</span>      // Region not in the cache - have to go to the meta RS<a name="line.732"></a>
-<span class="sourceLineNo">733</span>      return locateRegionInMeta(tableName, row, useCache, retry, replicaId);<a name="line.733"></a>
-<span class="sourceLineNo">734</span>    }<a name="line.734"></a>
-<span class="sourceLineNo">735</span>  }<a name="line.735"></a>
-<span class="sourceLineNo">736</span><a name="line.736"></a>
-<span class="sourceLineNo">737</span>  private RegionLocations locateMeta(final TableName tableName,<a name="line.737"></a>
-<span class="sourceLineNo">738</span>      boolean useCache, int replicaId) throws IOException {<a name="line.738"></a>
-<span class="sourceLineNo">739</span>    // HBASE-10785: We cache the location of the META itself, so that we are not overloading<a name="line.739"></a>
-<span class="sourceLineNo">740</span>    // zookeeper with one request for every region lookup. We cache the META with empty row<a name="line.740"></a>
-<span class="sourceLineNo">741</span>    // key in MetaCache.<a name="line.741"></a>
-<span class="sourceLineNo">742</span>    byte[] metaCacheKey = HConstants.EMPTY_START_ROW; // use byte[0] as the row for meta<a name="line.742"></a>
-<span class="sourceLineNo">743</span>    RegionLocations locations = null;<a name="line.743"></a>
-<span class="sourceLineNo">744</span>    if (useCache) {<a name="line.744"></a>
-<span class="sourceLineNo">745</span>      locations = getCachedLocation(tableName, metaCacheKey);<a name="line.745"></a>
-<span class="sourceLineNo">746</span>      if (locations != null &amp;&amp; locations.getRegionLocation(replicaId) != null) {<a name="line.746"></a>
-<span class="sourceLineNo">747</span>        return locations;<a name="line.747"></a>
-<span class="sourceLineNo">748</span>      }<a name="line.748"></a>
-<span class="sourceLineNo">749</span>    }<a name="line.749"></a>
-<span class="sourceLineNo">750</span><a name="line.750"></a>
-<span class="sourceLineNo">751</span>    // only one thread should do the lookup.<a name="line.751"></a>
-<span class="sourceLineNo">752</span>    synchronized (metaRegionLock) {<a name="line.752"></a>
-<span class="sourceLineNo">753</span>      // Check the cache again for a hit in case some other thread made the<a name="line.753"></a>
-<span class="sourceLineNo">754</span>      // same query while we were waiting on the lock.<a name="line.754"></a>
-<span class="sourceLineNo">755</span>      if (useCache) {<a name="line.755"></a>
-<span class="sourceLineNo">756</span>        locations = getCachedLocation(tableName, metaCacheKey);<a name="line.756"></a>
-<span class="sourceLineNo">757</span>        if (locations != null &amp;&amp; locations.getRegionLocation(replicaId) != null) {<a name="line.757"></a>
-<span class="sourceLineNo">758</span>          return locations;<a name="line.758"></a>
-<span class="sourceLineNo">759</span>        }<a name="line.759"></a>
-<span class="sourceLineNo">760</span>      }<a name="line.760"></a>
-<span class="sourceLineNo">761</span><a name="line.761"></a>
-<span class="sourceLineNo">762</span>      // Look up from zookeeper<a name="line.762"></a>
-<span class="sourceLineNo">763</span>      locations = get(this.registry.getMetaRegionLocation());<a name="line.763"></a>
-<span class="sourceLineNo">764</span>      if (locations != null) {<a name="line.764"></a>
-<span class="sourceLineNo">765</span>        cacheLocation(tableName, locations);<a name="line.765"></a>
-<span class="sourceLineNo">766</span>      }<a name="line.766"></a>
-<span class="sourceLineNo">767</span>    }<a name="line.767"></a>
-<span class="sourceLineNo">768</span>    return locations;<a name="line.768"></a>
-<span class="sourceLineNo">769</span>  }<a name="line.769"></a>
-<span class="sourceLineNo">770</span><a name="line.770"></a>
-<span class="sourceLineNo">771</span>  /*<a name="line.771"></a>
-<span class="sourceLineNo">772</span>    * Search the hbase:meta table for the HRegionLocation<a name="line.772"></a>
-<span class="sourceLineNo">773</span>    * info that contains the table and row we're seeking.<a name="line.773"></a>
-<span class="sourceLineNo">774</span>    */<a name="line.774"></a>
-<span class="sourceLineNo">775</span>  private RegionLocations locateRegionInMeta(TableName tableName, byte[] row,<a name="line.775"></a>
-<span class="sourceLineNo">776</span>                 boolean useCache, boolean retry, int replicaId) throws IOException {<a name="line.776"></a>
-<span class="sourceLineNo">777</span><a name="line.777"></a>
-<span class="sourceLineNo">778</span>    // If we are supposed to be using the cache, look in the cache to see if<a name="line.778"></a>
-<span class="sourceLineNo">779</span>    // we already have the region.<a name="line.779"></a>
-<span class="sourceLineNo">780</span>    if (useCache) {<a name="line.780"></a>
-<span class="sourceLineNo">781</span>      RegionLocations locations = getCachedLocation(tableName, row);<a name="line.781"></a>
-<span class="sourceLineNo">782</span>      if (locations != null &amp;&amp; locations.getRegionLocation(replicaId) != null) {<a name="line.782"></a>
-<span class="sourceLineNo">783</span>        return locations;<a name="line.783"></a>
-<span class="sourceLineNo">784</span>      }<a name="line.784"></a>
-<span class="sourceLineNo">785</span>    }<a name="line.785"></a>
-<span class="sourceLineNo">786</span><a name="line.786"></a>
-<span class="sourceLineNo">787</span>    // build the key of the meta region we should be looking for.<a name="line.787"></a>
-<span class="sourceLineNo">788</span>    // the extra 9's on the end are necessary to allow "exact" matches<a name="line.788"></a>
-<span class="sourceLineNo">789</span>    // without knowing the precise region names.<a name="line.789"></a>
-<span class="sourceLineNo">790</span>    byte[] metaStartKey = RegionInfo.createRegionName(tableName, row, HConstants.NINES, false);<a name="line.790"></a>
-<span class="sourceLineNo">791</span>    byte[] metaStopKey =<a name="line.791"></a>
-<span class="sourceLineNo">792</span>      RegionInfo.createRegionName(tableName, HConstants.EMPTY_START_ROW, "", false);<a name="line.792"></a>
-<span class="sourceLineNo">793</span><a name="line.793"></a>
-<span class="sourceLineNo">794</span>    Scan s = new Scan();<a name="line.794"></a>
-<span class="sourceLineNo">795</span>    s.setReversed(true);<a name="line.795"></a>
-<span class="sourceLineNo">796</span>    s.withStartRow(metaStartKey);<a name="line.796"></a>
-<span class="sourceLineNo">797</span>    s.withStopRow(metaStopKey, true);<a name="line.797"></a>
-<span class="sourceLineNo">798</span>    s.addFamily(HConstants.CATALOG_FAMILY);<a name="line.798"></a>
-<span class="sourceLineNo">799</span><a name="line.799"></a>
-<span class="sourceLineNo">800</span>    if (this.useMetaReplicas) {<a name="line.800"></a>
-<span class="sourceLineNo">801</span>      s.setConsistency(Consistency.TIMELINE);<a name="line.801"></a>
-<span class="sourceLineNo">802</span>    }<a name="line.802"></a>
-<span class="sourceLineNo">803</span><a name="line.803"></a>
-<span class="sourceLineNo">804</span>    int maxAttempts = (retry ? numTries : 1);<a name="line.804"></a>
-<span class="sourceLineNo">805</span>    for (int tries = 0; true; tries++) {<a name="line.805"></a>
-<span class="sourceLineNo">806</span>      if (tries &gt;= maxAttempts) {<a name="line.806"></a>
-<span class="sourceLineNo">807</span>        throw new NoServerForRegionException("Unable to find region for "<a name="line.807"></a>
-<span class="sourceLineNo">808</span>            + Bytes.toStringBinary(row) + " in " + tableName + " after " + tries + " tries.");<a name="line.808"></a>
-<span class="sourceLineNo">809</span>      }<a name="line.809"></a>
-<span class="sourceLineNo">810</span>      if (useCache) {<a name="line.810"></a>
-<span class="sourceLineNo">811</span>        RegionLocations locations = getCachedLocation(tableName, row);<a name="line.811"></a>
-<span class="sourceLineNo">812</span>        if (locations != null &amp;&amp; locations.getRegionLocation(replicaId) != null) {<a name="line.812"></a>
-<span class="sourceLineNo">813</span>          return locations;<a name="line.813"></a>
-<span class="sourceLineNo">814</span>        }<a name="line.814"></a>
-<span class="sourceLineNo">815</span>      } else {<a name="line.815"></a>
-<span class="sourceLineNo">816</span>        // If we are not supposed to be using the cache, delete any existing cached location<a name="line.816"></a>
-<span class="sourceLineNo">817</span>        // so it won't interfere.<a name="line.817"></a>
-<span class="sourceLineNo">818</span>        // We are only supposed to clean the cache for the specific replicaId<a name="line.818"></a>
-<span class="sourceLineNo">819</span>        metaCache.clearCache(tableName, row, replicaId);<a name="line.819"></a>
-<span class="sourceLineNo">820</span>      }<a name="line.820"></a>
-<span class="sourceLineNo">821</span><a name="line.821"></a>
-<span class="sourceLineNo">822</span>      // Query the meta region<a name="line.822"></a>
-<span class="sourceLineNo">823</span>      long pauseBase = this.pause;<a name="line.823"></a>
-<span class="sourceLineNo">824</span>      userRegionLock.lock();<a name="line.824"></a>
-<span class="sourceLineNo">825</span>      try {<a name="line.825"></a>
-<span class="sourceLineNo">826</span>        if (useCache) {// re-check cache after get lock<a name="line.826"></a>
-<span class="sourceLineNo">827</span>          RegionLocations locations = getCachedLocation(tableName, row);<a name="line.827"></a>
-<span class="sourceLineNo">828</span>          if (locations != null &amp;&amp; locations.getRegionLocation(replicaId) != null) {<a name="line.828"></a>
-<span class="sourceLineNo">829</span>            return locations;<a name="line.829"></a>
-<span class="sourceLineNo">830</span>          }<a name="line.830"></a>
-<span class="sourceLineNo">831</span>        }<a name="line.831"></a>
-<span class="sourceLineNo">832</span>        Result regionInfoRow = null;<a name="line.832"></a>
-<span class="sourceLineNo">833</span>        s.resetMvccReadPoint();<a name="line.833"></a>
-<span class="sourceLineNo">834</span>        s.setOneRowLimit();<a name="line.834"></a>
-<span class="sourceLineNo">835</span>        try (ReversedClientScanner rcs =<a name="line.835"></a>
-<span class="sourceLineNo">836</span>            new ReversedClientScanner(conf, s, TableName.META_TABLE_NAME, this, rpcCallerFactory,<a name="line.836"></a>
-<span class="sourceLineNo">837</span>                rpcControllerFactory, getMetaLookupPool(), metaReplicaCallTimeoutScanInMicroSecond)) {<a name="line.837"></a>
-<span class="sourceLineNo">838</span>          regionInfoRow = rcs.next();<a name="line.838"></a>
-<span class="sourceLineNo">839</span>        }<a name="line.839"></a>
-<span class="sourceLineNo">840</span><a name="line.840"></a>
-<span class="sourceLineNo">841</span>        if (regionInfoRow == null) {<a name="line.841"></a>
-<span class="sourceLineNo">842</span>          throw new TableNotFoundException(tableName);<a name="line.842"></a>
-<span class="sourceLineNo">843</span>        }<a name="line.843"></a>
-<span class="sourceLineNo">844</span>        // convert the row result into the HRegionLocation we need!<a name="line.844"></a>
-<span class="sourceLineNo">845</span>        RegionLocations locations = MetaTableAccessor.getRegionLocations(regionInfoRow);<a name="line.845"></a>
-<span class="sourceLineNo">846</span>        if (locations == null || locations.getRegionLocation(replicaId) == null) {<a name="line.846"></a>
-<span class="sourceLineNo">847</span>          throw new IOException("RegionInfo null in " + tableName + ", row=" + regionInfoRow);<a name="line.847"></a>
-<span class="sourceLineNo">848</span>        }<a name="line.848"></a>
-<span class="sourceLineNo">849</span>        RegionInfo regionInfo = locations.getRegionLocation(replicaId).getRegion();<a name="line.849"></a>
-<span class="sourceLineNo">850</span>        if (regionInfo == null) {<a name="line.850"></a>
-<span class="sourceLineNo">851</span>          throw new IOException("RegionInfo null or empty in " +<a name="line.851"></a>
-<span class="sourceLineNo">852</span>            TableName.META_TABLE_NAME + ", row=" + regionInfoRow);<a name="line.852"></a>
-<span class="sourceLineNo">853</span>        }<a name="line.853"></a>
-<span class="sourceLineNo">854</span><a name="line.854"></a>
-<span class="sourceLineNo">855</span>        // possible we got a region of a different table...<a name="line.855"></a>
-<span class="sourceLineNo">856</span>        if (!regionInfo.getTable().equals(tableName)) {<a name="line.856"></a>
-<span class="sourceLineNo">857</span>          throw new TableNotFoundException(<a name="line.857"></a>
-<span class="sourceLineNo">858</span>            "Region of '" + regionInfo.getRegionNameAsString() + "' is expected in the table of '" + tableName + "', " +<a name="line.858"></a>
-<span class="sourceLineNo">859</span>            "but hbase:meta says it is in the table of '" + regionInfo.getTable() + "'. " +<a name="line.859"></a>
-<span class="sourceLineNo">860</span>            "hbase:meta might be damaged.");<a name="line.860"></a>
-<span class="sourceLineNo">861</span>        }<a name="line.861"></a>
-<span class="sourceLineNo">862</span>        if (regionInfo.isSplit()) {<a name="line.862"></a>
-<span class="sourceLineNo">863</span>          throw new RegionOfflineException ("Region for row is a split parent, daughters not online: " +<a name="line.863"></a>
-<span class="sourceLineNo">864</span>              regionInfo.getRegionNameAsString());<a name="line.864"></a>
-<span class="sourceLineNo">865</span>        }<a name="line.865"></a>
-<span class="sourceLineNo">866</span>        if (regionInfo.isOffline()) {<a name="line.866"></a>
-<span class="sourceLineNo">867</span>          throw new RegionOfflineException("Region offline; disable table call? " +<a name="line.867"></a>
-<span class="sourceLineNo">868</span>              regionInfo.getRegionNameAsString());<a name="line.868"></a>
-<span class="sourceLineNo">869</span>        }<a name="line.869"></a>
-<span class="sourceLineNo">870</span><a name="line.870"></a>
-<span class="sourceLineNo">871</span>        ServerName serverName = locations.getRegionLocation(replicaId).getServerName();<a name="line.871"></a>
-<span class="sourceLineNo">872</span>        if (serverName == null) {<a name="line.872"></a>
-<span class="sourceLineNo">873</span>          throw new NoServerForRegionException("No server address listed in "<a name="line.873"></a>
-<span class="sourceLineNo">874</span>              + TableName.META_TABLE_NAME + " for region " + regionInfo.getRegionNameAsString()<a name="line.874"></a>
-<span class="sourceLineNo">875</span>              + " containing row " + Bytes.toStringBinary(row));<a name="line.875"></a>
-<span class="sourceLineNo">876</span>        }<a name="line.876"></a>
-<span class="sourceLineNo">877</span><a name="line.877"></a>
-<span class="sourceLineNo">878</span>        if (isDeadServer(serverName)){<a name="line.878"></a>
-<span class="sourceLineNo">879</span>          throw new RegionServerStoppedException("hbase:meta says the region "+<a name="line.879"></a>
-<span class="sourceLineNo">880</span>              regionInfo.getRegionNameAsString()+" is managed by the server " + serverName +<a name="line.880"></a>
-<span class="sourceLineNo">881</span>              ", but it is dead.");<a name="line.881"></a>
-<span class="sourceLineNo">882</span>        }<a name="line.882"></a>
-<span class="sourceLineNo">883</span>        // Instantiate the location<a name="line.883"></a>
-<span class="sourceLineNo">884</span>        cacheLocation(tableName, locations);<a name="line.884"></a>
-<span class="sourceLineNo">885</span>        return locations;<a name="line.885"></a>
-<span class="sourceLineNo">886</span>      } catch (TableNotFoundException e) {<a name="line.886"></a>
-<span class="sourceLineNo">887</span>        // if we got this error, probably means the table just plain doesn't<a name="line.887"></a>
-<span class="sourceLineNo">888</span>        // exist. rethrow the error immediately. this should always be coming<a name="line.888"></a>
-<span class="sourceLineNo">889</span>        // from the HTable constructor.<a name="line.889"></a>
-<span class="sourceLineNo">890</span>        throw e;<a name="line.890"></a>
-<span class="sourceLineNo">891</span>      } catch (IOException e) {<a name="line.891"></a>
-<span class="sourceLineNo">892</span>        ExceptionUtil.rethrowIfInterrupt(e);<a name="line.892"></a>
-<span class="sourceLineNo">893</span>        if (e instanceof RemoteException) {<a name="line.893"></a>
-<span class="sourceLineNo">894</span>          e = ((RemoteException)e).unwrapRemoteException();<a name="line.894"></a>
-<span class="sourceLineNo">895</span>        }<a name="line.895"></a>
-<span class="sourceLineNo">896</span>        if (e instanceof CallQueueTooBigException) {<a name="line.896"></a>
-<span class="sourceLineNo">897</span>          // Give a special check on CallQueueTooBigException, see #HBASE-17114<a name="line.897"></a>
-<span class="sourceLineNo">898</span>          pauseBase = this.pauseForCQTBE;<a name="line.898"></a>
-<span class="sourceLineNo">899</span>        }<a name="line.899"></a>
-<span class="sourceLineNo">900</span>        if (tries &lt; maxAttempts - 1) {<a name="line.900"></a>
-<span class="sourceLineNo">901</span>          if (LOG.isDebugEnabled()) {<a name="line.901"></a>
-<span class="sourceLineNo">902</span>            LOG.debug("locateRegionInMeta parentTable=" + TableName.META_TABLE_NAME<a name="line.902"></a>
-<span class="sourceLineNo">903</span>                + ", metaLocation=" + ", attempt=" + tries + " of " + maxAttempts<a name="line.903"></a>
-<span class="sourceLineNo">904</span>                + " failed; retrying after sleep of "<a name="line.904"></a>
-<span class="sourceLineNo">905</span>                + ConnectionUtils.getPauseTime(pauseBase, tries) + " because: " + e.getMessage());<a name="line.905"></a>
-<span class="sourceLineNo">906</span>          }<a name="line.906"></a>
-<span class="sourceLineNo">907</span>        } else {<a name="line.907"></a>
-<span class="sourceLineNo">908</span>          throw e;<a name="line.908"></a>
-<span class="sourceLineNo">909</span>        }<a name="line.909"></a>
-<span class="sourceLineNo">910</span>        // Only relocate the parent region if necessary<a name="line.910"></a>
-<span class="sourceLineNo">911</span>        if(!(e instanceof RegionOfflineException ||<a name="line.911"></a>
-<span class="sourceLineNo">912</span>            e instanceof NoServerForRegionException)) {<a name="line.912"></a>
-<span class="sourceLineNo">913</span>          relocateRegion(TableName.META_TABLE_NAME, metaStartKey, replicaId);<a name="line.913"></a>
-<span class="sourceLineNo">914</span>        }<a name="line.914"></a>
-<span class="sourceLineNo">915</span>      } finally {<a name="line.915"></a>
-<span class="sourceLineNo">916</span>        userRegionLock.unlock();<a name="line.916"></a>
-<span class="sourceLineNo">917</span>      }<a name="line.917"></a>
-<span class="sourceLineNo">918</span>      try{<a name="line.918"></a>
-<span class="sourceLineNo">919</span>        Thread.sleep(ConnectionUtils.getPauseTime(pauseBase, tries));<a name="line.919"></a>
-<span class="sourceLineNo">920</span>      } catch (InterruptedException e) {<a name="line.920"></a>
-<span class="sourceLineNo">921</span>        throw new InterruptedIOException("Giving up trying to location region in " +<a name="line.921"></a>
-<span class="sourceLineNo">922</span>          "meta: thread is interrupted.");<a name="line.922"></a>
-<span class="sourceLineNo">923</span>      }<a name="line.923"></a>
-<span class="sourceLineNo">924</span>    }<a name="line.924"></a>
-<span class="sourceLineNo">925</span>  }<a name="line.925"></a>
-<span class="sourceLineNo">926</span><a name="line.926"></a>
-<span class="sourceLineNo">927</span>  /**<a name="line.927"></a>
-<span class="sourceLineNo">928</span>   * Put a newly discovered HRegionLocation into the cache.<a name="line.928"></a>
-<span class="sourceLineNo">929</span>   * @param tableName The table name.<a name="line.929"></a>
-<span class="sourceLineNo">930</span>   * @param location the new location<a name="line.930"></a>
-<span class="sourceLineNo">931</span>   */<a name="line.931"></a>
-<span class="sourceLineNo">932</span>  @Override<a name="line.932"></a>
-<span class="sourceLineNo">933</span>  public void cacheLocation(final TableName tableName, final RegionLocations location) {<a name="line.933"></a>
-<span class="sourceLineNo">934</span>    metaCache.cacheLocation(tableName, location);<a name="line.934"></a>
-<span class="sourceLineNo">935</span>  }<a name="line.935"></a>
-<span class="sourceLineNo">936</span><a name="line.936"></a>
-<span class="sourceLineNo">937</span>  /**<a name="line.937"></a>
-<span class="sourceLineNo">938</span>   * Search the cache for a location that fits our table and row key.<a name="line.938"></a>
-<span class="sourceLineNo">939</span>   * Return null if no suitable region is located.<a name="line.939"></a>
-<span class="sourceLineNo">940</span>   * @return Null or region location found in cache.<a name="line.940"></a>
-<span class="sourceLineNo">941</span>   */<a name="line.941"></a>
-<span class="sourceLineNo">942</span>  RegionLocations getCachedLocation(final TableName tableName,<a name="line.942"></a>
-<span class="sourceLineNo">943</span>      final byte [] row) {<a name="line.943"></a>
-<span class="sourceLineNo">944</span>    return metaCache.getCachedLocation(tableName, row);<a name="line.944"></a>
-<span class="sourceLineNo">945</span>  }<a name="line.945"></a>
-<span class="sourceLineNo">946</span><a name="line.946"></a>
-<span class="sourceLineNo">947</span>  public void clearRegionCache(final TableName tableName, byte[] row) {<a name="line.947"></a>
-<span class="sourceLineNo">948</span>    metaCache.clearCache(tableName, row);<a name="line.948"></a>
-<span class="sourceLineNo">949</span>  }<a name="line.949"></a>
-<span class="sourceLineNo">950</span><a name="line.950"></a>
-<span class="sourceLineNo">951</span>  /*<a name="line.951"></a>
-<span class="sourceLineNo">952</span>   * Delete all cached entries of a table that maps to a specific location.<a name="line.952"></a>
-<span class="sourceLineNo">953</span>   */<a name="line.953"></a>
-<span class="sourceLineNo">954</span>  @Override<a name="line.954"></a>
-<span class="sourceLineNo">955</span>  public void clearCaches(final ServerName serverName) {<a name="line.955"></a>
-<span class="sourceLineNo">956</span>    metaCache.clearCache(serverName);<a name="line.956"></a>
-<span class="sourceLineNo">957</span>  }<a name="line.957"></a>
-<span class="sourceLineNo">958</span><a name="line.958"></a>
-<span class="sourceLineNo">959</span>  @Override<a name="line.959"></a>
-<span class="sourceLineNo">960</span>  public void clearRegionCache() {<a name="line.960"></a>
-<span class="sourceLineNo">961</span>    metaCache.clearCache();<a name="line.961"></a>
-<span class="sourceLineNo">962</span>  }<a name="line.962"></a>
-<span class="sourceLineNo">963</span><a name="line.963"></a>
-<span class="sourceLineNo">964</span>  @Override<a name="line.964"></a>
-<span class="sourceLineNo">965</span>  public void clearRegionCache(final TableName tableName) {<a name="line.965"></a>
-<span class="sourceLineNo">966</span>    metaCache.clearCache(tableName);<a name="line.966"></a>
-<span class="sourceLineNo">967</span>  }<a name="line.967"></a>
-<span class="sourceLineNo">968</span><a name="line.968"></a>
-<span class="sourceLineNo">969</span>  /**<a name="line.969"></a>
-<span class="sourceLineNo">970</span>   * Put a newly discovered HRegionLocation into the cache.<a name="line.970"></a>
-<span class="sourceLineNo">971</span>   * @param tableName The table name.<a name="line.971"></a>
-<span class="sourceLineNo">972</span>   * @param source the source of the new location, if it's not coming from meta<a name="line.972"></a>
-<span class="sourceLineNo">973</span>   * @param location the new location<a name="line.973"></a>
-<span class="sourceLineNo">974</span>   */<a name="line.974"></a>
-<span class="sourceLineNo">975</span>  private void cacheLocation(final TableName tableName, final ServerName source,<a name="line.975"></a>
-<span class="sourceLineNo">976</span>      final HRegionLocation location) {<a name="line.976"></a>
-<span class="sourceLineNo">977</span>    metaCache.cacheLocation(tableName, source, location);<a name="line.977"></a>
-<span class="sourceLineNo">978</span>  }<a name="line.978"></a>
-<span class="sourceLineNo">979</span><a name="line.979"></a>
-<span class="sourceLineNo">980</span>  // Map keyed by service name + regionserver to service stub implementation<a name="line.980"></a>
-<span class="sourceLineNo">981</span>  private final ConcurrentMap&lt;String, Object&gt; stubs = new ConcurrentHashMap&lt;&gt;();<a name="line.981"></a>
+<span class="sourceLineNo">716</span>    return locateRegion(tableName, row, false, true, replicaId);<a name="line.716"></a>
+<span class="sourceLineNo">717</span>  }<a name="line.717"></a>
+<span class="sourceLineNo">718</span><a name="line.718"></a>
+<span class="sourceLineNo">719</span>  @Override<a name="line.719"></a>
+<span class="sourceLineNo">720</span>  public RegionLocations locateRegion(final TableName tableName, final byte[] row, boolean useCache,<a name="line.720"></a>
+<span class="sourceLineNo">721</span>      boolean retry) throws IOException {<a name="line.721"></a>
+<span class="sourceLineNo">722</span>    return locateRegion(tableName, row, useCache, retry, RegionReplicaUtil.DEFAULT_REPLICA_ID);<a name="line.722"></a>
+<span class="sourceLineNo">723</span>  }<a name="line.723"></a>
+<span class="sourceLineNo">724</span><a name="line.724"></a>
+<span class="sourceLineNo">725</span>  @Override<a name="line.725"></a>
+<span class="sourceLineNo">726</span>  public RegionLocations locateRegion(final TableName tableName, final byte[] row, boolean useCache,<a name="line.726"></a>
+<span class="sourceLineNo">727</span>      boolean retry, int replicaId) throws IOException {<a name="line.727"></a>
+<span class="sourceLineNo">728</span>    checkClosed();<a name="line.728"></a>
+<span class="sourceLineNo">729</span>    if (tableName == null || tableName.getName().length == 0) {<a name="line.729"></a>
+<span class="sourceLineNo">730</span>      throw new IllegalArgumentException("table name cannot be null or zero length");<a name="line.730"></a>
+<span class="sourceLineNo">731</span>    }<a name="line.731"></a>
+<span class="sourceLineNo">732</span>    if (tableName.equals(TableName.META_TABLE_NAME)) {<a name="line.732"></a>
+<span class="sourceLineNo">733</span>      return locateMeta(tableName, useCache, replicaId);<a name="line.733"></a>
+<span class="sourceLineNo">734</span>    } else {<a name="line.734"></a>
+<span class="sourceLineNo">735</span>      // Region not in the cache - have to go to the meta RS<a name="line.735"></a>
+<span class="sourceLineNo">736</span>      return locateRegionInMeta(tableName, row, useCache, retry, replicaId);<a name="line.736"></a>
+<span class="sourceLineNo">737</span>    }<a name="line.737"></a>
+<span class="sourceLineNo">738</span>  }<a name="line.738"></a>
+<span class="sourceLineNo">739</span><a name="line.739"></a>
+<span class="sourceLineNo">740</span>  private RegionLocations locateMeta(final TableName tableName,<a name="line.740"></a>
+<span class="sourceLineNo">741</span>      boolean useCache, int replicaId) throws IOException {<a name="line.741"></a>
+<span class="sourceLineNo">742</span>    // HBASE-10785: We cache the location of the META itself, so that we are not overloading<a name="line.742"></a>
+<span class="sourceLineNo">743</span>    // zookeeper with one request for every region lookup. We cache the META with empty row<a name="line.743"></a>
+<span class="sourceLineNo">744</span>    // key in MetaCache.<a name="line.744"></a>
+<span class="sourceLineNo">745</span>    byte[] metaCacheKey = HConstants.EMPTY_START_ROW; // use byte[0] as the row for meta<a name="line.745"></a>
+<span class="sourceLineNo">746</span>    RegionLocations locations = null;<a name="line.746"></a>
+<span class="sourceLineNo">747</span>    if (useCache) {<a name="line.747"></a>
+<span class="sourceLineNo">748</span>      locations = getCachedLocation(tableName, metaCacheKey);<a name="line.748"></a>
+<span class="sourceLineNo">749</span>      if (locations != null &amp;&amp; locations.getRegionLocation(replicaId) != null) {<a name="line.749"></a>
+<span class="sourceLineNo">750</span>        return locations;<a name="line.750"></a>
+<span class="sourceLineNo">751</span>      }<a name="line.751"></a>
+<span class="sourceLineNo">752</span>    }<a name="line.752"></a>
+<span class="sourceLineNo">753</span><a name="line.753"></a>
+<span class="sourceLineNo">754</span>    // only one thread should do the lookup.<a name="line.754"></a>
+<span class="sourceLineNo">755</span>    synchronized (metaRegionLock) {<a name="line.755"></a>
+<span class="sourceLineNo">756</span>      // Check the cache again for a hit in case some other thread made the<a name="line.756"></a>
+<span class="sourceLineNo">757</span>      // same query while we were waiting on the lock.<a name="line.757"></a>
+<span class="sourceLineNo">758</span>      if (useCache) {<a name="line.758"></a>
+<span class="sourceLineNo">759</span>        locations = getCachedLocation(tableName, metaCacheKey);<a name="line.759"></a>
+<span class="sourceLineNo">760</span>        if (locations != null &amp;&amp; locations.getRegionLocation(replicaId) != null) {<a name="line.760"></a>
+<span class="sourceLineNo">761</span>          return locations;<a name="line.761"></a>
+<span class="sourceLineNo">762</span>        }<a name="line.762"></a>
+<span class="sourceLineNo">763</span>      }<a name="line.763"></a>
+<span class="sourceLineNo">764</span><a name="line.764"></a>
+<span class="sourceLineNo">765</span>      // Look up from zookeeper<a name="line.765"></a>
+<span class="sourceLineNo">766</span>      locations = get(this.registry.getMetaRegionLocation());<a name="line.766"></a>
+<span class="sourceLineNo">767</span>      if (locations != null) {<a name="line.767"></a>
+<span class="sourceLineNo">768</span>        cacheLocation(tableName, locations);<a name="line.768"></a>
+<span class="sourceLineNo">769</span>      }<a name="line.769"></a>
+<span class="sourceLineNo">770</span>    }<a name="line.770"></a>
+<span class="sourceLineNo">771</span>    return locations;<a name="line.771"></a>
+<span class="sourceLineNo">772</span>  }<a name="line.772"></a>
+<span class="sourceLineNo">773</span><a name="line.773"></a>
+<span class="sourceLineNo">774</span>  /*<a name="line.774"></a>
+<span class="sourceLineNo">775</span>    * Search the hbase:meta table for the HRegionLocation<a name="line.775"></a>
+<span class="sourceLineNo">776</span>    * info that contains the table and row we're seeking.<a name="line.776"></a>
+<span class="sourceLineNo">777</span>    */<a name="line.777"></a>
+<span class="sourceLineNo">778</span>  private RegionLocations locateRegionInMeta(TableName tableName, byte[] row,<a name="line.778"></a>
+<span class="sourceLineNo">779</span>                 boolean useCache, boolean retry, int replicaId) throws IOException {<a name="line.779"></a>
+<span class="sourceLineNo">780</span><a name="line.780"></a>
+<span class="sourceLineNo">781</span>    // If we are supposed to be using the cache, look in the cache to see if<a name="line.781"></a>
+<span class="sourceLineNo">782</span>    // we already have the region.<a name="line.782"></a>
+<span class="sourceLineNo">783</span>    if (useCache) {<a name="line.783"></a>
+<span class="sourceLineNo">784</span>      RegionLocations locations = getCachedLocation(tableName, row);<a name="line.784"></a>
+<span class="sourceLineNo">785</span>      if (locations != null &amp;&amp; locations.getRegionLocation(replicaId) != null) {<a name="line.785"></a>
+<span class="sourceLineNo">786</span>        return locations;<a name="line.786"></a>
+<span class="sourceLineNo">787</span>      }<a name="line.787"></a>
+<span class="sourceLineNo">788</span>    }<a name="line.788"></a>
+<span class="sourceLineNo">789</span><a name="line.789"></a>
+<span class="sourceLineNo">790</span>    // build the key of the meta region we should be looking for.<a name="line.790"></a>
+<span class="sourceLineNo">791</span>    // the extra 9's on the end are necessary to allow "exact" matches<a name="line.791"></a>
+<span class="sourceLineNo">792</span>    // without knowing the precise region names.<a name="line.792"></a>
+<span class="sourceLineNo">793</span>    byte[] metaStartKey = RegionInfo.createRegionName(tableName, row, HConstants.NINES, false);<a name="line.793"></a>
+<span class="sourceLineNo">794</span>    byte[] metaStopKey =<a name="line.794"></a>
+<span class="sourceLineNo">795</span>      RegionInfo.createRegionName(tableName, HConstants.EMPTY_START_ROW, "", false);<a name="line.795"></a>
+<span class="sourceLineNo">796</span><a name="line.796"></a>
+<span class="sourceLineNo">797</span>    Scan s = new Scan();<a name="line.797"></a>
+<span class="sourceLineNo">798</span>    s.setReversed(true);<a name="line.798"></a>
+<span class="sourceLineNo">799</span>    s.withStartRow(metaStartKey);<a name="line.799"></a>
+<span class="sourceLineNo">800</span>    s.withStopRow(metaStopKey, true);<a name="line.800"></a>
+<span class="sourceLineNo">801</span>    s.addFamily(HConstants.CATALOG_FAMILY);<a name="line.801"></a>
+<span class="sourceLineNo">802</span><a name="line.802"></a>
+<span class="sourceLineNo">803</span>    if (this.useMetaReplicas) {<a name="line.803"></a>
+<span class="sourceLineNo">804</span>      s.setConsistency(Consistency.TIMELINE);<a name="line.804"></a>
+<span class="sourceLineNo">805</span>    }<a name="line.805"></a>
+<span class="sourceLineNo">806</span><a name="line.806"></a>
+<span class="sourceLineNo">807</span>    int maxAttempts = (retry ? numTries : 1);<a name="line.807"></a>
+<span class="sourceLineNo">808</span>    for (int tries = 0; true; tries++) {<a name="line.808"></a>
+<span class="sourceLineNo">809</span>      if (tries &gt;= maxAttempts) {<a name="line.809"></a>
+<span class="sourceLineNo">810</span>        throw new NoServerForRegionException("Unable to find region for "<a name="line.810"></a>
+<span class="sourceLineNo">811</span>            + Bytes.toStringBinary(row) + " in " + tableName + " after " + tries + " tries.");<a name="line.811"></a>
+<span class="sourceLineNo">812</span>      }<a name="line.812"></a>
+<span class="sourceLineNo">813</span>      if (useCache) {<a name="line.813"></a>
+<span class="sourceLineNo">814</span>        RegionLocations locations = getCachedLocation(tableName, row);<a name="line.814"></a>
+<span class="sourceLineNo">815</span>        if (locations != null &amp;&amp; locations.getRegionLocation(replicaId) != null) {<a name="line.815"></a>
+<span class="sourceLineNo">816</span>          return locations;<a name="line.816"></a>
+<span class="sourceLineNo">817</span>        }<a name="line.817"></a>
+<span class="sourceLineNo">818</span>      } else {<a name="line.818"></a>
+<span class="sourceLineNo">819</span>        // If we are not supposed to be using the cache, delete any existing cached location<a name="line.819"></a>
+<span class="sourceLineNo">820</span>        // so it won't interfere.<a name="line.820"></a>
+<span class="sourceLineNo">821</span>        // We are only supposed to clean the cache for the specific replicaId<a name="line.821"></a>
+<span class="sourceLineNo">822</span>        metaCache.clearCache(tableName, row, replicaId);<a name="line.822"></a>
+<span class="sourceLineNo">823</span>      }<a name="line.823"></a>
+<span class="sourceLineNo">824</span><a name="line.824"></a>
+<span class="sourceLineNo">825</span>      // Query the meta region<a name="line.825"></a>
+<span class="sourceLineNo">826</span>      long pauseBase = this.pause;<a name="line.826"></a>
+<span class="sourceLineNo">827</span>      userRegionLock.lock();<a name="line.827"></a>
+<span class="sourceLineNo">828</span>      try {<a name="line.828"></a>
+<span class="sourceLineNo">829</span>        if (useCache) {// re-check cache after get lock<a name="line.829"></a>
+<span class="sourceLineNo">830</span>          RegionLocations locations = getCachedLocation(tableName, row);<a name="line.830"></a>
+<span class="sourceLineNo">831</span>          if (locations != null &amp;&amp; locations.getRegionLocation(replicaId) != null) {<a name="line.831"></a>
+<span class="sourceLineNo">832</span>            return locations;<a name="line.832"></a>
+<span class="sourceLineNo">833</span>          }<a name="line.833"></a>
+<span class="sourceLineNo">834</span>        }<a name="line.834"></a>
+<span class="sourceLineNo">835</span>        Result regionInfoRow = null;<a name="line.835"></a>
+<span class="sourceLineNo">836</span>        s.resetMvccReadPoint();<a name="line.836"></a>
+<span class="sourceLineNo">837</span>        s.setOneRowLimit();<a name="line.837"></a>
+<span class="sourceLineNo">838</span>        try (ReversedClientScanner rcs =<a name="line.838"></a>
+<span class="sourceLineNo">839</span>            new ReversedClientScanner(conf, s, TableName.META_TABLE_NAME, this, rpcCallerFactory,<a name="line.839"></a>
+<span class="sourceLineNo">840</span>                rpcControllerFactory, getMetaLookupPool(), metaReplicaCallTimeoutScanInMicroSecond)) {<a name="line.840"></a>
+<span class="sourceLineNo">841</span>          regionInfoRow = rcs.next();<a name="line.841"></a>
+<span class="sourceLineNo">842</span>        }<a name="line.842"></a>
+<span class="sourceLineNo">843</span><a name="line.843"></a>
+<span class="sourceLineNo">844</span>        if (regionInfoRow == null) {<a name="line.844"></a>
+<span class="sourceLineNo">845</span>          throw new TableNotFoundException(tableName);<a name="line.845"></a>
+<span class="sourceLineNo">846</span>        }<a name="line.846"></a>
+<span class="sourceLineNo">847</span>        // convert the row result into the HRegionLocation we need!<a name="line.847"></a>
+<span class="sourceLineNo">848</span>        RegionLocations locations = MetaTableAccessor.getRegionLocations(regionInfoRow);<a name="line.848"></a>
+<span class="sourceLineNo">849</span>        if (locations == null || locations.getRegionLocation(replicaId) == null) {<a name="line.849"></a>
+<span class="sourceLineNo">850</span>          throw new IOException("RegionInfo null in " + tableName + ", row=" + regionInfoRow);<a name="line.850"></a>
+<span class="sourceLineNo">851</span>        }<a name="line.851"></a>
+<span class="sourceLineNo">852</span>        RegionInfo regionInfo = locations.getRegionLocation(replicaId).getRegion();<a name="line.852"></a>
+<span class="sourceLineNo">853</span>        if (regionInfo == null) {<a name="line.853"></a>
+<span class="sourceLineNo">854</span>          throw new IOException("RegionInfo null or empty in " +<a name="line.854"></a>
+<span class="sourceLineNo">855</span>            TableName.META_TABLE_NAME + ", row=" + regionInfoRow);<a name="line.855"></a>
+<span class="sourceLineNo">856</span>        }<a name="line.856"></a>
+<span class="sourceLineNo">857</span><a name="line.857"></a>
+<span class="sourceLineNo">858</span>        // possible we got a region of a different table...<a name="line.858"></a>
+<span class="sourceLineNo">859</span>        if (!regionInfo.getTable().equals(tableName)) {<a name="line.859"></a>
+<span class="sourceLineNo">860</span>          throw new TableNotFoundException(<a name="line.860"></a>
+<span class="sourceLineNo">861</span>            "Region of '" + regionInfo.getRegionNameAsString() + "' is expected in the table of '" + tableName + "', " +<a name="line.861"></a>
+<span class="sourceLineNo">862</span>            "but hbase:meta says it is in the table of '" + regionInfo.getTable() + "'. " +<a name="line.862"></a>
+<span class="sourceLineNo">863</span>            "hbase:meta might be damaged.");<a name="line.863"></a>
+<span class="sourceLineNo">864</span>        }<a name="line.864"></a>
+<span class="sourceLineNo">865</span>        if (regionInfo.isSplit()) {<a name="line.865"></a>
+<span class="sourceLineNo">866</span>          throw new RegionOfflineException ("Region for row is a split parent, daughters not online: " +<a name="line.866"></a>
+<span class="sourceLineNo">867</span>              regionInfo.getRegionNameAsString());<a name="line.867"></a>
+<span class="sourceLineNo">868</span>        }<a name="line.868"></a>
+<span class="sourceLineNo">869</span>        if (regionInfo.isOffline()) {<a name="line.869"></a>
+<span class="sourceLineNo">870</span>          throw new RegionOfflineException("Region offline; disable table call? " +<a name="line.870"></a>
+<span class="sourceLineNo">871</span>              regionInfo.getRegionNameAsString());<a name="line.871"></a>
+<span class="sourceLineNo">872</span>        }<a name="line.872"></a>
+<span class="sourceLineNo">873</span><a name="line.873"></a>
+<span class="sourceLineNo">874</span>        ServerName serverName = locations.getRegionLocation(replicaId).getServerName();<a name="line.874"></a>
+<span class="sourceLineNo">875</span>        if (serverName == null) {<a name="line.875"></a>
+<span class="sourceLineNo">876</span>          throw new NoServerForRegionException("No server address listed in "<a name="line.876"></a>
+<span class="sourceLineNo">877</span>              + TableName.META_TABLE_NAME + " for region " + regionInfo.getRegionNameAsString()<a name="line.877"></a>
+<span class="sourceLineNo">878</span>              + " containing row " + Bytes.toStringBinary(row));<a name="line.878"></a>
+<span class="sourceLineNo">879</span>        }<a name="line.879"></a>
+<span class="sourceLineNo">880</span><a name="line.880"></a>
+<span class="sourceLineNo">881</span>        if (isDeadServer(serverName)){<a name="line.881"></a>
+<span class="sourceLineNo">882</span>          throw new RegionServerStoppedException("hbase:meta says the region "+<a name="line.882"></a>
+<span class="sourceLineNo">883</span>              regionInfo.getRegionNameAsString()+" is managed by the server " + serverName +<a name="line.883"></a>
+<span class="sourceLineNo">884</span>              ", but it is dead.");<a name="line.884"></a>
+<span class="sourceLineNo">885</span>        }<a name="line.885"></a>
+<span class="sourceLineNo">886</span>        // Instantiate the location<a name="line.886"></a>
+<span class="sourceLineNo">887</span>        cacheLocation(tableName, locations);<a name="line.887"></a>
+<span class="sourceLineNo">888</span>        return locations;<a name="line.888"></a>
+<span class="sourceLineNo">889</span>      } catch (TableNotFoundException e) {<a name="line.889"></a>
+<span class="sourceLineNo">890</span>        // if we got this error, probably means the table just plain doesn't<a name="line.890"></a>
+<span class="sourceLineNo">891</span>        // exist. rethrow the error immediately. this should always be coming<a name="line.891"></a>
+<span class="sourceLineNo">892</span>        // from the HTable constructor.<a name="line.892"></a>
+<span class="sourceLineNo">893</span>        throw e;<a name="line.893"></a>
+<span class="sourceLineNo">894</span>      } catch (IOException e) {<a name="line.894"></a>
+<span class="sourceLineNo">895</span>        ExceptionUtil.rethrowIfInterrupt(e);<a name="line.895"></a>
+<span class="sourceLineNo">896</span>        if (e instanceof RemoteException) {<a name="line.896"></a>
+<span class="sourceLineNo">897</span>          e = ((RemoteException)e).unwrapRemoteException();<a name="line.897"></a>
+<span class="sourceLineNo">898</span>        }<a name="line.898"></a>
+<span class="sourceLineNo">899</span>        if (e instanceof CallQueueTooBigException) {<a name="line.899"></a>
+<span class="sourceLineNo">900</span>          // Give a special check on CallQueueTooBigException, see #HBASE-17114<a name="line.900"></a>
+<span class="sourceLineNo">901</span>          pauseBase = this.pauseForCQTBE;<a name="line.901"></a>
+<span class="sourceLineNo">902</span>        }<a name="line.902"></a>
+<span class="sourceLineNo">903</span>        if (tries &lt; maxAttempts - 1) {<a name="line.903"></a>
+<span class="sourceLineNo">904</span>          if (LOG.isDebugEnabled()) {<a name="line.904"></a>
+<span class="sourceLineNo">905</span>            LOG.debug("locateRegionInMeta parentTable=" + TableName.META_TABLE_NAME<a name="line.905"></a>
+<span class="sourceLineNo">906</span>                + ", metaLocation=" + ", attempt=" + tries + " of " + maxAttempts<a name="line.906"></a>
+<span class="sourceLineNo">907</span>                + " failed; retrying after sleep of "<a name="line.907"></a>
+<span class="sourceLineNo">908</span>                + ConnectionUtils.getPauseTime(pauseBase, tries) + " because: " + e.getMessage());<a name="line.908"></a>
+<span class="sourceLineNo">909</span>          }<a name="line.909"></a>
+<span class="sourceLineNo">910</span>        } else {<a name="line.910"></a>
+<span class="sourceLineNo">911</span>          throw e;<a name="line.911"></a>
+<span class="sourceLineNo">912</span>        }<a name="line.912"></a>
+<span class="sourceLineNo">913</span>        // Only relocate the parent region if necessary<a name="line.913"></a>
+<span class="sourceLineNo">914</span>        if(!(e instanceof RegionOfflineException ||<a name="line.914"></a>
+<span class="sourceLineNo">915</span>            e instanceof NoServerForRegionException)) {<a name="line.915"></a>
+<span class="sourceLineNo">916</span>          relocateRegion(TableName.META_TABLE_NAME, metaStartKey, replicaId);<a name="line.916"></a>
+<span class="sourceLineNo">917</span>        }<a name="line.917"></a>
+<span class="sourceLineNo">918</span>      } finally {<a name="line.918"></a>
+<span class="sourceLineNo">919</span>        userRegionLock.unlock();<a name="line.919"></a>
+<span class="sourceLineNo">920</span>      }<a name="line.920"></a>
+<span class="sourceLineNo">921</span>      try{<a name="line.921"></a>
+<span class="sourceLineNo">922</span>        Thread.sleep(ConnectionUtils.getPauseTime(pauseBase, tries));<a name="line.922"></a>
+<span class="sourceLineNo">923</span>      } catch (InterruptedException e) {<a name="line.923"></a>
+<span class="sourceLineNo">924</span>        throw new InterruptedIOException("Giving up trying to location region in " +<a name="line.924"></a>
+<span class="sourceLineNo">925</span>          "meta: thread is interrupted.");<a name="line.925"></a>
+<span class="sourceLineNo">926</span>      }<a name="line.926"></a>
+<span class="sourceLineNo">927</span>    }<a name="line.927"></a>
+<span class="sourceLineNo">928</span>  }<a name="line.928"></a>
+<span class="sourceLineNo">929</span><a name="line.929"></a>
+<span class="sourceLineNo">930</span>  /**<a name="line.930"></a>
+<span class="sourceLineNo">931</span>   * Put a newly discovered HRegionLocation into the cache.<a name="line.931"></a>
+<span class="sourceLineNo">932</span>   * @param tableName The table name.<a name="line.932"></a>
+<span class="sourceLineNo">933</span>   * @param location the new location<a name="line.933"></a>
+<span class="sourceLineNo">934</span>   */<a name="line.934"></a>
+<span class="sourceLineNo">935</span>  @Override<a name="line.935"></a>
+<span class="sourceLineNo">936</span>  public void cacheLocation(final TableName tableName, final RegionLocations location) {<a name="line.936"></a>
+<span class="sourceLineNo">937</span>    metaCache.cacheLocation(tableName, location);<a name="line.937"></a>
+<span class="sourceLineNo">938</span>  }<a name="line.938"></a>
+<span class="sourceLineNo">939</span><a name="line.939"></a>
+<span class="sourceLineNo">940</span>  /**<a name="line.940"></a>
+<span class="sourceLineNo">941</span>   * Search the cache for a location that fits our table and row key.<a name="line.941"></a>
+<span class="sourceLineNo">942</span>   * Return null if no suitable region is located.<a name="line.942"></a>
+<span class="sourceLineNo">943</span>   * @return Null or region location found in cache.<a name="line.943"></a>
+<span class="sourceLineNo">944</span>   */<a name="line.944"></a>
+<span class="sourceLineNo">945</span>  RegionLocations getCachedLocation(final TableName tableName,<a name="line.945"></a>
+<span class="sourceLineNo">946</span>      final byte [] row) {<a name="line.946"></a>
+<span class="sourceLineNo">947</span>    return metaCache.getCachedLocation(tableName, row);<a name="line.947"></a>
+<span class="sourceLineNo">948</span>  }<a name="line.948"></a>
+<span class="sourceLineNo">949</span><a name="line.949"></a>
+<span class="sourceLineNo">950</span>  public void clearRegionCache(final TableName tableName, byte[] row) {<a name="line.950"></a>
+<span class="sourceLineNo">951</span>    metaCache.clearCache(tableName, row);<a name="line.951"></a>
+<span class="sourceLineNo">952</span>  }<a name="line.952"></a>
+<span class="sourceLineNo">953</span><a name="line.953"></a>
+<span class="sourceLineNo">954</span>  /*<a name="line.954"></a>
+<span class="sourceLineNo">955</span>   * Delete all cached entries of a table that maps to a specific location.<a name="line.955"></a>
+<span class="sourceLineNo">956</span>   */<a name="line.956"></a>
+<span class="sourceLineNo">957</span>  @Override<a name="line.957"></a>
+<span class="sourceLineNo">958</span>  public void clearCaches(final ServerName serverName) {<a name="line.958"></a>
+<span class="sourceLineNo">959</span>    metaCache.clearCache(serverName);<a name="line.959"></a>
+<span class="sourceLineNo">960</span>  }<a name="line.960"></a>
+<span class="sourceLineNo">961</span><a name="line.961"></a>
+<span class="sourceLineNo">962</span>  @Override<a name="line.962"></a>
+<span class="sourceLineNo">963</span>  public void clearRegionCache() {<a name="line.963"></a>
+<span class="sourceLineNo">964</span>    metaCache.clearCache();<a name="line.964"></a>
+<span class="sourceLineNo">965</span>  }<a name="line.965"></a>
+<span class="sourceLineNo">966</span><a name="line.966"></a>
+<span class="sourceLineNo">967</span>  @Override<a name="line.967"></a>
+<span class="sourceLineNo">968</span>  public void clearRegionCache(final TableName tableName) {<a name="line.968"></a>
+<span class="sourceLineNo">969</span>    metaCache.clearCache(tableName);<a name="line.969"></a>
+<span class="sourceLineNo">970</span>  }<a name="line.970"></a>
+<span class="sourceLineNo">971</span><a name="line.971"></a>
+<span class="sourceLineNo">972</span>  /**<a name="line.972"></a>
+<span class="sourceLineNo">973</span>   * Put a newly discovered HRegionLocation into the cache.<a name="line.973"></a>
+<span class="sourceLineNo">974</span>   * @param tableName The table name.<a name="line.974"></a>
+<span class="sourceLineNo">975</span>   * @param source the source of the new location, if it's not coming from meta<a name="line.975"></a>
+<span class="sourceLineNo">976</span>   * @param location the new location<a name="line.976"></a>
+<span class="sourceLineNo">977</span>   */<a name="line.977"></a>
+<span class="sourceLineNo">978</span>  private void cacheLocation(final TableName tableName, final ServerName source,<a name="line.978"></a>
+<span class="sourceLineNo">979</span>      final HRegionLocation location) {<a name="line.979"></a>
+<span class="sourceLineNo">980</span>    metaCache.cacheLocation(tableName, source, location);<a name="line.980"></a>
+<span class="sourceLineNo">981</span>  }<a name="line.981"></a>
 <span class="sourceLineNo">982</span><a name="line.982"></a>
-<span class="sourceLineNo">983</span>  /**<a name="line.983"></a>
-<span class="sourceLineNo">984</span>   * State of the MasterService connection/setup.<a name="line.984"></a>
-<span class="sourceLineNo">985</span>   */<a name="line.985"></a>
-<span class="sourceLineNo">986</span>  static class MasterServiceState {<a name="line.986"></a>
-<span class="sourceLineNo">987</span>    Connection connection;<a name="line.987"></a>
-<span class="sourceLineNo">988</span><a name="line.988"></a>
-<span class="sourceLineNo">989</span>    MasterProtos.MasterService.BlockingInterface stub;<a name="line.989"></a>
-<span class="sourceLineNo">990</span>    int userCount;<a name="line.990"></a>
+<span class="sourceLineNo">983</span>  // Map keyed by service name + regionserver to service stub implementation<a name="line.983"></a>
+<span class="sourceLineNo">984</span>  private final ConcurrentMap&lt;String, Object&gt; stubs = new ConcurrentHashMap&lt;&gt;();<a name="line.984"></a>
+<span class="sourceLineNo">985</span><a name="line.985"></a>
+<span class="sourceLineNo">986</span>  /**<a name="line.986"></a>
+<span class="sourceLineNo">987</span>   * State of the MasterService connection/setup.<a name="line.987"></a>
+<span class="sourceLineNo">988</span>   */<a name="line.988"></a>
+<span class="sourceLineNo">989</span>  static class MasterServiceState {<a name="line.989"></a>
+<span class="sourceLineNo">990</span>    Connection connection;<a name="line.990"></a>
 <span class="sourceLineNo">991</span><a name="line.991"></a>
-<span class="sourceLineNo">992</span>    MasterServiceState(final Connection connection) {<a name="line.992"></a>
-<span class="sourceLineNo">993</span>      super();<a name="line.993"></a>
-<span class="sourceLineNo">994</span>      this.connection = connection;<a name="line.994"></a>
-<span class="sourceLineNo">995</span>    }<a name="line.995"></a>
-<span class="sourceLineNo">996</span><a name="line.996"></a>
-<span class="sourceLineNo">997</span>    @Override<a name="line.997"></a>
-<span class="sourceLineNo">998</span>    public String toString() {<a name="line.998"></a>
-<span class="sourceLineNo">999</span>      return "MasterService";<a name="line.999"></a>
-<span class="sourceLineNo">1000</span>    }<a name="line.1000"></a>
-<span class="sourceLineNo">1001</span><a name="line.1001"></a>
-<span class="sourceLineNo">1002</span>    Object getStub() {<a name="line.1002"></a>
-<span class="sourceLineNo">1003</span>      return this.stub;<a name="line.1003"></a>
-<span class="sourceLineNo">1004</span>    }<a name="line.1004"></a>
-<span class="sourceLineNo">1005</span><a name="line.1005"></a>
-<span class="sourceLineNo">1006</span>    void clearStub() {<a name="line.1006"></a>
-<span class="sourceLineNo">1007</span>      this.stub = null;<a name="line.1007"></a>
-<span class="sourceLineNo">1008</span>    }<a name="line.1008"></a>
-<span class="sourceLineNo">1009</span><a name="line.1009"></a>
-<span class="sourceLineNo">1010</span>    boolean isMasterRunning() throws IOException {<a name="line.1010"></a>
-<span class="sourceLineNo">1011</span>      MasterProtos.IsMasterRunningResponse response = null;<a name="line.1011"></a>
-<span class="sourceLineNo">1012</span>      try {<a name="line.1012"></a>
-<span class="sourceLineNo">1013</span>        response = this.stub.isMasterRunning(null, RequestConverter.buildIsMasterRunningRequest());<a name="line.1013"></a>
-<span class="sourceLineNo">1014</span>      } catch (Exception e) {<a name="line.1014"></a>
-<span class="sourceLineNo">1015</span>        throw ProtobufUtil.handleRemoteException(e);<a name="line.1015"></a>
-<span class="sourceLineNo">1016</span>      }<a name="line.1016"></a>
-<span class="sourceLineNo">1017</span>      return response != null? response.getIsMasterRunning(): false;<a name="line.1017"></a>
-<span class="sourceLineNo">1018</span>    }<a name="line.1018"></a>
-<span class="sourceLineNo">1019</span>  }<a name="line.1019"></a>
-<span class="sourceLineNo">1020</span><a name="line.1020"></a>
-<span class="sourceLineNo">1021</span>  /**<a name="line.1021"></a>
-<span class="sourceLineNo">1022</span>   * The record of errors for servers.<a name="line.1022"></a>
-<span class="sourceLineNo">1023</span>   */<a name="line.1023"></a>
-<span class="sourceLineNo">1024</span>  static class ServerErrorTracker {<a name="line.1024"></a>
-<span class="sourceLineNo">1025</span>    // We need a concurrent map here, as we could have multiple threads updating it in parallel.<a name="line.1025"></a>
-<span class="sourceLineNo">1026</span>    private final ConcurrentMap&lt;ServerName, ServerErrors&gt; errorsByServer = new ConcurrentHashMap&lt;&gt;();<a name="line.1026"></a>
-<span class="sourceLineNo">1027</span>    private final long canRetryUntil;<a name="line.1027"></a>
-<span class="sourceLineNo">1028</span>    private final int maxTries;// max number to try<a name="line.1028"></a>
-<span class="sourceLineNo">1029</span>    private final long startTrackingTime;<a name="line.1029"></a>
-<span class="sourceLineNo">1030</span><a name="line.1030"></a>
-<span class="sourceLineNo">1031</span>    /**<a name="line.1031"></a>
-<span class="sourceLineNo">1032</span>     * Constructor<a name="line.1032"></a>
-<span class="sourceLineNo">1033</span>     * @param timeout how long to wait before timeout, in unit of millisecond<a name="line.1033"></a>
-<span class="sourceLineNo">1034</span>     * @param maxTries how many times to try<a name="line.1034"></a>
-<span class="sourceLineNo">1035</span>     */<a name="line.1035"></a>
-<span class="sourceLineNo">1036</span>    public ServerErrorTracker(long timeout, int maxTries) {<a name="line.1036"></a>
-<span class="sourceLineNo">1037</span>      this.maxTries = maxTries;<a name="line.1037"></a>
-<span class="sourceLineNo">1038</span>      this.canRetryUntil = EnvironmentEdgeManager.currentTime() + timeout;<a name="line.1038"></a>
-<span class="sourceLineNo">1039</span>      this.startTrackingTime = new Date().getTime();<a name="line.1039"></a>
-<span class="sourceLineNo">1040</span>    }<a name="line.1040"></a>
-<span class="sourceLineNo">1041</span><a name="line.1041"></a>
-<span class="sourceLineNo">1042</span>    /**<a name="line.1042"></a>
-<span class="sourceLineNo">1043</span>     * We stop to retry when we have exhausted BOTH the number of tries and the time allocated.<a name="line.1043"></a>
-<span class="sourceLineNo">1044</span>     * @param numAttempt how many times we have tried by now<a name="line.1044"></a>
-<span class="sourceLineNo">1045</span>     */<a name="line.1045"></a>
-<span class="sourceLineNo">1046</span>    boolean canTryMore(int numAttempt) {<a name="line.1046"></a>
-<span class="sourceLineNo">1047</span>      // If there is a single try we must not take into account the time.<a name="line.1047"></a>
-<span class="sourceLineNo">1048</span>      return numAttempt &lt; maxTries || (maxTries &gt; 1 &amp;&amp;<a name="line.1048"></a>
-<span class="sourceLineNo">1049</span>          EnvironmentEdgeManager.currentTime() &lt; this.canRetryUntil);<a name="line.1049"></a>
-<span class="sourceLineNo">1050</span>    }<a name="line.1050"></a>
-<span class="sourceLineNo">1051</span><a name="line.1051"></a>
-<span class="sourceLineNo">1052</span>    /**<a name="line.1052"></a>
-<span class="sourceLineNo">1053</span>     * Calculates the back-off time for a retrying request to a particular server.<a name="line.1053"></a>
-<span class="sourceLineNo">1054</span>     *<a name="line.1054"></a>
-<span class="sourceLineNo">1055</span>     * @param server    The server in question.<a name="line.1055"></a>
-<span class="sourceLineNo">1056</span>     * @param basePause The default hci pause.<a name="line.1056"></a>
-<span class="sourceLineNo">1057</span>     * @return The time to wait before sending next request.<a name="line.1057"></a>
-<span class="sourceLineNo">1058</span>     */<a name="line.1058"></a>
-<span class="sourceLineNo">1059</span>    long calculateBackoffTime(ServerName server, long basePause) {<a name="line.1059"></a>
-<span class="sourceLineNo">1060</span>      long result;<a name="line.1060"></a>
-<span class="sourceLineNo">1061</span>      ServerErrors errorStats = errorsByServer.get(server);<a name="line.1061"></a>
-<span class="sourceLineNo">1062</span>      if (errorStats != null) {<a name="line.1062"></a>
-<span class="sourceLineNo">1063</span>        result = ConnectionUtils.getPauseTime(basePause, Math.max(0, errorStats.getCount() - 1));<a name="line.1063"></a>
-<span class="sourceLineNo">1064</span>      } else {<a name="line.1064"></a>
-<span class="sourceLineNo">1065</span>        result = 0; // yes, if the server is not in our list we don't wait before retrying.<a name="line.1065"></a>
-<span class="sourceLineNo">1066</span>      }<a name="line.1066"></a>
-<span class="sourceLineNo">1067</span>      return result;<a name="line.1067"></a>
-<span class="sourceLineNo">1068</span>    }<a name="line.1068"></a>
-<span class="sourceLineNo">1069</span><a name="line.1069"></a>
-<span class="sourceLineNo">1070</span>    /**<a name="line.1070"></a>
-<span class="sourceLineNo">1071</span>     * Reports that there was an error on the server to do whatever bean-counting necessary.<a name="line.1071"></a>
-<span class="sourceLineNo">1072</span>     * @param server The server in question.<a name="line.1072"></a>
-<span class="sourceLineNo">1073</span>     */<a name="line.1073"></a>
-<span class="sourceLineNo">1074</span>    void reportServerError(ServerName server) {<a name="line.1074"></a>
-<span class="sourceLineNo">1075</span>      computeIfAbsent(errorsByServer, server, ServerErrors::new).addError();<a name="line.1075"></a>
-<span class="sourceLineNo">1076</span>    }<a name="line.1076"></a>
-<span class="sourceLineNo">1077</span><a name="line.1077"></a>
-<span class="sourceLineNo">1078</span>    long getStartTrackingTime() {<a name="line.1078"></a>
-<span class="sourceLineNo">1079</span>      return startTrackingTime;<a name="line.1079"></a>
-<span class="sourceLineNo">1080</span>    }<a name="line.1080"></a>
-<span class="sourceLineNo">1081</span><a name="line.1081"></a>
-<span class="sourceLineNo">1082</span>    /**<a name="line.1082"></a>
-<span class="sourceLineNo">1083</span>     * The record of errors for a server.<a name="line.1083"></a>
-<span class="sourceLineNo">1084</span>     */<a name="line.1084"></a>
-<span class="sourceLineNo">1085</span>    private static class ServerErrors {<a name="line.1085"></a>
-<span class="sourceLineNo">1086</span>      private final AtomicInteger retries = new AtomicInteger(0);<a name="line.1086"></a>
-<span class="sourceLineNo">1087</span><a name="line.1087"></a>
-<span class="sourceLineNo">1088</span>      public int getCount() {<a name="line.1088"></a>
-<span class="sourceLineNo">1089</span>        return retries.get();<a name="line.1089"></a>
-<span class="sourceLineNo">1090</span>      }<a name="line.1090"></a>
-<span class="sourceLineNo">1091</span><a name="line.1091"></a>
-<span class="sourceLineNo">1092</span>      public void addError() {<a name="line.1092"></a>
-<span class="sourceLineNo">1093</span>        retries.incrementAndGet();<a name="line.1093"></a>
-<span class="sourceLineNo">1094</span>      }<a name="line.1094"></a>
-<span class="sourceLineNo">1095</span>    }<a name="line.1095"></a>
-<span class="sourceLineNo">1096</span>  }<a name="line.1096"></a>
-<span class="sourceLineNo">1097</span><a name="line.1097"></a>
-<span class="sourceLineNo">1098</span>  /**<a name="line.1098"></a>
-<span class="sourceLineNo">1099</span>   * Class to make a MasterServiceStubMaker stub.<a name="line.1099"></a>
-<span class="sourceLineNo">1100</span>   */<a name="line.1100"></a>
-<span class="sourceLineNo">1101</span>  private final class MasterServiceStubMaker {<a name="line.1101"></a>
-<span class="sourceLineNo">1102</span><a name="line.1102"></a>
-<span class="sourceLineNo">1103</span>    private void isMasterRunning(MasterProtos.MasterService.BlockingInterface stub)<a name="line.1103"></a>
-<span class="sourceLineNo">1104</span>        throws IOException {<a name="line.1104"></a>
-<span class="sourceLineNo">1105</span>      try {<a name="line.1105"></a>
-<span class="sourceLineNo">1106</span>        stub.isMasterRunning(null, RequestConverter.buildIsMasterRunningRequest());<a name="line.1106"></a>
-<span class="sourceLineNo">1107</span>      } catch (ServiceException e) {<a name="line.1107"></a>
-<span class="sourceLineNo">1108</span>        throw ProtobufUtil.handleRemoteException(e);<a name="line.1108"></a>
-<span class="sourceLineNo">1109</span>      }<a name="line.1109"></a>
-<span class="sourceLineNo">1110</span>    }<a name="line.1110"></a>
-<span class="sourceLineNo">1111</span><a name="line.1111"></a>
-<span class="sourceLineNo">1112</span>    /**<a name="line.1112"></a>
-<span class="sourceLineNo">1113</span>     * Create a stub. Try once only. It is not typed because there is no common type to protobuf<a name="line.1113"></a>
-<span class="sourceLineNo">1114</span>     * services nor their interfaces. Let the caller do appropriate casting.<a name="line.1114"></a>
-<span class="sourceLineNo">1115</span>     * @return A stub for master services.<a name="line.1115"></a>
-<span class="sourceLineNo">1116</span>     */<a name="line.1116"></a>
-<span class="sourceLineNo">1117</span>    private MasterProtos.MasterService.BlockingInterface makeStubNoRetries()<a name="line.1117"></a>
-<span class="sourceLineNo">1118</span>        throws IOException, KeeperException {<a name="line.1118"></a>
-<span class="sourceLineNo">1119</span>      ServerName sn = get(registry.getMasterAddress());<a name="line.1119"></a>
-<span class="sourceLineNo">1120</span>      if (sn == null) {<a name="line.1120"></a>
-<span class="sourceLineNo">1121</span>        String msg = "ZooKeeper available but no active master location found";<a name="line.1121"></a>
-<span class="sourceLineNo">1122</span>        LOG.info(msg);<a name="line.1122"></a>
-<span class="sourceLineNo">1123</span>        throw new MasterNotRunningException(msg);<a name="line.1123"></a>
-<span class="sourceLineNo">1124</span>      }<a name="line.1124"></a>
-<span class="sourceLineNo">1125</span>      if (isDeadServer(sn)) {<a name="line.1125"></a>
-<span class="sourceLineNo">1126</span>        throw new MasterNotRunningException(sn + " is dead.");<a name="line.1126"></a>
+<span class="sourceLineNo">992</span>    MasterProtos.MasterService.BlockingInterface stub;<a name="line.992"></a>
+<span class="sourceLineNo">993</span>    int userCount;<a name="line.993"></a>
+<span class="sourceLineNo">994</span><a name="line.994"></a>
+<span class="sourceLineNo">995</span>    MasterServiceState(final Connection connection) {<a name="line.995"></a>
+<span class="sourceLineNo">996</span>      super();<a name="line.996"></a>
+<span class="sourceLineNo">997</span>      this.connection = connection;<a name="line.997"></a>
+<span class="sourceLineNo">998</span>    }<a name="line.998"></a>
+<span class="sourceLineNo">999</span><a name="line.999"></a>
+<span class="sourceLineNo">1000</span>    @Override<a name="line.1000"></a>
+<span class="sourceLineNo">1001</span>    public String toString() {<a name="line.1001"></a>
+<span class="sourceLineNo">1002</span>      return "MasterService";<a name="line.1002"></a>
+<span class="sourceLineNo">1003</span>    }<a name="line.1003"></a>
+<span class="sourceLineNo">1004</span><a name="line.1004"></a>
+<span class="sourceLineNo">1005</span>    Object getStub() {<a name="line.1005"></a>
+<span class="sourceLineNo">1006</span>      return this.stub;<a name="line.1006"></a>
+<span class="sourceLineNo">1007</span>    }<a name="line.1007"></a>
+<span class="sourceLineNo">1008</span><a name="line.1008"></a>
+<span class="sourceLineNo">1009</span>    void clearStub() {<a name="line.1009"></a>
+<span class="sourceLineNo">1010</span>      this.stub = null;<a name="line.1010"></a>
+<span class="sourceLineNo">1011</span>    }<a name="line.1011"></a>
+<span class="sourceLineNo">1012</span><a name="line.1012"></a>
+<span class="sourceLineNo">1013</span>    boolean isMasterRunning() throws IOException {<a name="line.1013"></a>
+<span class="sourceLineNo">1014</span>      MasterProtos.IsMasterRunningResponse response = null;<a name="line.1014"></a>
+<span class="sourceLineNo">1015</span>      try {<a name="line.1015"></a>
+<span class="sourceLineNo">1016</span>        response = this.stub.isMasterRunning(null, RequestConverter.buildIsMasterRunningRequest());<a name="line.1016"></a>
+<span class="sourceLineNo">1017</span>      } catch (Exception e) {<a name="line.1017"></a>
+<span class="sourceLineNo">1018</span>        throw ProtobufUtil.handleRemoteException(e);<a name="line.1018"></a>
+<span class="sourceLineNo">1019</span>      }<a name="line.1019"></a>
+<span class="sourceLineNo">1020</span>      return response != null? response.getIsMasterRunning(): false;<a name="line.1020"></a>
+<span class="sourceLineNo">1021</span>    }<a name="line.1021"></a>
+<span class="sourceLineNo">1022</span>  }<a name="line.1022"></a>
+<span class="sourceLineNo">1023</span><a name="line.1023"></a>
+<span class="sourceLineNo">1024</span>  /**<a name="line.1024"></a>
+<span class="sourceLineNo">1025</span>   * The record of errors for servers.<a name="line.1025"></a>
+<span class="sourceLineNo">1026</span>   */<a name="line.1026"></a>
+<span class="sourceLineNo">1027</span>  static class ServerErrorTracker {<a name="line.1027"></a>
+<span class="sourceLineNo">1028</span>    // We need a concurrent map here, as we could have multiple threads updating it in parallel.<a name="line.1028"></a>
+<span class="sourceLineNo">1029</span>    private final ConcurrentMap&lt;ServerName, ServerErrors&gt; errorsByServer = new ConcurrentHashMap&lt;&gt;();<a name="line.1029"></a>
+<span class="sourceLineNo">1030</span>    private final long canRetryUntil;<a name="line.1030"></a>
+<span class="sourceLineNo">1031</span>    private final int maxTries;// max number to try<a name="line.1031"></a>
+<span class="sourceLineNo">1032</span>    private final long startTrackingTime;<a name="line.1032"></a>
+<span class="sourceLineNo">1033</span><a name="line.1033"></a>
+<span class="sourceLineNo">1034</span>    /**<a name="line.1034"></a>
+<span class="sourceLineNo">1035</span>     * Constructor<a name="line.1035"></a>
+<span class="sourceLineNo">1036</span>     * @param timeout how long to wait before timeout, in unit of millisecond<a name="line.1036"></a>
+<span class="sourceLineNo">1037</span>     * @param maxTries how many times to try<a name="line.1037"></a>
+<span class="sourceLineNo">1038</span>     */<a name="line.1038"></a>
+<span class="sourceLineNo">1039</span>    public ServerErrorTracker(long timeout, int maxTries) {<a name="line.1039"></a>
+<span class="sourceLineNo">1040</span>      this.maxTries = maxTries;<a name="line.1040"></a>
+<span class="sourceLineNo">1041</span>      this.canRetryUntil = EnvironmentEdgeManager.currentTime() + timeout;<a name="line.1041"></a>
+<span class="sourceLineNo">1042</span>      this.startTrackingTime = new Date().getTime();<a name="line.1042"></a>
+<span class="sourceLineNo">1043</span>    }<a name="line.1043"></a>
+<span class="sourceLineNo">1044</span><a name="line.1044"></a>
+<span class="sourceLineNo">1045</span>    /**<a name="line.1045"></a>
+<span class="sourceLineNo">1046</span>     * We stop to retry when we have exhausted BOTH the number of tries and the time allocated.<a name="line.1046"></a>
+<span class="sourceLineNo">1047</span>     * @param numAttempt how many times we have tried by now<a name="line.1047"></a>
+<span class="sourceLineNo">1048</span>     */<a name="line.1048"></a>
+<span class="sourceLineNo">1049</span>    boolean canTryMore(int numAttempt) {<a name="line.1049"></a>
+<span class="sourceLineNo">1050</span>      // If there is a single try we must not take into account the time.<a name="line.1050"></a>
+<span class="sourceLineNo">1051</span>      return numAttempt &lt; maxTries || (maxTries &gt; 1 &amp;&amp;<a name="line.1051"></a>
+<span class="sourceLineNo">1052</span>          EnvironmentEdgeManager.currentTime() &lt; this.canRetryUntil);<a name="line.1052"></a>
+<span class="sourceLineNo">1053</span>    }<a name="line.1053"></a>
+<span class="sourceLineNo">1054</span><a name="line.1054"></a>
+<span class="sourceLineNo">1055</span>    /**<a name="line.1055"></a>
+<span class="sourceLineNo">1056</span>     * Calculates the back-off time for a retrying request to a particular server.<a name="line.1056"></a>
+<span class="sourceLineNo">1057</span>     *<a name="line.1057"></a>
+<span class="sourceLineNo">1058</span>     * @param server    The server in question.<a name="line.1058"></a>
+<span class="sourceLineNo">1059</span>     * @param basePause The default hci pause.<a name="line.1059"></a>
+<span class="sourceLineNo">1060</span>     * @return The time to wait before sending next request.<a name="line.1060"></a>
+<span class="sourceLineNo">1061</span>     */<a name="line.1061"></a>
+<span class="sourceLineNo">1062</span>    long calculateBackoffTime(ServerName server, long basePause) {<a name="line.1062"></a>
+<span class="sourceLineNo">1063</span>      long result;<a name="line.1063"></a>
+<span class="sourceLineNo">1064</span>      ServerErrors errorStats = errorsByServer.get(server);<a name="line.1064"></a>
+<span class="sourceLineNo">1065</span>      if (errorStats != null) {<a name="line.1065"></a>
+<span class="sourceLineNo">1066</span>        result = ConnectionUtils.getPauseTime(basePause, Math.max(0, errorStats.getCount() - 1));<a name="line.1066"></a>
+<span class="sourceLineNo">1067</span>      } else {<a name="line.1067"></a>
+<span class="sourceLineNo">1068</span>        result = 0; // yes, if the server is not in our list we don't wait before retrying.<a name="line.1068"></a>
+<span class="sourceLineNo">1069</span>      }<a name="line.1069"></a>
+<span class="sourceLineNo">1070</span>      return result;<a name="line.1070"></a>
+<span class="sourceLineNo">1071</span>    }<a name="line.1071"></a>
+<span class="sourceLineNo">1072</span><a name="line.1072"></a>
+<span class="sourceLineNo">1073</span>    /**<a name="line.1073"></a>
+<span class="sourceLineNo">1074</span>     * Reports that there was an error on the server to do whatever bean-counting necessary.<a name="line.1074"></a>
+<span class="sourceLineNo">1075</span>     * @param server The server in question.<a name="line.1075"></a>
+<span class="sourceLineNo">1076</span>     */<a name="line.1076"></a>
+<span class="sourceLineNo">1077</span>    void reportServerError(ServerName server) {<a name="line.1077"></a>
+<span class="sourceLineNo">1078</span>      computeIfAbsent(errorsByServer, server, ServerErrors::new).addError();<a name="line.1078"></a>
+<span class="sourceLineNo">1079</span>    }<a name="line.1079"></a>
+<span class="sourceLineNo">1080</span><a name="line.1080"></a>
+<span class="sourceLineNo">1081</span>    long getStartTrackingTime() {<a name="line.1081"></a>
+<span class="sourceLineNo">1082</span>      return startTrackingTime;<a name="line.1082"></a>
+<span class="sourceLineNo">1083</span>    }<a name="line.1083"></a>
+<span class="sourceLineNo">1084</span><a name="line.1084"></a>
+<span class="sourceLineNo">1085</span>    /**<a name="line.1085"></a>
+<span class="sourceLineNo">1086</span>     * The record of errors for a server.<a name="line.1086"></a>
+<span class="sourceLineNo">1087</span>     */<a name="line.1087"></a>
+<span class="sourceLineNo">1088</span>    private static class ServerErrors {<a name="line.1088"></a>
+<span class="sourceLineNo">1089</span>      private final AtomicInteger retries = new AtomicInteger(0);<a name="line.1089"></a>
+<span class="sourceLineNo">1090</span><a name="line.1090"></a>
+<span class="sourceLineNo">1091</span>      public int getCount() {<a name="line.1091"></a>
+<span class="sourceLineNo">1092</span>        return retries.get();<a name="line.1092"></a>
+<span class="sourceLineNo">1093</span>      }<a name="line.1093"></a>
+<span class="sourceLineNo">1094</span><a name="line.1094"></a>
+<span class="sourceLineNo">1095</span>      public void addError() {<a name="line.1095"></a>
+<span class="sourceLineNo">1096</span>        retries.incrementAndGet();<a name="line.1096"></a>
+<span class="sourceLineNo">1097</span>      }<a name="line.1097"></a>
+<span class="sourceLineNo">1098</span>    }<a name="line.1098"></a>
+<span class="sourceLineNo">1099</span>  }<a name="line.1099"></a>
+<span class="sourceLineNo">1100</span><a name="line.1100"></a>
+<span class="sourceLineNo">1101</span>  /**<a name="line.1101"></a>
+<span class="sourceLineNo">1102</span>   * Class to make a MasterServiceStubMaker stub.<a name="line.1102"></a>
+<span class="sourceLineNo">1103</span>   */<a name="line.1103"></a>
+<span class="sourceLineNo">1104</span>  private final class MasterServiceStubMaker {<a name="line.1104"></a>
+<span class="sourceLineNo">1105</span><a name="line.1105"></a>
+<span class="sourceLineNo">1106</span>    private void isMasterRunning(MasterProtos.MasterService.BlockingInterface stub)<a name="line.1106"></a>
+<span class="sourceLineNo">1107</span>        throws IOException {<a name="line.1107"></a>
+<span class="sourceLineNo">1108</span>      try {<a name="line.1108"></a>
+<span class="sourceLineNo">1109</span>        stub.isMasterRunning(null, RequestConverter.buildIsMasterRunningRequest());<a name="line.1109"></a>
+<span class="sourceLineNo">1110</span>      } catch (ServiceException e) {<a name="line.1110"></a>
+<span class="sourceLineNo">1111</span>        throw ProtobufUtil.handleRemoteException(e);<a name="line.1111"></a>
+<span class="sourceLineNo">1112</span>      }<a name="line.1112"></a>
+<span class="sourceLineNo">1113</span>    }<a name="line.1113"></a>
+<span class="sourceLineNo">1114</span><a name="line.1114"></a>
+<span class="sourceLineNo">1115</span>    /**<a name="line.1115"></a>
+<span class="sourceLineNo">1116</span>     * Create a stub. Try once only. It is not typed because there is no common type to protobuf<a name="line.1116"></a>
+<span class="sourceLineNo">1117</span>     * services nor their interfaces. Let the caller do appropriate casting.<a name="line.1117"></a>
+<span class="sourceLineNo">1118</span>     * @return A stub for master services.<a name="line.1118"></a>
+<span class="sourceLineNo">1119</span>     */<a name="line.1119"></a>
+<span class="sourceL

<TRUNCATED>

Mime
View raw message