hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [11/51] [partial] hbase-site git commit: Published site at .
Date Wed, 16 Aug 2017 15:06:32 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/1ada5f22/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.TableCache.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.TableCache.html b/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.TableCache.html
index 13bde46..9aa8673 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.TableCache.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.TableCache.html
@@ -37,18 +37,18 @@
 <span class="sourceLineNo">029</span><a name="line.29"></a>
 <span class="sourceLineNo">030</span>import java.io.IOException;<a name="line.30"></a>
 <span class="sourceLineNo">031</span>import java.util.Arrays;<a name="line.31"></a>
-<span class="sourceLineNo">032</span>import java.util.HashMap;<a name="line.32"></a>
-<span class="sourceLineNo">033</span>import java.util.HashSet;<a name="line.33"></a>
-<span class="sourceLineNo">034</span>import java.util.Iterator;<a name="line.34"></a>
+<span class="sourceLineNo">032</span>import java.util.HashSet;<a name="line.32"></a>
+<span class="sourceLineNo">033</span>import java.util.Iterator;<a name="line.33"></a>
+<span class="sourceLineNo">034</span>import java.util.LinkedHashMap;<a name="line.34"></a>
 <span class="sourceLineNo">035</span>import java.util.List;<a name="line.35"></a>
 <span class="sourceLineNo">036</span>import java.util.Map;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>import java.util.Set;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>import java.util.concurrent.CompletableFuture;<a name="line.38"></a>
-<span class="sourceLineNo">039</span>import java.util.concurrent.ConcurrentHashMap;<a name="line.39"></a>
-<span class="sourceLineNo">040</span>import java.util.concurrent.ConcurrentMap;<a name="line.40"></a>
-<span class="sourceLineNo">041</span>import java.util.concurrent.ConcurrentNavigableMap;<a name="line.41"></a>
-<span class="sourceLineNo">042</span>import java.util.concurrent.ConcurrentSkipListMap;<a name="line.42"></a>
-<span class="sourceLineNo">043</span>import java.util.concurrent.ThreadLocalRandom;<a name="line.43"></a>
+<span class="sourceLineNo">037</span>import java.util.Optional;<a name="line.37"></a>
+<span class="sourceLineNo">038</span>import java.util.Set;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import java.util.concurrent.CompletableFuture;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import java.util.concurrent.ConcurrentHashMap;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>import java.util.concurrent.ConcurrentMap;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>import java.util.concurrent.ConcurrentNavigableMap;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>import java.util.concurrent.ConcurrentSkipListMap;<a name="line.43"></a>
 <span class="sourceLineNo">044</span><a name="line.44"></a>
 <span class="sourceLineNo">045</span>import org.apache.commons.logging.Log;<a name="line.45"></a>
 <span class="sourceLineNo">046</span>import org.apache.commons.logging.LogFactory;<a name="line.46"></a>
@@ -115,7 +115,7 @@
 <span class="sourceLineNo">107</span>    public final Set&lt;LocateRequest&gt; pendingRequests = new HashSet&lt;&gt;();<a name="line.107"></a>
 <span class="sourceLineNo">108</span><a name="line.108"></a>
 <span class="sourceLineNo">109</span>    public final Map&lt;LocateRequest, CompletableFuture&lt;HRegionLocation&gt;&gt; allRequests =<a name="line.109"></a>
-<span class="sourceLineNo">110</span>        new HashMap&lt;&gt;();<a name="line.110"></a>
+<span class="sourceLineNo">110</span>        new LinkedHashMap&lt;&gt;();<a name="line.110"></a>
 <span class="sourceLineNo">111</span><a name="line.111"></a>
 <span class="sourceLineNo">112</span>    public boolean hasQuota(int max) {<a name="line.112"></a>
 <span class="sourceLineNo">113</span>      return pendingRequests.size() &lt; max;<a name="line.113"></a>
@@ -128,353 +128,358 @@
 <span class="sourceLineNo">120</span>    public void send(LocateRequest req) {<a name="line.120"></a>
 <span class="sourceLineNo">121</span>      pendingRequests.add(req);<a name="line.121"></a>
 <span class="sourceLineNo">122</span>    }<a name="line.122"></a>
-<span class="sourceLineNo">123</span>  }<a name="line.123"></a>
-<span class="sourceLineNo">124</span><a name="line.124"></a>
-<span class="sourceLineNo">125</span>  AsyncNonMetaRegionLocator(AsyncConnectionImpl conn) {<a name="line.125"></a>
-<span class="sourceLineNo">126</span>    this.conn = conn;<a name="line.126"></a>
-<span class="sourceLineNo">127</span>    this.maxConcurrentLocateRequestPerTable = conn.getConfiguration().getInt(<a name="line.127"></a>
-<span class="sourceLineNo">128</span>      MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE, DEFAULT_MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE);<a name="line.128"></a>
-<span class="sourceLineNo">129</span>  }<a name="line.129"></a>
-<span class="sourceLineNo">130</span><a name="line.130"></a>
-<span class="sourceLineNo">131</span>  private TableCache getTableCache(TableName tableName) {<a name="line.131"></a>
-<span class="sourceLineNo">132</span>    return computeIfAbsent(cache, tableName, TableCache::new);<a name="line.132"></a>
-<span class="sourceLineNo">133</span>  }<a name="line.133"></a>
-<span class="sourceLineNo">134</span><a name="line.134"></a>
-<span class="sourceLineNo">135</span>  private void removeFromCache(HRegionLocation loc) {<a name="line.135"></a>
-<span class="sourceLineNo">136</span>    TableCache tableCache = cache.get(loc.getRegionInfo().getTable());<a name="line.136"></a>
-<span class="sourceLineNo">137</span>    if (tableCache == null) {<a name="line.137"></a>
-<span class="sourceLineNo">138</span>      return;<a name="line.138"></a>
-<span class="sourceLineNo">139</span>    }<a name="line.139"></a>
-<span class="sourceLineNo">140</span>    tableCache.cache.computeIfPresent(loc.getRegionInfo().getStartKey(), (k, oldLoc) -&gt; {<a name="line.140"></a>
-<span class="sourceLineNo">141</span>      if (oldLoc.getSeqNum() &gt; loc.getSeqNum() ||<a name="line.141"></a>
-<span class="sourceLineNo">142</span>          !oldLoc.getServerName().equals(loc.getServerName())) {<a name="line.142"></a>
-<span class="sourceLineNo">143</span>        return oldLoc;<a name="line.143"></a>
-<span class="sourceLineNo">144</span>      }<a name="line.144"></a>
-<span class="sourceLineNo">145</span>      return null;<a name="line.145"></a>
-<span class="sourceLineNo">146</span>    });<a name="line.146"></a>
-<span class="sourceLineNo">147</span>  }<a name="line.147"></a>
-<span class="sourceLineNo">148</span><a name="line.148"></a>
-<span class="sourceLineNo">149</span>  // return whether we add this loc to cache<a name="line.149"></a>
-<span class="sourceLineNo">150</span>  private boolean addToCache(TableCache tableCache, HRegionLocation loc) {<a name="line.150"></a>
-<span class="sourceLineNo">151</span>    if (LOG.isTraceEnabled()) {<a name="line.151"></a>
-<span class="sourceLineNo">152</span>      LOG.trace("Try adding " + loc + " to cache");<a name="line.152"></a>
-<span class="sourceLineNo">153</span>    }<a name="line.153"></a>
-<span class="sourceLineNo">154</span>    byte[] startKey = loc.getRegionInfo().getStartKey();<a name="line.154"></a>
-<span class="sourceLineNo">155</span>    HRegionLocation oldLoc = tableCache.cache.putIfAbsent(startKey, loc);<a name="line.155"></a>
-<span class="sourceLineNo">156</span>    if (oldLoc == null) {<a name="line.156"></a>
-<span class="sourceLineNo">157</span>      return true;<a name="line.157"></a>
-<span class="sourceLineNo">158</span>    }<a name="line.158"></a>
-<span class="sourceLineNo">159</span>    if (oldLoc.getSeqNum() &gt; loc.getSeqNum() ||<a name="line.159"></a>
-<span class="sourceLineNo">160</span>        oldLoc.getServerName().equals(loc.getServerName())) {<a name="line.160"></a>
-<span class="sourceLineNo">161</span>      if (LOG.isTraceEnabled()) {<a name="line.161"></a>
-<span class="sourceLineNo">162</span>        LOG.trace("Will not add " + loc + " to cache because the old value " + oldLoc +<a name="line.162"></a>
-<span class="sourceLineNo">163</span>            " is newer than us or has the same server name");<a name="line.163"></a>
+<span class="sourceLineNo">123</span><a name="line.123"></a>
+<span class="sourceLineNo">124</span>    public Optional&lt;LocateRequest&gt; getCandidate() {<a name="line.124"></a>
+<span class="sourceLineNo">125</span>      return allRequests.keySet().stream().filter(r -&gt; !isPending(r)).findFirst();<a name="line.125"></a>
+<span class="sourceLineNo">126</span>    }<a name="line.126"></a>
+<span class="sourceLineNo">127</span><a name="line.127"></a>
+<span class="sourceLineNo">128</span>    public void clearCompletedRequests(Optional&lt;HRegionLocation&gt; location) {<a name="line.128"></a>
+<span class="sourceLineNo">129</span>      for (Iterator&lt;Map.Entry&lt;LocateRequest, CompletableFuture&lt;HRegionLocation&gt;&gt;&gt; iter = allRequests<a name="line.129"></a>
+<span class="sourceLineNo">130</span>          .entrySet().iterator(); iter.hasNext();) {<a name="line.130"></a>
+<span class="sourceLineNo">131</span>        Map.Entry&lt;LocateRequest, CompletableFuture&lt;HRegionLocation&gt;&gt; entry = iter.next();<a name="line.131"></a>
+<span class="sourceLineNo">132</span>        if (tryComplete(entry.getKey(), entry.getValue(), location)) {<a name="line.132"></a>
+<span class="sourceLineNo">133</span>          iter.remove();<a name="line.133"></a>
+<span class="sourceLineNo">134</span>        }<a name="line.134"></a>
+<span class="sourceLineNo">135</span>      }<a name="line.135"></a>
+<span class="sourceLineNo">136</span>    }<a name="line.136"></a>
+<span class="sourceLineNo">137</span><a name="line.137"></a>
+<span class="sourceLineNo">138</span>    private boolean tryComplete(LocateRequest req, CompletableFuture&lt;HRegionLocation&gt; future,<a name="line.138"></a>
+<span class="sourceLineNo">139</span>        Optional&lt;HRegionLocation&gt; location) {<a name="line.139"></a>
+<span class="sourceLineNo">140</span>      if (future.isDone()) {<a name="line.140"></a>
+<span class="sourceLineNo">141</span>        return true;<a name="line.141"></a>
+<span class="sourceLineNo">142</span>      }<a name="line.142"></a>
+<span class="sourceLineNo">143</span>      if (!location.isPresent()) {<a name="line.143"></a>
+<span class="sourceLineNo">144</span>        return false;<a name="line.144"></a>
+<span class="sourceLineNo">145</span>      }<a name="line.145"></a>
+<span class="sourceLineNo">146</span>      HRegionLocation loc = location.get();<a name="line.146"></a>
+<span class="sourceLineNo">147</span>      boolean completed;<a name="line.147"></a>
+<span class="sourceLineNo">148</span>      if (req.locateType.equals(RegionLocateType.BEFORE)) {<a name="line.148"></a>
+<span class="sourceLineNo">149</span>        // for locating the row before current row, the common case is to find the previous region in<a name="line.149"></a>
+<span class="sourceLineNo">150</span>        // reverse scan, so we check the endKey first. In general, the condition should be startKey &lt;<a name="line.150"></a>
+<span class="sourceLineNo">151</span>        // req.row and endKey &gt;= req.row. Here we split it to endKey == req.row || (endKey &gt; req.row<a name="line.151"></a>
+<span class="sourceLineNo">152</span>        // &amp;&amp; startKey &lt; req.row). The two conditions are equal since startKey &lt; endKey.<a name="line.152"></a>
+<span class="sourceLineNo">153</span>        int c = Bytes.compareTo(loc.getRegionInfo().getEndKey(), req.row);<a name="line.153"></a>
+<span class="sourceLineNo">154</span>        completed =<a name="line.154"></a>
+<span class="sourceLineNo">155</span>            c == 0 || (c &gt; 0 &amp;&amp; Bytes.compareTo(loc.getRegionInfo().getStartKey(), req.row) &lt; 0);<a name="line.155"></a>
+<span class="sourceLineNo">156</span>      } else {<a name="line.156"></a>
+<span class="sourceLineNo">157</span>        completed = loc.getRegionInfo().containsRow(req.row);<a name="line.157"></a>
+<span class="sourceLineNo">158</span>      }<a name="line.158"></a>
+<span class="sourceLineNo">159</span>      if (completed) {<a name="line.159"></a>
+<span class="sourceLineNo">160</span>        future.complete(loc);<a name="line.160"></a>
+<span class="sourceLineNo">161</span>        return true;<a name="line.161"></a>
+<span class="sourceLineNo">162</span>      } else {<a name="line.162"></a>
+<span class="sourceLineNo">163</span>        return false;<a name="line.163"></a>
 <span class="sourceLineNo">164</span>      }<a name="line.164"></a>
-<span class="sourceLineNo">165</span>      return false;<a name="line.165"></a>
-<span class="sourceLineNo">166</span>    }<a name="line.166"></a>
-<span class="sourceLineNo">167</span>    return loc == tableCache.cache.compute(startKey, (k, oldValue) -&gt; {<a name="line.167"></a>
-<span class="sourceLineNo">168</span>      if (oldValue == null || oldValue.getSeqNum() &lt;= loc.getSeqNum()) {<a name="line.168"></a>
-<span class="sourceLineNo">169</span>        return loc;<a name="line.169"></a>
-<span class="sourceLineNo">170</span>      }<a name="line.170"></a>
-<span class="sourceLineNo">171</span>      if (LOG.isTraceEnabled()) {<a name="line.171"></a>
-<span class="sourceLineNo">172</span>        LOG.trace("Will not add " + loc + " to cache because the old value " + oldValue +<a name="line.172"></a>
-<span class="sourceLineNo">173</span>            " is newer than us or has the same server name." +<a name="line.173"></a>
-<span class="sourceLineNo">174</span>            " Maybe it is updated before we replace it");<a name="line.174"></a>
-<span class="sourceLineNo">175</span>      }<a name="line.175"></a>
-<span class="sourceLineNo">176</span>      return oldValue;<a name="line.176"></a>
-<span class="sourceLineNo">177</span>    });<a name="line.177"></a>
-<span class="sourceLineNo">178</span>  }<a name="line.178"></a>
-<span class="sourceLineNo">179</span><a name="line.179"></a>
-<span class="sourceLineNo">180</span>  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",<a name="line.180"></a>
-<span class="sourceLineNo">181</span>      justification = "Called by lambda expression")<a name="line.181"></a>
-<span class="sourceLineNo">182</span>  private void addToCache(HRegionLocation loc) {<a name="line.182"></a>
-<span class="sourceLineNo">183</span>    addToCache(getTableCache(loc.getRegionInfo().getTable()), loc);<a name="line.183"></a>
-<span class="sourceLineNo">184</span>    if (LOG.isTraceEnabled()) {<a name="line.184"></a>
-<span class="sourceLineNo">185</span>      LOG.trace("Try adding " + loc + " to cache");<a name="line.185"></a>
-<span class="sourceLineNo">186</span>    }<a name="line.186"></a>
-<span class="sourceLineNo">187</span>  }<a name="line.187"></a>
-<span class="sourceLineNo">188</span><a name="line.188"></a>
-<span class="sourceLineNo">189</span>  private boolean tryComplete(LocateRequest req, CompletableFuture&lt;HRegionLocation&gt; future,<a name="line.189"></a>
-<span class="sourceLineNo">190</span>      HRegionLocation loc) {<a name="line.190"></a>
-<span class="sourceLineNo">191</span>    if (future.isDone()) {<a name="line.191"></a>
-<span class="sourceLineNo">192</span>      return true;<a name="line.192"></a>
-<span class="sourceLineNo">193</span>    }<a name="line.193"></a>
-<span class="sourceLineNo">194</span>    boolean completed;<a name="line.194"></a>
-<span class="sourceLineNo">195</span>    if (req.locateType.equals(RegionLocateType.BEFORE)) {<a name="line.195"></a>
-<span class="sourceLineNo">196</span>      // for locating the row before current row, the common case is to find the previous region in<a name="line.196"></a>
-<span class="sourceLineNo">197</span>      // reverse scan, so we check the endKey first. In general, the condition should be startKey &lt;<a name="line.197"></a>
-<span class="sourceLineNo">198</span>      // req.row and endKey &gt;= req.row. Here we split it to endKey == req.row || (endKey &gt; req.row<a name="line.198"></a>
-<span class="sourceLineNo">199</span>      // &amp;&amp; startKey &lt; req.row). The two conditions are equal since startKey &lt; endKey.<a name="line.199"></a>
-<span class="sourceLineNo">200</span>      int c = Bytes.compareTo(loc.getRegionInfo().getEndKey(), req.row);<a name="line.200"></a>
-<span class="sourceLineNo">201</span>      completed =<a name="line.201"></a>
-<span class="sourceLineNo">202</span>          c == 0 || (c &gt; 0 &amp;&amp; Bytes.compareTo(loc.getRegionInfo().getStartKey(), req.row) &lt; 0);<a name="line.202"></a>
-<span class="sourceLineNo">203</span>    } else {<a name="line.203"></a>
-<span class="sourceLineNo">204</span>      completed = loc.getRegionInfo().containsRow(req.row);<a name="line.204"></a>
-<span class="sourceLineNo">205</span>    }<a name="line.205"></a>
-<span class="sourceLineNo">206</span>    if (completed) {<a name="line.206"></a>
-<span class="sourceLineNo">207</span>      future.complete(loc);<a name="line.207"></a>
-<span class="sourceLineNo">208</span>      return true;<a name="line.208"></a>
-<span class="sourceLineNo">209</span>    } else {<a name="line.209"></a>
-<span class="sourceLineNo">210</span>      return false;<a name="line.210"></a>
-<span class="sourceLineNo">211</span>    }<a name="line.211"></a>
-<span class="sourceLineNo">212</span>  }<a name="line.212"></a>
-<span class="sourceLineNo">213</span><a name="line.213"></a>
-<span class="sourceLineNo">214</span>  private void complete(TableName tableName, LocateRequest req, HRegionLocation loc,<a name="line.214"></a>
-<span class="sourceLineNo">215</span>      Throwable error) {<a name="line.215"></a>
-<span class="sourceLineNo">216</span>    if (error != null) {<a name="line.216"></a>
-<span class="sourceLineNo">217</span>      if (LOG.isDebugEnabled()) {<a name="line.217"></a>
-<span class="sourceLineNo">218</span>        LOG.debug("Failed to locate region in '" + tableName + "', row='" +<a name="line.218"></a>
-<span class="sourceLineNo">219</span>            Bytes.toStringBinary(req.row) + "', locateType=" + req.locateType,<a name="line.219"></a>
-<span class="sourceLineNo">220</span>          error);<a name="line.220"></a>
-<span class="sourceLineNo">221</span>      }<a name="line.221"></a>
-<span class="sourceLineNo">222</span>    }<a name="line.222"></a>
-<span class="sourceLineNo">223</span>    LocateRequest toSend = null;<a name="line.223"></a>
-<span class="sourceLineNo">224</span>    TableCache tableCache = getTableCache(tableName);<a name="line.224"></a>
-<span class="sourceLineNo">225</span>    if (loc != null) {<a name="line.225"></a>
-<span class="sourceLineNo">226</span>      if (!addToCache(tableCache, loc)) {<a name="line.226"></a>
-<span class="sourceLineNo">227</span>        // someone is ahead of us.<a name="line.227"></a>
-<span class="sourceLineNo">228</span>        synchronized (tableCache) {<a name="line.228"></a>
-<span class="sourceLineNo">229</span>          tableCache.pendingRequests.remove(req);<a name="line.229"></a>
-<span class="sourceLineNo">230</span>        }<a name="line.230"></a>
-<span class="sourceLineNo">231</span>        return;<a name="line.231"></a>
-<span class="sourceLineNo">232</span>      }<a name="line.232"></a>
-<span class="sourceLineNo">233</span>    }<a name="line.233"></a>
-<span class="sourceLineNo">234</span>    synchronized (tableCache) {<a name="line.234"></a>
-<span class="sourceLineNo">235</span>      tableCache.pendingRequests.remove(req);<a name="line.235"></a>
-<span class="sourceLineNo">236</span>      if (error instanceof DoNotRetryIOException) {<a name="line.236"></a>
-<span class="sourceLineNo">237</span>        CompletableFuture&lt;?&gt; future = tableCache.allRequests.remove(req);<a name="line.237"></a>
-<span class="sourceLineNo">238</span>        if (future != null) {<a name="line.238"></a>
-<span class="sourceLineNo">239</span>          future.completeExceptionally(error);<a name="line.239"></a>
-<span class="sourceLineNo">240</span>        }<a name="line.240"></a>
-<span class="sourceLineNo">241</span>      }<a name="line.241"></a>
-<span class="sourceLineNo">242</span>      if (loc != null) {<a name="line.242"></a>
-<span class="sourceLineNo">243</span>        for (Iterator&lt;Map.Entry&lt;LocateRequest, CompletableFuture&lt;HRegionLocation&gt;&gt;&gt; iter =<a name="line.243"></a>
-<span class="sourceLineNo">244</span>            tableCache.allRequests.entrySet().iterator(); iter.hasNext();) {<a name="line.244"></a>
-<span class="sourceLineNo">245</span>          Map.Entry&lt;LocateRequest, CompletableFuture&lt;HRegionLocation&gt;&gt; entry = iter.next();<a name="line.245"></a>
-<span class="sourceLineNo">246</span>          if (tryComplete(entry.getKey(), entry.getValue(), loc)) {<a name="line.246"></a>
-<span class="sourceLineNo">247</span>            iter.remove();<a name="line.247"></a>
-<span class="sourceLineNo">248</span>          }<a name="line.248"></a>
-<span class="sourceLineNo">249</span>        }<a name="line.249"></a>
-<span class="sourceLineNo">250</span>      }<a name="line.250"></a>
-<span class="sourceLineNo">251</span>      if (!tableCache.allRequests.isEmpty() &amp;&amp;<a name="line.251"></a>
-<span class="sourceLineNo">252</span>          tableCache.hasQuota(maxConcurrentLocateRequestPerTable)) {<a name="line.252"></a>
-<span class="sourceLineNo">253</span>        LocateRequest[] candidates = tableCache.allRequests.keySet().stream()<a name="line.253"></a>
-<span class="sourceLineNo">254</span>            .filter(r -&gt; !tableCache.isPending(r)).toArray(LocateRequest[]::new);<a name="line.254"></a>
-<span class="sourceLineNo">255</span>        if (candidates.length &gt; 0) {<a name="line.255"></a>
-<span class="sourceLineNo">256</span>          // TODO: use a better algorithm to send a request which is more likely to fetch a new<a name="line.256"></a>
-<span class="sourceLineNo">257</span>          // location.<a name="line.257"></a>
-<span class="sourceLineNo">258</span>          toSend = candidates[ThreadLocalRandom.current().nextInt(candidates.length)];<a name="line.258"></a>
-<span class="sourceLineNo">259</span>          tableCache.send(toSend);<a name="line.259"></a>
-<span class="sourceLineNo">260</span>        }<a name="line.260"></a>
-<span class="sourceLineNo">261</span>      }<a name="line.261"></a>
-<span class="sourceLineNo">262</span>    }<a name="line.262"></a>
-<span class="sourceLineNo">263</span>    if (toSend != null) {<a name="line.263"></a>
-<span class="sourceLineNo">264</span>      locateInMeta(tableName, toSend);<a name="line.264"></a>
-<span class="sourceLineNo">265</span>    }<a name="line.265"></a>
-<span class="sourceLineNo">266</span>  }<a name="line.266"></a>
-<span class="sourceLineNo">267</span><a name="line.267"></a>
-<span class="sourceLineNo">268</span>  private void onScanComplete(TableName tableName, LocateRequest req, List&lt;Result&gt; results,<a name="line.268"></a>
-<span class="sourceLineNo">269</span>      Throwable error) {<a name="line.269"></a>
-<span class="sourceLineNo">270</span>    if (error != null) {<a name="line.270"></a>
-<span class="sourceLineNo">271</span>      complete(tableName, req, null, error);<a name="line.271"></a>
-<span class="sourceLineNo">272</span>      return;<a name="line.272"></a>
-<span class="sourceLineNo">273</span>    }<a name="line.273"></a>
-<span class="sourceLineNo">274</span>    if (results.isEmpty()) {<a name="line.274"></a>
-<span class="sourceLineNo">275</span>      complete(tableName, req, null, new TableNotFoundException(tableName));<a name="line.275"></a>
-<span class="sourceLineNo">276</span>      return;<a name="line.276"></a>
-<span class="sourceLineNo">277</span>    }<a name="line.277"></a>
-<span class="sourceLineNo">278</span>    RegionLocations locs = MetaTableAccessor.getRegionLocations(results.get(0));<a name="line.278"></a>
-<span class="sourceLineNo">279</span>    if (LOG.isDebugEnabled()) {<a name="line.279"></a>
-<span class="sourceLineNo">280</span>      LOG.debug("The fetched location of '" + tableName + "', row='" +<a name="line.280"></a>
-<span class="sourceLineNo">281</span>          Bytes.toStringBinary(req.row) + "', locateType=" + req.locateType + " is " + locs);<a name="line.281"></a>
+<span class="sourceLineNo">165</span>    }<a name="line.165"></a>
+<span class="sourceLineNo">166</span>  }<a name="line.166"></a>
+<span class="sourceLineNo">167</span><a name="line.167"></a>
+<span class="sourceLineNo">168</span>  AsyncNonMetaRegionLocator(AsyncConnectionImpl conn) {<a name="line.168"></a>
+<span class="sourceLineNo">169</span>    this.conn = conn;<a name="line.169"></a>
+<span class="sourceLineNo">170</span>    this.maxConcurrentLocateRequestPerTable = conn.getConfiguration().getInt(<a name="line.170"></a>
+<span class="sourceLineNo">171</span>      MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE, DEFAULT_MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE);<a name="line.171"></a>
+<span class="sourceLineNo">172</span>  }<a name="line.172"></a>
+<span class="sourceLineNo">173</span><a name="line.173"></a>
+<span class="sourceLineNo">174</span>  private TableCache getTableCache(TableName tableName) {<a name="line.174"></a>
+<span class="sourceLineNo">175</span>    return computeIfAbsent(cache, tableName, TableCache::new);<a name="line.175"></a>
+<span class="sourceLineNo">176</span>  }<a name="line.176"></a>
+<span class="sourceLineNo">177</span><a name="line.177"></a>
+<span class="sourceLineNo">178</span>  private void removeFromCache(HRegionLocation loc) {<a name="line.178"></a>
+<span class="sourceLineNo">179</span>    TableCache tableCache = cache.get(loc.getRegionInfo().getTable());<a name="line.179"></a>
+<span class="sourceLineNo">180</span>    if (tableCache == null) {<a name="line.180"></a>
+<span class="sourceLineNo">181</span>      return;<a name="line.181"></a>
+<span class="sourceLineNo">182</span>    }<a name="line.182"></a>
+<span class="sourceLineNo">183</span>    tableCache.cache.computeIfPresent(loc.getRegionInfo().getStartKey(), (k, oldLoc) -&gt; {<a name="line.183"></a>
+<span class="sourceLineNo">184</span>      if (oldLoc.getSeqNum() &gt; loc.getSeqNum() ||<a name="line.184"></a>
+<span class="sourceLineNo">185</span>          !oldLoc.getServerName().equals(loc.getServerName())) {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>        return oldLoc;<a name="line.186"></a>
+<span class="sourceLineNo">187</span>      }<a name="line.187"></a>
+<span class="sourceLineNo">188</span>      return null;<a name="line.188"></a>
+<span class="sourceLineNo">189</span>    });<a name="line.189"></a>
+<span class="sourceLineNo">190</span>  }<a name="line.190"></a>
+<span class="sourceLineNo">191</span><a name="line.191"></a>
+<span class="sourceLineNo">192</span>  // return whether we add this loc to cache<a name="line.192"></a>
+<span class="sourceLineNo">193</span>  private boolean addToCache(TableCache tableCache, HRegionLocation loc) {<a name="line.193"></a>
+<span class="sourceLineNo">194</span>    if (LOG.isTraceEnabled()) {<a name="line.194"></a>
+<span class="sourceLineNo">195</span>      LOG.trace("Try adding " + loc + " to cache");<a name="line.195"></a>
+<span class="sourceLineNo">196</span>    }<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    byte[] startKey = loc.getRegionInfo().getStartKey();<a name="line.197"></a>
+<span class="sourceLineNo">198</span>    HRegionLocation oldLoc = tableCache.cache.putIfAbsent(startKey, loc);<a name="line.198"></a>
+<span class="sourceLineNo">199</span>    if (oldLoc == null) {<a name="line.199"></a>
+<span class="sourceLineNo">200</span>      return true;<a name="line.200"></a>
+<span class="sourceLineNo">201</span>    }<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    if (oldLoc.getSeqNum() &gt; loc.getSeqNum() ||<a name="line.202"></a>
+<span class="sourceLineNo">203</span>        oldLoc.getServerName().equals(loc.getServerName())) {<a name="line.203"></a>
+<span class="sourceLineNo">204</span>      if (LOG.isTraceEnabled()) {<a name="line.204"></a>
+<span class="sourceLineNo">205</span>        LOG.trace("Will not add " + loc + " to cache because the old value " + oldLoc +<a name="line.205"></a>
+<span class="sourceLineNo">206</span>            " is newer than us or has the same server name");<a name="line.206"></a>
+<span class="sourceLineNo">207</span>      }<a name="line.207"></a>
+<span class="sourceLineNo">208</span>      return false;<a name="line.208"></a>
+<span class="sourceLineNo">209</span>    }<a name="line.209"></a>
+<span class="sourceLineNo">210</span>    return loc == tableCache.cache.compute(startKey, (k, oldValue) -&gt; {<a name="line.210"></a>
+<span class="sourceLineNo">211</span>      if (oldValue == null || oldValue.getSeqNum() &lt;= loc.getSeqNum()) {<a name="line.211"></a>
+<span class="sourceLineNo">212</span>        return loc;<a name="line.212"></a>
+<span class="sourceLineNo">213</span>      }<a name="line.213"></a>
+<span class="sourceLineNo">214</span>      if (LOG.isTraceEnabled()) {<a name="line.214"></a>
+<span class="sourceLineNo">215</span>        LOG.trace("Will not add " + loc + " to cache because the old value " + oldValue +<a name="line.215"></a>
+<span class="sourceLineNo">216</span>            " is newer than us or has the same server name." +<a name="line.216"></a>
+<span class="sourceLineNo">217</span>            " Maybe it is updated before we replace it");<a name="line.217"></a>
+<span class="sourceLineNo">218</span>      }<a name="line.218"></a>
+<span class="sourceLineNo">219</span>      return oldValue;<a name="line.219"></a>
+<span class="sourceLineNo">220</span>    });<a name="line.220"></a>
+<span class="sourceLineNo">221</span>  }<a name="line.221"></a>
+<span class="sourceLineNo">222</span><a name="line.222"></a>
+<span class="sourceLineNo">223</span>  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",<a name="line.223"></a>
+<span class="sourceLineNo">224</span>      justification = "Called by lambda expression")<a name="line.224"></a>
+<span class="sourceLineNo">225</span>  private void addToCache(HRegionLocation loc) {<a name="line.225"></a>
+<span class="sourceLineNo">226</span>    addToCache(getTableCache(loc.getRegionInfo().getTable()), loc);<a name="line.226"></a>
+<span class="sourceLineNo">227</span>    if (LOG.isTraceEnabled()) {<a name="line.227"></a>
+<span class="sourceLineNo">228</span>      LOG.trace("Try adding " + loc + " to cache");<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    }<a name="line.229"></a>
+<span class="sourceLineNo">230</span>  }<a name="line.230"></a>
+<span class="sourceLineNo">231</span><a name="line.231"></a>
+<span class="sourceLineNo">232</span>  private void complete(TableName tableName, LocateRequest req, HRegionLocation loc,<a name="line.232"></a>
+<span class="sourceLineNo">233</span>      Throwable error) {<a name="line.233"></a>
+<span class="sourceLineNo">234</span>    if (error != null) {<a name="line.234"></a>
+<span class="sourceLineNo">235</span>      LOG.warn(<a name="line.235"></a>
+<span class="sourceLineNo">236</span>        "Failed to locate region in '" + tableName + "', row='" + Bytes.toStringBinary(req.row)<a name="line.236"></a>
+<span class="sourceLineNo">237</span>            + "', locateType=" + req.locateType, error);<a name="line.237"></a>
+<span class="sourceLineNo">238</span>    }<a name="line.238"></a>
+<span class="sourceLineNo">239</span>    Optional&lt;LocateRequest&gt; toSend = Optional.empty();<a name="line.239"></a>
+<span class="sourceLineNo">240</span>    TableCache tableCache = getTableCache(tableName);<a name="line.240"></a>
+<span class="sourceLineNo">241</span>    if (loc != null) {<a name="line.241"></a>
+<span class="sourceLineNo">242</span>      if (!addToCache(tableCache, loc)) {<a name="line.242"></a>
+<span class="sourceLineNo">243</span>        // someone is ahead of us.<a name="line.243"></a>
+<span class="sourceLineNo">244</span>        synchronized (tableCache) {<a name="line.244"></a>
+<span class="sourceLineNo">245</span>          tableCache.pendingRequests.remove(req);<a name="line.245"></a>
+<span class="sourceLineNo">246</span>          tableCache.clearCompletedRequests(Optional.empty());<a name="line.246"></a>
+<span class="sourceLineNo">247</span>          // Remove a complete locate request in a synchronized block, so the table cache must have<a name="line.247"></a>
+<span class="sourceLineNo">248</span>          // quota to send a candidate request.<a name="line.248"></a>
+<span class="sourceLineNo">249</span>          toSend = tableCache.getCandidate();<a name="line.249"></a>
+<span class="sourceLineNo">250</span>          toSend.ifPresent(r -&gt; tableCache.send(r));<a name="line.250"></a>
+<span class="sourceLineNo">251</span>        }<a name="line.251"></a>
+<span class="sourceLineNo">252</span>        toSend.ifPresent(r -&gt; locateInMeta(tableName, r));<a name="line.252"></a>
+<span class="sourceLineNo">253</span>        return;<a name="line.253"></a>
+<span class="sourceLineNo">254</span>      }<a name="line.254"></a>
+<span class="sourceLineNo">255</span>    }<a name="line.255"></a>
+<span class="sourceLineNo">256</span>    synchronized (tableCache) {<a name="line.256"></a>
+<span class="sourceLineNo">257</span>      tableCache.pendingRequests.remove(req);<a name="line.257"></a>
+<span class="sourceLineNo">258</span>      if (error instanceof DoNotRetryIOException) {<a name="line.258"></a>
+<span class="sourceLineNo">259</span>        CompletableFuture&lt;?&gt; future = tableCache.allRequests.remove(req);<a name="line.259"></a>
+<span class="sourceLineNo">260</span>        if (future != null) {<a name="line.260"></a>
+<span class="sourceLineNo">261</span>          future.completeExceptionally(error);<a name="line.261"></a>
+<span class="sourceLineNo">262</span>        }<a name="line.262"></a>
+<span class="sourceLineNo">263</span>      }<a name="line.263"></a>
+<span class="sourceLineNo">264</span>      tableCache.clearCompletedRequests(Optional.ofNullable(loc));<a name="line.264"></a>
+<span class="sourceLineNo">265</span>      // Remove a complete locate request in a synchronized block, so the table cache must have<a name="line.265"></a>
+<span class="sourceLineNo">266</span>      // quota to send a candidate request.<a name="line.266"></a>
+<span class="sourceLineNo">267</span>      toSend = tableCache.getCandidate();<a name="line.267"></a>
+<span class="sourceLineNo">268</span>      toSend.ifPresent(r -&gt; tableCache.send(r));<a name="line.268"></a>
+<span class="sourceLineNo">269</span>    }<a name="line.269"></a>
+<span class="sourceLineNo">270</span>    toSend.ifPresent(r -&gt; locateInMeta(tableName, r));<a name="line.270"></a>
+<span class="sourceLineNo">271</span>  }<a name="line.271"></a>
+<span class="sourceLineNo">272</span><a name="line.272"></a>
+<span class="sourceLineNo">273</span>  private void onScanComplete(TableName tableName, LocateRequest req, List&lt;Result&gt; results,<a name="line.273"></a>
+<span class="sourceLineNo">274</span>      Throwable error) {<a name="line.274"></a>
+<span class="sourceLineNo">275</span>    if (error != null) {<a name="line.275"></a>
+<span class="sourceLineNo">276</span>      complete(tableName, req, null, error);<a name="line.276"></a>
+<span class="sourceLineNo">277</span>      return;<a name="line.277"></a>
+<span class="sourceLineNo">278</span>    }<a name="line.278"></a>
+<span class="sourceLineNo">279</span>    if (results.isEmpty()) {<a name="line.279"></a>
+<span class="sourceLineNo">280</span>      complete(tableName, req, null, new TableNotFoundException(tableName));<a name="line.280"></a>
+<span class="sourceLineNo">281</span>      return;<a name="line.281"></a>
 <span class="sourceLineNo">282</span>    }<a name="line.282"></a>
-<span class="sourceLineNo">283</span>    if (locs == null || locs.getDefaultRegionLocation() == null) {<a name="line.283"></a>
-<span class="sourceLineNo">284</span>      complete(tableName, req, null,<a name="line.284"></a>
-<span class="sourceLineNo">285</span>        new IOException(String.format("No location found for '%s', row='%s', locateType=%s",<a name="line.285"></a>
-<span class="sourceLineNo">286</span>          tableName, Bytes.toStringBinary(req.row), req.locateType)));<a name="line.286"></a>
-<span class="sourceLineNo">287</span>      return;<a name="line.287"></a>
-<span class="sourceLineNo">288</span>    }<a name="line.288"></a>
-<span class="sourceLineNo">289</span>    HRegionLocation loc = locs.getDefaultRegionLocation();<a name="line.289"></a>
-<span class="sourceLineNo">290</span>    HRegionInfo info = loc.getRegionInfo();<a name="line.290"></a>
-<span class="sourceLineNo">291</span>    if (info == null) {<a name="line.291"></a>
-<span class="sourceLineNo">292</span>      complete(tableName, req, null,<a name="line.292"></a>
-<span class="sourceLineNo">293</span>        new IOException(String.format("HRegionInfo is null for '%s', row='%s', locateType=%s",<a name="line.293"></a>
-<span class="sourceLineNo">294</span>          tableName, Bytes.toStringBinary(req.row), req.locateType)));<a name="line.294"></a>
-<span class="sourceLineNo">295</span>      return;<a name="line.295"></a>
-<span class="sourceLineNo">296</span>    }<a name="line.296"></a>
-<span class="sourceLineNo">297</span>    if (!info.getTable().equals(tableName)) {<a name="line.297"></a>
-<span class="sourceLineNo">298</span>      complete(tableName, req, null, new TableNotFoundException(<a name="line.298"></a>
-<span class="sourceLineNo">299</span>          "Table '" + tableName + "' was not found, got: '" + info.getTable() + "'"));<a name="line.299"></a>
+<span class="sourceLineNo">283</span>    RegionLocations locs = MetaTableAccessor.getRegionLocations(results.get(0));<a name="line.283"></a>
+<span class="sourceLineNo">284</span>    if (LOG.isDebugEnabled()) {<a name="line.284"></a>
+<span class="sourceLineNo">285</span>      LOG.debug("The fetched location of '" + tableName + "', row='" +<a name="line.285"></a>
+<span class="sourceLineNo">286</span>          Bytes.toStringBinary(req.row) + "', locateType=" + req.locateType + " is " + locs);<a name="line.286"></a>
+<span class="sourceLineNo">287</span>    }<a name="line.287"></a>
+<span class="sourceLineNo">288</span>    if (locs == null || locs.getDefaultRegionLocation() == null) {<a name="line.288"></a>
+<span class="sourceLineNo">289</span>      complete(tableName, req, null,<a name="line.289"></a>
+<span class="sourceLineNo">290</span>        new IOException(String.format("No location found for '%s', row='%s', locateType=%s",<a name="line.290"></a>
+<span class="sourceLineNo">291</span>          tableName, Bytes.toStringBinary(req.row), req.locateType)));<a name="line.291"></a>
+<span class="sourceLineNo">292</span>      return;<a name="line.292"></a>
+<span class="sourceLineNo">293</span>    }<a name="line.293"></a>
+<span class="sourceLineNo">294</span>    HRegionLocation loc = locs.getDefaultRegionLocation();<a name="line.294"></a>
+<span class="sourceLineNo">295</span>    HRegionInfo info = loc.getRegionInfo();<a name="line.295"></a>
+<span class="sourceLineNo">296</span>    if (info == null) {<a name="line.296"></a>
+<span class="sourceLineNo">297</span>      complete(tableName, req, null,<a name="line.297"></a>
+<span class="sourceLineNo">298</span>        new IOException(String.format("HRegionInfo is null for '%s', row='%s', locateType=%s",<a name="line.298"></a>
+<span class="sourceLineNo">299</span>          tableName, Bytes.toStringBinary(req.row), req.locateType)));<a name="line.299"></a>
 <span class="sourceLineNo">300</span>      return;<a name="line.300"></a>
 <span class="sourceLineNo">301</span>    }<a name="line.301"></a>
-<span class="sourceLineNo">302</span>    if (info.isSplit()) {<a name="line.302"></a>
-<span class="sourceLineNo">303</span>      complete(tableName, req, null,<a name="line.303"></a>
-<span class="sourceLineNo">304</span>        new RegionOfflineException(<a name="line.304"></a>
-<span class="sourceLineNo">305</span>            "the only available region for the required row is a split parent," +<a name="line.305"></a>
-<span class="sourceLineNo">306</span>                " the daughters should be online soon: '" + info.getRegionNameAsString() + "'"));<a name="line.306"></a>
-<span class="sourceLineNo">307</span>      return;<a name="line.307"></a>
-<span class="sourceLineNo">308</span>    }<a name="line.308"></a>
-<span class="sourceLineNo">309</span>    if (info.isOffline()) {<a name="line.309"></a>
-<span class="sourceLineNo">310</span>      complete(tableName, req, null, new RegionOfflineException("the region is offline, could" +<a name="line.310"></a>
-<span class="sourceLineNo">311</span>          " be caused by a disable table call: '" + info.getRegionNameAsString() + "'"));<a name="line.311"></a>
+<span class="sourceLineNo">302</span>    if (!info.getTable().equals(tableName)) {<a name="line.302"></a>
+<span class="sourceLineNo">303</span>      complete(tableName, req, null, new TableNotFoundException(<a name="line.303"></a>
+<span class="sourceLineNo">304</span>          "Table '" + tableName + "' was not found, got: '" + info.getTable() + "'"));<a name="line.304"></a>
+<span class="sourceLineNo">305</span>      return;<a name="line.305"></a>
+<span class="sourceLineNo">306</span>    }<a name="line.306"></a>
+<span class="sourceLineNo">307</span>    if (info.isSplit()) {<a name="line.307"></a>
+<span class="sourceLineNo">308</span>      complete(tableName, req, null,<a name="line.308"></a>
+<span class="sourceLineNo">309</span>        new RegionOfflineException(<a name="line.309"></a>
+<span class="sourceLineNo">310</span>            "the only available region for the required row is a split parent," +<a name="line.310"></a>
+<span class="sourceLineNo">311</span>                " the daughters should be online soon: '" + info.getRegionNameAsString() + "'"));<a name="line.311"></a>
 <span class="sourceLineNo">312</span>      return;<a name="line.312"></a>
 <span class="sourceLineNo">313</span>    }<a name="line.313"></a>
-<span class="sourceLineNo">314</span>    if (loc.getServerName() == null) {<a name="line.314"></a>
-<span class="sourceLineNo">315</span>      complete(tableName, req, null,<a name="line.315"></a>
-<span class="sourceLineNo">316</span>        new NoServerForRegionException(<a name="line.316"></a>
-<span class="sourceLineNo">317</span>            String.format("No server address listed for region '%s', row='%s', locateType=%s",<a name="line.317"></a>
-<span class="sourceLineNo">318</span>              info.getRegionNameAsString(), Bytes.toStringBinary(req.row), req.locateType)));<a name="line.318"></a>
-<span class="sourceLineNo">319</span>      return;<a name="line.319"></a>
-<span class="sourceLineNo">320</span>    }<a name="line.320"></a>
-<span class="sourceLineNo">321</span>    complete(tableName, req, loc, null);<a name="line.321"></a>
-<span class="sourceLineNo">322</span>  }<a name="line.322"></a>
-<span class="sourceLineNo">323</span><a name="line.323"></a>
-<span class="sourceLineNo">324</span>  private HRegionLocation locateRowInCache(TableCache tableCache, TableName tableName, byte[] row) {<a name="line.324"></a>
-<span class="sourceLineNo">325</span>    Map.Entry&lt;byte[], HRegionLocation&gt; entry = tableCache.cache.floorEntry(row);<a name="line.325"></a>
-<span class="sourceLineNo">326</span>    if (entry == null) {<a name="line.326"></a>
-<span class="sourceLineNo">327</span>      return null;<a name="line.327"></a>
-<span class="sourceLineNo">328</span>    }<a name="line.328"></a>
-<span class="sourceLineNo">329</span>    HRegionLocation loc = entry.getValue();<a name="line.329"></a>
-<span class="sourceLineNo">330</span>    byte[] endKey = loc.getRegionInfo().getEndKey();<a name="line.330"></a>
-<span class="sourceLineNo">331</span>    if (isEmptyStopRow(endKey) || Bytes.compareTo(row, endKey) &lt; 0) {<a name="line.331"></a>
-<span class="sourceLineNo">332</span>      if (LOG.isTraceEnabled()) {<a name="line.332"></a>
-<span class="sourceLineNo">333</span>        LOG.trace("Found " + loc + " in cache for '" + tableName + "', row='" +<a name="line.333"></a>
-<span class="sourceLineNo">334</span>            Bytes.toStringBinary(row) + "', locateType=" + RegionLocateType.CURRENT);<a name="line.334"></a>
-<span class="sourceLineNo">335</span>      }<a name="line.335"></a>
-<span class="sourceLineNo">336</span>      return loc;<a name="line.336"></a>
-<span class="sourceLineNo">337</span>    } else {<a name="line.337"></a>
-<span class="sourceLineNo">338</span>      return null;<a name="line.338"></a>
-<span class="sourceLineNo">339</span>    }<a name="line.339"></a>
-<span class="sourceLineNo">340</span>  }<a name="line.340"></a>
-<span class="sourceLineNo">341</span><a name="line.341"></a>
-<span class="sourceLineNo">342</span>  private HRegionLocation locateRowBeforeInCache(TableCache tableCache, TableName tableName,<a name="line.342"></a>
-<span class="sourceLineNo">343</span>      byte[] row) {<a name="line.343"></a>
-<span class="sourceLineNo">344</span>    Map.Entry&lt;byte[], HRegionLocation&gt; entry =<a name="line.344"></a>
-<span class="sourceLineNo">345</span>        isEmptyStopRow(row) ? tableCache.cache.lastEntry() : tableCache.cache.lowerEntry(row);<a name="line.345"></a>
-<span class="sourceLineNo">346</span>    if (entry == null) {<a name="line.346"></a>
-<span class="sourceLineNo">347</span>      return null;<a name="line.347"></a>
-<span class="sourceLineNo">348</span>    }<a name="line.348"></a>
-<span class="sourceLineNo">349</span>    HRegionLocation loc = entry.getValue();<a name="line.349"></a>
-<span class="sourceLineNo">350</span>    if (isEmptyStopRow(loc.getRegionInfo().getEndKey()) ||<a name="line.350"></a>
-<span class="sourceLineNo">351</span>        Bytes.compareTo(loc.getRegionInfo().getEndKey(), row) &gt;= 0) {<a name="line.351"></a>
-<span class="sourceLineNo">352</span>      if (LOG.isTraceEnabled()) {<a name="line.352"></a>
-<span class="sourceLineNo">353</span>        LOG.trace("Found " + loc + " in cache for '" + tableName + "', row='" +<a name="line.353"></a>
-<span class="sourceLineNo">354</span>            Bytes.toStringBinary(row) + "', locateType=" + RegionLocateType.BEFORE);<a name="line.354"></a>
-<span class="sourceLineNo">355</span>      }<a name="line.355"></a>
-<span class="sourceLineNo">356</span>      return loc;<a name="line.356"></a>
-<span class="sourceLineNo">357</span>    } else {<a name="line.357"></a>
-<span class="sourceLineNo">358</span>      return null;<a name="line.358"></a>
-<span class="sourceLineNo">359</span>    }<a name="line.359"></a>
-<span class="sourceLineNo">360</span>  }<a name="line.360"></a>
-<span class="sourceLineNo">361</span><a name="line.361"></a>
-<span class="sourceLineNo">362</span>  private void locateInMeta(TableName tableName, LocateRequest req) {<a name="line.362"></a>
-<span class="sourceLineNo">363</span>    if (LOG.isTraceEnabled()) {<a name="line.363"></a>
-<span class="sourceLineNo">364</span>      LOG.trace("Try locate '" + tableName + "', row='" + Bytes.toStringBinary(req.row) +<a name="line.364"></a>
-<span class="sourceLineNo">365</span>          "', locateType=" + req.locateType + " in meta");<a name="line.365"></a>
-<span class="sourceLineNo">366</span>    }<a name="line.366"></a>
-<span class="sourceLineNo">367</span>    byte[] metaKey;<a name="line.367"></a>
-<span class="sourceLineNo">368</span>    if (req.locateType.equals(RegionLocateType.BEFORE)) {<a name="line.368"></a>
-<span class="sourceLineNo">369</span>      if (isEmptyStopRow(req.row)) {<a name="line.369"></a>
-<span class="sourceLineNo">370</span>        byte[] binaryTableName = tableName.getName();<a name="line.370"></a>
-<span class="sourceLineNo">371</span>        metaKey = Arrays.copyOf(binaryTableName, binaryTableName.length + 1);<a name="line.371"></a>
-<span class="sourceLineNo">372</span>      } else {<a name="line.372"></a>
-<span class="sourceLineNo">373</span>        metaKey = createRegionName(tableName, req.row, ZEROES, false);<a name="line.373"></a>
-<span class="sourceLineNo">374</span>      }<a name="line.374"></a>
-<span class="sourceLineNo">375</span>    } else {<a name="line.375"></a>
-<span class="sourceLineNo">376</span>      metaKey = createRegionName(tableName, req.row, NINES, false);<a name="line.376"></a>
-<span class="sourceLineNo">377</span>    }<a name="line.377"></a>
-<span class="sourceLineNo">378</span>    conn.getRawTable(META_TABLE_NAME)<a name="line.378"></a>
-<span class="sourceLineNo">379</span>        .scanAll(new Scan().withStartRow(metaKey).setReversed(true).addFamily(CATALOG_FAMILY)<a name="line.379"></a>
-<span class="sourceLineNo">380</span>            .setOneRowLimit())<a name="line.380"></a>
-<span class="sourceLineNo">381</span>        .whenComplete((results, error) -&gt; onScanComplete(tableName, req, results, error));<a name="line.381"></a>
-<span class="sourceLineNo">382</span>  }<a name="line.382"></a>
-<span class="sourceLineNo">383</span><a name="line.383"></a>
-<span class="sourceLineNo">384</span>  private HRegionLocation locateInCache(TableCache tableCache, TableName tableName, byte[] row,<a name="line.384"></a>
-<span class="sourceLineNo">385</span>      RegionLocateType locateType) {<a name="line.385"></a>
-<span class="sourceLineNo">386</span>    return locateType.equals(RegionLocateType.BEFORE)<a name="line.386"></a>
-<span class="sourceLineNo">387</span>        ? locateRowBeforeInCache(tableCache, tableName, row)<a name="line.387"></a>
-<span class="sourceLineNo">388</span>        : locateRowInCache(tableCache, tableName, row);<a name="line.388"></a>
-<span class="sourceLineNo">389</span>  }<a name="line.389"></a>
-<span class="sourceLineNo">390</span><a name="line.390"></a>
-<span class="sourceLineNo">391</span>  // locateToPrevious is true means we will use the start key of a region to locate the region<a name="line.391"></a>
-<span class="sourceLineNo">392</span>  // placed before it. Used for reverse scan. See the comment of<a name="line.392"></a>
-<span class="sourceLineNo">393</span>  // AsyncRegionLocator.getPreviousRegionLocation.<a name="line.393"></a>
-<span class="sourceLineNo">394</span>  private CompletableFuture&lt;HRegionLocation&gt; getRegionLocationInternal(TableName tableName,<a name="line.394"></a>
-<span class="sourceLineNo">395</span>      byte[] row, RegionLocateType locateType, boolean reload) {<a name="line.395"></a>
-<span class="sourceLineNo">396</span>    // AFTER should be convert to CURRENT before calling this method<a name="line.396"></a>
-<span class="sourceLineNo">397</span>    assert !locateType.equals(RegionLocateType.AFTER);<a name="line.397"></a>
-<span class="sourceLineNo">398</span>    TableCache tableCache = getTableCache(tableName);<a name="line.398"></a>
-<span class="sourceLineNo">399</span>    if (!reload) {<a name="line.399"></a>
-<span class="sourceLineNo">400</span>      HRegionLocation loc = locateInCache(tableCache, tableName, row, locateType);<a name="line.400"></a>
-<span class="sourceLineNo">401</span>      if (loc != null) {<a name="line.401"></a>
-<span class="sourceLineNo">402</span>        return CompletableFuture.completedFuture(loc);<a name="line.402"></a>
-<span class="sourceLineNo">403</span>      }<a name="line.403"></a>
-<span class="sourceLineNo">404</span>    }<a name="line.404"></a>
-<span class="sourceLineNo">405</span>    CompletableFuture&lt;HRegionLocation&gt; future;<a name="line.405"></a>
-<span class="sourceLineNo">406</span>    LocateRequest req;<a name="line.406"></a>
-<span class="sourceLineNo">407</span>    boolean sendRequest = false;<a name="line.407"></a>
-<span class="sourceLineNo">408</span>    synchronized (tableCache) {<a name="line.408"></a>
-<span class="sourceLineNo">409</span>      // check again<a name="line.409"></a>
-<span class="sourceLineNo">410</span>      if (!reload) {<a name="line.410"></a>
-<span class="sourceLineNo">411</span>        HRegionLocation loc = locateInCache(tableCache, tableName, row, locateType);<a name="line.411"></a>
-<span class="sourceLineNo">412</span>        if (loc != null) {<a name="line.412"></a>
-<span class="sourceLineNo">413</span>          return CompletableFuture.completedFuture(loc);<a name="line.413"></a>
-<span class="sourceLineNo">414</span>        }<a name="line.414"></a>
-<span class="sourceLineNo">415</span>      }<a name="line.415"></a>
-<span class="sourceLineNo">416</span>      req = new LocateRequest(row, locateType);<a name="line.416"></a>
-<span class="sourceLineNo">417</span>      future = tableCache.allRequests.get(req);<a name="line.417"></a>
-<span class="sourceLineNo">418</span>      if (future == null) {<a name="line.418"></a>
-<span class="sourceLineNo">419</span>        future = new CompletableFuture&lt;&gt;();<a name="line.419"></a>
-<span class="sourceLineNo">420</span>        tableCache.allRequests.put(req, future);<a name="line.420"></a>
-<span class="sourceLineNo">421</span>        if (tableCache.hasQuota(maxConcurrentLocateRequestPerTable) &amp;&amp; !tableCache.isPending(req)) {<a name="line.421"></a>
-<span class="sourceLineNo">422</span>          tableCache.send(req);<a name="line.422"></a>
-<span class="sourceLineNo">423</span>          sendRequest = true;<a name="line.423"></a>
-<span class="sourceLineNo">424</span>        }<a name="line.424"></a>
-<span class="sourceLineNo">425</span>      }<a name="line.425"></a>
-<span class="sourceLineNo">426</span>    }<a name="line.426"></a>
-<span class="sourceLineNo">427</span>    if (sendRequest) {<a name="line.427"></a>
-<span class="sourceLineNo">428</span>      locateInMeta(tableName, req);<a name="line.428"></a>
-<span class="sourceLineNo">429</span>    }<a name="line.429"></a>
-<span class="sourceLineNo">430</span>    return future;<a name="line.430"></a>
-<span class="sourceLineNo">431</span>  }<a name="line.431"></a>
-<span class="sourceLineNo">432</span><a name="line.432"></a>
-<span class="sourceLineNo">433</span>  CompletableFuture&lt;HRegionLocation&gt; getRegionLocation(TableName tableName, byte[] row,<a name="line.433"></a>
-<span class="sourceLineNo">434</span>      RegionLocateType locateType, boolean reload) {<a name="line.434"></a>
-<span class="sourceLineNo">435</span>    if (locateType.equals(RegionLocateType.BEFORE)) {<a name="line.435"></a>
-<span class="sourceLineNo">436</span>      return getRegionLocationInternal(tableName, row, locateType, reload);<a name="line.436"></a>
-<span class="sourceLineNo">437</span>    } else {<a name="line.437"></a>
-<span class="sourceLineNo">438</span>      // as we know the exact row after us, so we can just create the new row, and use the same<a name="line.438"></a>
-<span class="sourceLineNo">439</span>      // algorithm to locate it.<a name="line.439"></a>
-<span class="sourceLineNo">440</span>      if (locateType.equals(RegionLocateType.AFTER)) {<a name="line.440"></a>
-<span class="sourceLineNo">441</span>        row = createClosestRowAfter(row);<a name="line.441"></a>
-<span class="sourceLineNo">442</span>      }<a name="line.442"></a>
-<span class="sourceLineNo">443</span>      return getRegionLocationInternal(tableName, row, RegionLocateType.CURRENT, reload);<a name="line.443"></a>
-<span class="sourceLineNo">444</span>    }<a name="line.444"></a>
-<span class="sourceLineNo">445</span>  }<a name="line.445"></a>
-<span class="sourceLineNo">446</span><a name="line.446"></a>
-<span class="sourceLineNo">447</span>  void updateCachedLocation(HRegionLocation loc, Throwable exception) {<a name="line.447"></a>
-<span class="sourceLineNo">448</span>    AsyncRegionLocator.updateCachedLocation(loc, exception, l -&gt; {<a name="line.448"></a>
-<span class="sourceLineNo">449</span>      TableCache tableCache = cache.get(l.getRegionInfo().getTable());<a name="line.449"></a>
-<span class="sourceLineNo">450</span>      if (tableCache == null) {<a name="line.450"></a>
-<span class="sourceLineNo">451</span>        return null;<a name="line.451"></a>
-<span class="sourceLineNo">452</span>      }<a name="line.452"></a>
-<span class="sourceLineNo">453</span>      return tableCache.cache.get(l.getRegionInfo().getStartKey());<a name="line.453"></a>
-<span class="sourceLineNo">454</span>    }, this::addToCache, this::removeFromCache);<a name="line.454"></a>
-<span class="sourceLineNo">455</span>  }<a name="line.455"></a>
-<span class="sourceLineNo">456</span><a name="line.456"></a>
-<span class="sourceLineNo">457</span>  void clearCache(TableName tableName) {<a name="line.457"></a>
-<span class="sourceLineNo">458</span>    TableCache tableCache = cache.remove(tableName);<a name="line.458"></a>
-<span class="sourceLineNo">459</span>    if (tableCache == null) {<a name="line.459"></a>
-<span class="sourceLineNo">460</span>      return;<a name="line.460"></a>
-<span class="sourceLineNo">461</span>    }<a name="line.461"></a>
-<span class="sourceLineNo">462</span>    synchronized (tableCache) {<a name="line.462"></a>
-<span class="sourceLineNo">463</span>      if (!tableCache.allRequests.isEmpty()) {<a name="line.463"></a>
-<span class="sourceLineNo">464</span>        IOException error = new IOException("Cache cleared");<a name="line.464"></a>
-<span class="sourceLineNo">465</span>        tableCache.allRequests.values().forEach(f -&gt; f.completeExceptionally(error));<a name="line.465"></a>
-<span class="sourceLineNo">466</span>      }<a name="line.466"></a>
-<span class="sourceLineNo">467</span>    }<a name="line.467"></a>
-<span class="sourceLineNo">468</span>  }<a name="line.468"></a>
-<span class="sourceLineNo">469</span>}<a name="line.469"></a>
+<span class="sourceLineNo">314</span>    if (info.isOffline()) {<a name="line.314"></a>
+<span class="sourceLineNo">315</span>      complete(tableName, req, null, new RegionOfflineException("the region is offline, could" +<a name="line.315"></a>
+<span class="sourceLineNo">316</span>          " be caused by a disable table call: '" + info.getRegionNameAsString() + "'"));<a name="line.316"></a>
+<span class="sourceLineNo">317</span>      return;<a name="line.317"></a>
+<span class="sourceLineNo">318</span>    }<a name="line.318"></a>
+<span class="sourceLineNo">319</span>    if (loc.getServerName() == null) {<a name="line.319"></a>
+<span class="sourceLineNo">320</span>      complete(tableName, req, null,<a name="line.320"></a>
+<span class="sourceLineNo">321</span>        new NoServerForRegionException(<a name="line.321"></a>
+<span class="sourceLineNo">322</span>            String.format("No server address listed for region '%s', row='%s', locateType=%s",<a name="line.322"></a>
+<span class="sourceLineNo">323</span>              info.getRegionNameAsString(), Bytes.toStringBinary(req.row), req.locateType)));<a name="line.323"></a>
+<span class="sourceLineNo">324</span>      return;<a name="line.324"></a>
+<span class="sourceLineNo">325</span>    }<a name="line.325"></a>
+<span class="sourceLineNo">326</span>    complete(tableName, req, loc, null);<a name="line.326"></a>
+<span class="sourceLineNo">327</span>  }<a name="line.327"></a>
+<span class="sourceLineNo">328</span><a name="line.328"></a>
+<span class="sourceLineNo">329</span>  private HRegionLocation locateRowInCache(TableCache tableCache, TableName tableName, byte[] row) {<a name="line.329"></a>
+<span class="sourceLineNo">330</span>    Map.Entry&lt;byte[], HRegionLocation&gt; entry = tableCache.cache.floorEntry(row);<a name="line.330"></a>
+<span class="sourceLineNo">331</span>    if (entry == null) {<a name="line.331"></a>
+<span class="sourceLineNo">332</span>      return null;<a name="line.332"></a>
+<span class="sourceLineNo">333</span>    }<a name="line.333"></a>
+<span class="sourceLineNo">334</span>    HRegionLocation loc = entry.getValue();<a name="line.334"></a>
+<span class="sourceLineNo">335</span>    byte[] endKey = loc.getRegionInfo().getEndKey();<a name="line.335"></a>
+<span class="sourceLineNo">336</span>    if (isEmptyStopRow(endKey) || Bytes.compareTo(row, endKey) &lt; 0) {<a name="line.336"></a>
+<span class="sourceLineNo">337</span>      if (LOG.isTraceEnabled()) {<a name="line.337"></a>
+<span class="sourceLineNo">338</span>        LOG.trace("Found " + loc + " in cache for '" + tableName + "', row='" +<a name="line.338"></a>
+<span class="sourceLineNo">339</span>            Bytes.toStringBinary(row) + "', locateType=" + RegionLocateType.CURRENT);<a name="line.339"></a>
+<span class="sourceLineNo">340</span>      }<a name="line.340"></a>
+<span class="sourceLineNo">341</span>      return loc;<a name="line.341"></a>
+<span class="sourceLineNo">342</span>    } else {<a name="line.342"></a>
+<span class="sourceLineNo">343</span>      return null;<a name="line.343"></a>
+<span class="sourceLineNo">344</span>    }<a name="line.344"></a>
+<span class="sourceLineNo">345</span>  }<a name="line.345"></a>
+<span class="sourceLineNo">346</span><a name="line.346"></a>
+<span class="sourceLineNo">347</span>  private HRegionLocation locateRowBeforeInCache(TableCache tableCache, TableName tableName,<a name="line.347"></a>
+<span class="sourceLineNo">348</span>      byte[] row) {<a name="line.348"></a>
+<span class="sourceLineNo">349</span>    Map.Entry&lt;byte[], HRegionLocation&gt; entry =<a name="line.349"></a>
+<span class="sourceLineNo">350</span>        isEmptyStopRow(row) ? tableCache.cache.lastEntry() : tableCache.cache.lowerEntry(row);<a name="line.350"></a>
+<span class="sourceLineNo">351</span>    if (entry == null) {<a name="line.351"></a>
+<span class="sourceLineNo">352</span>      return null;<a name="line.352"></a>
+<span class="sourceLineNo">353</span>    }<a name="line.353"></a>
+<span class="sourceLineNo">354</span>    HRegionLocation loc = entry.getValue();<a name="line.354"></a>
+<span class="sourceLineNo">355</span>    if (isEmptyStopRow(loc.getRegionInfo().getEndKey()) ||<a name="line.355"></a>
+<span class="sourceLineNo">356</span>        Bytes.compareTo(loc.getRegionInfo().getEndKey(), row) &gt;= 0) {<a name="line.356"></a>
+<span class="sourceLineNo">357</span>      if (LOG.isTraceEnabled()) {<a name="line.357"></a>
+<span class="sourceLineNo">358</span>        LOG.trace("Found " + loc + " in cache for '" + tableName + "', row='" +<a name="line.358"></a>
+<span class="sourceLineNo">359</span>            Bytes.toStringBinary(row) + "', locateType=" + RegionLocateType.BEFORE);<a name="line.359"></a>
+<span class="sourceLineNo">360</span>      }<a name="line.360"></a>
+<span class="sourceLineNo">361</span>      return loc;<a name="line.361"></a>
+<span class="sourceLineNo">362</span>    } else {<a name="line.362"></a>
+<span class="sourceLineNo">363</span>      return null;<a name="line.363"></a>
+<span class="sourceLineNo">364</span>    }<a name="line.364"></a>
+<span class="sourceLineNo">365</span>  }<a name="line.365"></a>
+<span class="sourceLineNo">366</span><a name="line.366"></a>
+<span class="sourceLineNo">367</span>  private void locateInMeta(TableName tableName, LocateRequest req) {<a name="line.367"></a>
+<span class="sourceLineNo">368</span>    if (LOG.isTraceEnabled()) {<a name="line.368"></a>
+<span class="sourceLineNo">369</span>      LOG.trace("Try locate '" + tableName + "', row='" + Bytes.toStringBinary(req.row) +<a name="line.369"></a>
+<span class="sourceLineNo">370</span>          "', locateType=" + req.locateType + " in meta");<a name="line.370"></a>
+<span class="sourceLineNo">371</span>    }<a name="line.371"></a>
+<span class="sourceLineNo">372</span>    byte[] metaKey;<a name="line.372"></a>
+<span class="sourceLineNo">373</span>    if (req.locateType.equals(RegionLocateType.BEFORE)) {<a name="line.373"></a>
+<span class="sourceLineNo">374</span>      if (isEmptyStopRow(req.row)) {<a name="line.374"></a>
+<span class="sourceLineNo">375</span>        byte[] binaryTableName = tableName.getName();<a name="line.375"></a>
+<span class="sourceLineNo">376</span>        metaKey = Arrays.copyOf(binaryTableName, binaryTableName.length + 1);<a name="line.376"></a>
+<span class="sourceLineNo">377</span>      } else {<a name="line.377"></a>
+<span class="sourceLineNo">378</span>        metaKey = createRegionName(tableName, req.row, ZEROES, false);<a name="line.378"></a>
+<span class="sourceLineNo">379</span>      }<a name="line.379"></a>
+<span class="sourceLineNo">380</span>    } else {<a name="line.380"></a>
+<span class="sourceLineNo">381</span>      metaKey = createRegionName(tableName, req.row, NINES, false);<a name="line.381"></a>
+<span class="sourceLineNo">382</span>    }<a name="line.382"></a>
+<span class="sourceLineNo">383</span>    conn.getRawTable(META_TABLE_NAME)<a name="line.383"></a>
+<span class="sourceLineNo">384</span>        .scanAll(new Scan().withStartRow(metaKey).setReversed(true).addFamily(CATALOG_FAMILY)<a name="line.384"></a>
+<span class="sourceLineNo">385</span>            .setOneRowLimit())<a name="line.385"></a>
+<span class="sourceLineNo">386</span>        .whenComplete((results, error) -&gt; onScanComplete(tableName, req, results, error));<a name="line.386"></a>
+<span class="sourceLineNo">387</span>  }<a name="line.387"></a>
+<span class="sourceLineNo">388</span><a name="line.388"></a>
+<span class="sourceLineNo">389</span>  private HRegionLocation locateInCache(TableCache tableCache, TableName tableName, byte[] row,<a name="line.389"></a>
+<span class="sourceLineNo">390</span>      RegionLocateType locateType) {<a name="line.390"></a>
+<span class="sourceLineNo">391</span>    return locateType.equals(RegionLocateType.BEFORE)<a name="line.391"></a>
+<span class="sourceLineNo">392</span>        ? locateRowBeforeInCache(tableCache, tableName, row)<a name="line.392"></a>
+<span class="sourceLineNo">393</span>        : locateRowInCache(tableCache, tableName, row);<a name="line.393"></a>
+<span class="sourceLineNo">394</span>  }<a name="line.394"></a>
+<span class="sourceLineNo">395</span><a name="line.395"></a>
+<span class="sourceLineNo">396</span>  // locateToPrevious is true means we will use the start key of a region to locate the region<a name="line.396"></a>
+<span class="sourceLineNo">397</span>  // placed before it. Used for reverse scan. See the comment of<a name="line.397"></a>
+<span class="sourceLineNo">398</span>  // AsyncRegionLocator.getPreviousRegionLocation.<a name="line.398"></a>
+<span class="sourceLineNo">399</span>  private CompletableFuture&lt;HRegionLocation&gt; getRegionLocationInternal(TableName tableName,<a name="line.399"></a>
+<span class="sourceLineNo">400</span>      byte[] row, RegionLocateType locateType, boolean reload) {<a name="line.400"></a>
+<span class="sourceLineNo">401</span>    // AFTER should be convert to CURRENT before calling this method<a name="line.401"></a>
+<span class="sourceLineNo">402</span>    assert !locateType.equals(RegionLocateType.AFTER);<a name="line.402"></a>
+<span class="sourceLineNo">403</span>    TableCache tableCache = getTableCache(tableName);<a name="line.403"></a>
+<span class="sourceLineNo">404</span>    if (!reload) {<a name="line.404"></a>
+<span class="sourceLineNo">405</span>      HRegionLocation loc = locateInCache(tableCache, tableName, row, locateType);<a name="line.405"></a>
+<span class="sourceLineNo">406</span>      if (loc != null) {<a name="line.406"></a>
+<span class="sourceLineNo">407</span>        return CompletableFuture.completedFuture(loc);<a name="line.407"></a>
+<span class="sourceLineNo">408</span>      }<a name="line.408"></a>
+<span class="sourceLineNo">409</span>    }<a name="line.409"></a>
+<span class="sourceLineNo">410</span>    CompletableFuture&lt;HRegionLocation&gt; future;<a name="line.410"></a>
+<span class="sourceLineNo">411</span>    LocateRequest req;<a name="line.411"></a>
+<span class="sourceLineNo">412</span>    boolean sendRequest = false;<a name="line.412"></a>
+<span class="sourceLineNo">413</span>    synchronized (tableCache) {<a name="line.413"></a>
+<span class="sourceLineNo">414</span>      // check again<a name="line.414"></a>
+<span class="sourceLineNo">415</span>      if (!reload) {<a name="line.415"></a>
+<span class="sourceLineNo">416</span>        HRegionLocation loc = locateInCache(tableCache, tableName, row, locateType);<a name="line.416"></a>
+<span class="sourceLineNo">417</span>        if (loc != null) {<a name="line.417"></a>
+<span class="sourceLineNo">418</span>          return CompletableFuture.completedFuture(loc);<a name="line.418"></a>
+<span class="sourceLineNo">419</span>        }<a name="line.419"></a>
+<span class="sourceLineNo">420</span>      }<a name="line.420"></a>
+<span class="sourceLineNo">421</span>      req = new LocateRequest(row, locateType);<a name="line.421"></a>
+<span class="sourceLineNo">422</span>      future = tableCache.allRequests.get(req);<a name="line.422"></a>
+<span class="sourceLineNo">423</span>      if (future == null) {<a name="line.423"></a>
+<span class="sourceLineNo">424</span>        future = new CompletableFuture&lt;&gt;();<a name="line.424"></a>
+<span class="sourceLineNo">425</span>        tableCache.allRequests.put(req, future);<a name="line.425"></a>
+<span class="sourceLineNo">426</span>        if (tableCache.hasQuota(maxConcurrentLocateRequestPerTable) &amp;&amp; !tableCache.isPending(req)) {<a name="line.426"></a>
+<span class="sourceLineNo">427</span>          tableCache.send(req);<a name="line.427"></a>
+<span class="sourceLineNo">428</span>          sendRequest = true;<a name="line.428"></a>
+<span class="sourceLineNo">429</span>        }<a name="line.429"></a>
+<span class="sourceLineNo">430</span>      }<a name="line.430"></a>
+<span class="sourceLineNo">431</span>    }<a name="line.431"></a>
+<span class="sourceLineNo">432</span>    if (sendRequest) {<a name="line.432"></a>
+<span class="sourceLineNo">433</span>      locateInMeta(tableName, req);<a name="line.433"></a>
+<span class="sourceLineNo">434</span>    }<a name="line.434"></a>
+<span class="sourceLineNo">435</span>    return future;<a name="line.435"></a>
+<span class="sourceLineNo">436</span>  }<a name="line.436"></a>
+<span class="sourceLineNo">437</span><a name="line.437"></a>
+<span class="sourceLineNo">438</span>  CompletableFuture&lt;HRegionLocation&gt; getRegionLocation(TableName tableName, byte[] row,<a name="line.438"></a>
+<span class="sourceLineNo">439</span>      RegionLocateType locateType, boolean reload) {<a name="line.439"></a>
+<span class="sourceLineNo">440</span>    if (locateType.equals(RegionLocateType.BEFORE)) {<a name="line.440"></a>
+<span class="sourceLineNo">441</span>      return getRegionLocationInternal(tableName, row, locateType, reload);<a name="line.441"></a>
+<span class="sourceLineNo">442</span>    } else {<a name="line.442"></a>
+<span class="sourceLineNo">443</span>      // as we know the exact row after us, so we can just create the new row, and use the same<a name="line.443"></a>
+<span class="sourceLineNo">444</span>      // algorithm to locate it.<a name="line.444"></a>
+<span class="sourceLineNo">445</span>      if (locateType.equals(RegionLocateType.AFTER)) {<a name="line.445"></a>
+<span class="sourceLineNo">446</span>        row = createClosestRowAfter(row);<a name="line.446"></a>
+<span class="sourceLineNo">447</span>      }<a name="line.447"></a>
+<span class="sourceLineNo">448</span>      return getRegionLocationInternal(tableName, row, RegionLocateType.CURRENT, reload);<a name="line.448"></a>
+<span class="sourceLineNo">449</span>    }<a name="line.449"></a>
+<span class="sourceLineNo">450</span>  }<a name="line.450"></a>
+<span class="sourceLineNo">451</span><a name="line.451"></a>
+<span class="sourceLineNo">452</span>  void updateCachedLocation(HRegionLocation loc, Throwable exception) {<a name="line.452"></a>
+<span class="sourceLineNo">453</span>    AsyncRegionLocator.updateCachedLocation(loc, exception, l -&gt; {<a name="line.453"></a>
+<span class="sourceLineNo">454</span>      TableCache tableCache = cache.get(l.getRegionInfo().getTable());<a name="line.454"></a>
+<span class="sourceLineNo">455</span>      if (tableCache == null) {<a name="line.455"></a>
+<span class="sourceLineNo">456</span>        return null;<a name="line.456"></a>
+<span class="sourceLineNo">457</span>      }<a name="line.457"></a>
+<span class="sourceLineNo">458</span>      return tableCache.cache.get(l.getRegionInfo().getStartKey());<a name="line.458"></a>
+<span class="sourceLineNo">459</span>    }, this::addToCache, this::removeFromCache);<a name="line.459"></a>
+<span class="sourceLineNo">460</span>  }<a name="line.460"></a>
+<span class="sourceLineNo">461</span><a name="line.461"></a>
+<span class="sourceLineNo">462</span>  void clearCache(TableName tableName) {<a name="line.462"></a>
+<span class="sourceLineNo">463</span>    TableCache tableCache = cache.remove(tableName);<a name="line.463"></a>
+<span class="sourceLineNo">464</span>    if (tableCache == null) {<a name="line.464"></a>
+<span class="sourceLineNo">465</span>      return;<a name="line.465"></a>
+<span class="sourceLineNo">466</span>    }<a name="line.466"></a>
+<span class="sourceLineNo">467</span>    synchronized (tableCache) {<a name="line.467"></a>
+<span class="sourceLineNo">468</span>      if (!tableCache.allRequests.isEmpty()) {<a name="line.468"></a>
+<span class="sourceLineNo">469</span>        IOException error = new IOException("Cache cleared");<a name="line.469"></a>
+<span class="sourceLineNo">470</span>        tableCache.allRequests.values().forEach(f -&gt; f.completeExceptionally(error));<a name="line.470"></a>
+<span class="sourceLineNo">471</span>      }<a name="line.471"></a>
+<span class="sourceLineNo">472</span>    }<a name="line.472"></a>
+<span class="sourceLineNo">473</span>  }<a name="line.473"></a>
+<span class="sourceLineNo">474</span>}<a name="line.474"></a>
 
 
 


Mime
View raw message