hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [11/17] hbase-site git commit: Published site at adc0e85e8532870fa83cb21a44061c83ae77ec34.
Date Sat, 07 Apr 2018 14:48:23 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/1ee65067/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.LocateRequest.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.LocateRequest.html b/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.LocateRequest.html
index 63b8c53..88e70e2 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.LocateRequest.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.LocateRequest.html
@@ -25,460 +25,470 @@
 <span class="sourceLineNo">017</span> */<a name="line.17"></a>
 <span class="sourceLineNo">018</span>package org.apache.hadoop.hbase.client;<a name="line.18"></a>
 <span class="sourceLineNo">019</span><a name="line.19"></a>
-<span class="sourceLineNo">020</span>import static org.apache.hadoop.hbase.HConstants.CATALOG_FAMILY;<a name="line.20"></a>
-<span class="sourceLineNo">021</span>import static org.apache.hadoop.hbase.HConstants.NINES;<a name="line.21"></a>
-<span class="sourceLineNo">022</span>import static org.apache.hadoop.hbase.HConstants.ZEROES;<a name="line.22"></a>
-<span class="sourceLineNo">023</span>import static org.apache.hadoop.hbase.TableName.META_TABLE_NAME;<a name="line.23"></a>
-<span class="sourceLineNo">024</span>import static org.apache.hadoop.hbase.client.ConnectionUtils.createClosestRowAfter;<a name="line.24"></a>
-<span class="sourceLineNo">025</span>import static org.apache.hadoop.hbase.client.ConnectionUtils.isEmptyStopRow;<a name="line.25"></a>
-<span class="sourceLineNo">026</span>import static org.apache.hadoop.hbase.client.RegionInfo.createRegionName;<a name="line.26"></a>
-<span class="sourceLineNo">027</span>import static org.apache.hadoop.hbase.util.Bytes.BYTES_COMPARATOR;<a name="line.27"></a>
-<span class="sourceLineNo">028</span>import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent;<a name="line.28"></a>
-<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.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.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.hadoop.hbase.DoNotRetryIOException;<a name="line.45"></a>
-<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.HRegionLocation;<a name="line.46"></a>
-<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.MetaTableAccessor;<a name="line.47"></a>
-<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.RegionLocations;<a name="line.48"></a>
-<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.TableName;<a name="line.49"></a>
-<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.TableNotFoundException;<a name="line.50"></a>
-<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.51"></a>
-<span class="sourceLineNo">052</span>import org.apache.yetus.audience.InterfaceAudience;<a name="line.52"></a>
-<span class="sourceLineNo">053</span>import org.slf4j.Logger;<a name="line.53"></a>
-<span class="sourceLineNo">054</span>import org.slf4j.LoggerFactory;<a name="line.54"></a>
-<span class="sourceLineNo">055</span><a name="line.55"></a>
-<span class="sourceLineNo">056</span>/**<a name="line.56"></a>
-<span class="sourceLineNo">057</span> * The asynchronous locator for regions other than meta.<a name="line.57"></a>
-<span class="sourceLineNo">058</span> */<a name="line.58"></a>
-<span class="sourceLineNo">059</span>@InterfaceAudience.Private<a name="line.59"></a>
-<span class="sourceLineNo">060</span>class AsyncNonMetaRegionLocator {<a name="line.60"></a>
-<span class="sourceLineNo">061</span><a name="line.61"></a>
-<span class="sourceLineNo">062</span>  private static final Logger LOG = LoggerFactory.getLogger(AsyncNonMetaRegionLocator.class);<a name="line.62"></a>
-<span class="sourceLineNo">063</span><a name="line.63"></a>
-<span class="sourceLineNo">064</span>  static final String MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE =<a name="line.64"></a>
-<span class="sourceLineNo">065</span>    "hbase.client.meta.max.concurrent.locate.per.table";<a name="line.65"></a>
-<span class="sourceLineNo">066</span><a name="line.66"></a>
-<span class="sourceLineNo">067</span>  private static final int DEFAULT_MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE = 8;<a name="line.67"></a>
-<span class="sourceLineNo">068</span><a name="line.68"></a>
-<span class="sourceLineNo">069</span>  private final AsyncConnectionImpl conn;<a name="line.69"></a>
-<span class="sourceLineNo">070</span><a name="line.70"></a>
-<span class="sourceLineNo">071</span>  private final int maxConcurrentLocateRequestPerTable;<a name="line.71"></a>
-<span class="sourceLineNo">072</span><a name="line.72"></a>
-<span class="sourceLineNo">073</span>  private final ConcurrentMap&lt;TableName, TableCache&gt; cache = new ConcurrentHashMap&lt;&gt;();<a name="line.73"></a>
-<span class="sourceLineNo">074</span><a name="line.74"></a>
-<span class="sourceLineNo">075</span>  private static final class LocateRequest {<a name="line.75"></a>
-<span class="sourceLineNo">076</span><a name="line.76"></a>
-<span class="sourceLineNo">077</span>    public final byte[] row;<a name="line.77"></a>
-<span class="sourceLineNo">078</span><a name="line.78"></a>
-<span class="sourceLineNo">079</span>    public final RegionLocateType locateType;<a name="line.79"></a>
-<span class="sourceLineNo">080</span><a name="line.80"></a>
-<span class="sourceLineNo">081</span>    public LocateRequest(byte[] row, RegionLocateType locateType) {<a name="line.81"></a>
-<span class="sourceLineNo">082</span>      this.row = row;<a name="line.82"></a>
-<span class="sourceLineNo">083</span>      this.locateType = locateType;<a name="line.83"></a>
-<span class="sourceLineNo">084</span>    }<a name="line.84"></a>
-<span class="sourceLineNo">085</span><a name="line.85"></a>
-<span class="sourceLineNo">086</span>    @Override<a name="line.86"></a>
-<span class="sourceLineNo">087</span>    public int hashCode() {<a name="line.87"></a>
-<span class="sourceLineNo">088</span>      return Bytes.hashCode(row) ^ locateType.hashCode();<a name="line.88"></a>
-<span class="sourceLineNo">089</span>    }<a name="line.89"></a>
-<span class="sourceLineNo">090</span><a name="line.90"></a>
-<span class="sourceLineNo">091</span>    @Override<a name="line.91"></a>
-<span class="sourceLineNo">092</span>    public boolean equals(Object obj) {<a name="line.92"></a>
-<span class="sourceLineNo">093</span>      if (obj == null || obj.getClass() != LocateRequest.class) {<a name="line.93"></a>
-<span class="sourceLineNo">094</span>        return false;<a name="line.94"></a>
-<span class="sourceLineNo">095</span>      }<a name="line.95"></a>
-<span class="sourceLineNo">096</span>      LocateRequest that = (LocateRequest) obj;<a name="line.96"></a>
-<span class="sourceLineNo">097</span>      return locateType.equals(that.locateType) &amp;&amp; Bytes.equals(row, that.row);<a name="line.97"></a>
-<span class="sourceLineNo">098</span>    }<a name="line.98"></a>
-<span class="sourceLineNo">099</span>  }<a name="line.99"></a>
-<span class="sourceLineNo">100</span><a name="line.100"></a>
-<span class="sourceLineNo">101</span>  private static final class TableCache {<a name="line.101"></a>
-<span class="sourceLineNo">102</span><a name="line.102"></a>
-<span class="sourceLineNo">103</span>    public final ConcurrentNavigableMap&lt;byte[], HRegionLocation&gt; cache =<a name="line.103"></a>
-<span class="sourceLineNo">104</span>      new ConcurrentSkipListMap&lt;&gt;(BYTES_COMPARATOR);<a name="line.104"></a>
-<span class="sourceLineNo">105</span><a name="line.105"></a>
-<span class="sourceLineNo">106</span>    public final Set&lt;LocateRequest&gt; pendingRequests = new HashSet&lt;&gt;();<a name="line.106"></a>
-<span class="sourceLineNo">107</span><a name="line.107"></a>
-<span class="sourceLineNo">108</span>    public final Map&lt;LocateRequest, CompletableFuture&lt;HRegionLocation&gt;&gt; allRequests =<a name="line.108"></a>
-<span class="sourceLineNo">109</span>      new LinkedHashMap&lt;&gt;();<a name="line.109"></a>
-<span class="sourceLineNo">110</span><a name="line.110"></a>
-<span class="sourceLineNo">111</span>    public boolean hasQuota(int max) {<a name="line.111"></a>
-<span class="sourceLineNo">112</span>      return pendingRequests.size() &lt; max;<a name="line.112"></a>
-<span class="sourceLineNo">113</span>    }<a name="line.113"></a>
-<span class="sourceLineNo">114</span><a name="line.114"></a>
-<span class="sourceLineNo">115</span>    public boolean isPending(LocateRequest req) {<a name="line.115"></a>
-<span class="sourceLineNo">116</span>      return pendingRequests.contains(req);<a name="line.116"></a>
-<span class="sourceLineNo">117</span>    }<a name="line.117"></a>
-<span class="sourceLineNo">118</span><a name="line.118"></a>
-<span class="sourceLineNo">119</span>    public void send(LocateRequest req) {<a name="line.119"></a>
-<span class="sourceLineNo">120</span>      pendingRequests.add(req);<a name="line.120"></a>
-<span class="sourceLineNo">121</span>    }<a name="line.121"></a>
-<span class="sourceLineNo">122</span><a name="line.122"></a>
-<span class="sourceLineNo">123</span>    public Optional&lt;LocateRequest&gt; getCandidate() {<a name="line.123"></a>
-<span class="sourceLineNo">124</span>      return allRequests.keySet().stream().filter(r -&gt; !isPending(r)).findFirst();<a name="line.124"></a>
-<span class="sourceLineNo">125</span>    }<a name="line.125"></a>
-<span class="sourceLineNo">126</span><a name="line.126"></a>
-<span class="sourceLineNo">127</span>    public void clearCompletedRequests(Optional&lt;HRegionLocation&gt; location) {<a name="line.127"></a>
-<span class="sourceLineNo">128</span>      for (Iterator&lt;Map.Entry&lt;LocateRequest, CompletableFuture&lt;HRegionLocation&gt;&gt;&gt; iter =<a name="line.128"></a>
-<span class="sourceLineNo">129</span>        allRequests.entrySet().iterator(); iter.hasNext();) {<a name="line.129"></a>
-<span class="sourceLineNo">130</span>        Map.Entry&lt;LocateRequest, CompletableFuture&lt;HRegionLocation&gt;&gt; entry = iter.next();<a name="line.130"></a>
-<span class="sourceLineNo">131</span>        if (tryComplete(entry.getKey(), entry.getValue(), location)) {<a name="line.131"></a>
-<span class="sourceLineNo">132</span>          iter.remove();<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>    }<a name="line.135"></a>
-<span class="sourceLineNo">136</span><a name="line.136"></a>
-<span class="sourceLineNo">137</span>    private boolean tryComplete(LocateRequest req, CompletableFuture&lt;HRegionLocation&gt; future,<a name="line.137"></a>
-<span class="sourceLineNo">138</span>        Optional&lt;HRegionLocation&gt; location) {<a name="line.138"></a>
-<span class="sourceLineNo">139</span>      if (future.isDone()) {<a name="line.139"></a>
-<span class="sourceLineNo">140</span>        return true;<a name="line.140"></a>
-<span class="sourceLineNo">141</span>      }<a name="line.141"></a>
-<span class="sourceLineNo">142</span>      if (!location.isPresent()) {<a name="line.142"></a>
-<span class="sourceLineNo">143</span>        return false;<a name="line.143"></a>
-<span class="sourceLineNo">144</span>      }<a name="line.144"></a>
-<span class="sourceLineNo">145</span>      HRegionLocation loc = location.get();<a name="line.145"></a>
-<span class="sourceLineNo">146</span>      boolean completed;<a name="line.146"></a>
-<span class="sourceLineNo">147</span>      if (req.locateType.equals(RegionLocateType.BEFORE)) {<a name="line.147"></a>
-<span class="sourceLineNo">148</span>        // for locating the row before current row, the common case is to find the previous region<a name="line.148"></a>
-<span class="sourceLineNo">149</span>        // in reverse scan, so we check the endKey first. In general, the condition should be<a name="line.149"></a>
-<span class="sourceLineNo">150</span>        // startKey &lt; req.row and endKey &gt;= req.row. Here we split it to endKey == req.row ||<a name="line.150"></a>
-<span class="sourceLineNo">151</span>        // (endKey &gt; req.row &amp;&amp; startKey &lt; req.row). The two conditions are equal since startKey &lt;<a name="line.151"></a>
-<span class="sourceLineNo">152</span>        // endKey.<a name="line.152"></a>
-<span class="sourceLineNo">153</span>        int c = Bytes.compareTo(loc.getRegion().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.getRegion().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.getRegion().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>    }<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.getRegion().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.getRegion().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.getRegion().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.getRegion().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("Failed to locate region in '" + tableName + "', row='" +<a name="line.235"></a>
-<span class="sourceLineNo">236</span>        Bytes.toStringBinary(req.row) + "', locateType=" + req.locateType, error);<a name="line.236"></a>
-<span class="sourceLineNo">237</span>    }<a name="line.237"></a>
-<span class="sourceLineNo">238</span>    Optional&lt;LocateRequest&gt; toSend = Optional.empty();<a name="line.238"></a>
-<span class="sourceLineNo">239</span>    TableCache tableCache = getTableCache(tableName);<a name="line.239"></a>
-<span class="sourceLineNo">240</span>    if (loc != null) {<a name="line.240"></a>
-<span class="sourceLineNo">241</span>      if (!addToCache(tableCache, loc)) {<a name="line.241"></a>
-<span class="sourceLineNo">242</span>        // someone is ahead of us.<a name="line.242"></a>
-<span class="sourceLineNo">243</span>        synchronized (tableCache) {<a name="line.243"></a>
-<span class="sourceLineNo">244</span>          tableCache.pendingRequests.remove(req);<a name="line.244"></a>
-<span class="sourceLineNo">245</span>          tableCache.clearCompletedRequests(Optional.empty());<a name="line.245"></a>
-<span class="sourceLineNo">246</span>          // Remove a complete locate request in a synchronized block, so the table cache must have<a name="line.246"></a>
-<span class="sourceLineNo">247</span>          // quota to send a candidate request.<a name="line.247"></a>
-<span class="sourceLineNo">248</span>          toSend = tableCache.getCandidate();<a name="line.248"></a>
-<span class="sourceLineNo">249</span>          toSend.ifPresent(r -&gt; tableCache.send(r));<a name="line.249"></a>
-<span class="sourceLineNo">250</span>        }<a name="line.250"></a>
-<span class="sourceLineNo">251</span>        toSend.ifPresent(r -&gt; locateInMeta(tableName, r));<a name="line.251"></a>
-<span class="sourceLineNo">252</span>        return;<a name="line.252"></a>
-<span class="sourceLineNo">253</span>      }<a name="line.253"></a>
-<span class="sourceLineNo">254</span>    }<a name="line.254"></a>
-<span class="sourceLineNo">255</span>    synchronized (tableCache) {<a name="line.255"></a>
-<span class="sourceLineNo">256</span>      tableCache.pendingRequests.remove(req);<a name="line.256"></a>
-<span class="sourceLineNo">257</span>      if (error instanceof DoNotRetryIOException) {<a name="line.257"></a>
-<span class="sourceLineNo">258</span>        CompletableFuture&lt;?&gt; future = tableCache.allRequests.remove(req);<a name="line.258"></a>
-<span class="sourceLineNo">259</span>        if (future != null) {<a name="line.259"></a>
-<span class="sourceLineNo">260</span>          future.completeExceptionally(error);<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>      tableCache.clearCompletedRequests(Optional.ofNullable(loc));<a name="line.263"></a>
-<span class="sourceLineNo">264</span>      // Remove a complete locate request in a synchronized block, so the table cache must have<a name="line.264"></a>
-<span class="sourceLineNo">265</span>      // quota to send a candidate request.<a name="line.265"></a>
-<span class="sourceLineNo">266</span>      toSend = tableCache.getCandidate();<a name="line.266"></a>
-<span class="sourceLineNo">267</span>      toSend.ifPresent(r -&gt; tableCache.send(r));<a name="line.267"></a>
-<span class="sourceLineNo">268</span>    }<a name="line.268"></a>
-<span class="sourceLineNo">269</span>    toSend.ifPresent(r -&gt; locateInMeta(tableName, r));<a name="line.269"></a>
-<span class="sourceLineNo">270</span>  }<a name="line.270"></a>
-<span class="sourceLineNo">271</span><a name="line.271"></a>
-<span class="sourceLineNo">272</span>  private void onScanComplete(TableName tableName, LocateRequest req, List&lt;Result&gt; results,<a name="line.272"></a>
+<span class="sourceLineNo">020</span>import static org.apache.hadoop.hbase.HConstants.NINES;<a name="line.20"></a>
+<span class="sourceLineNo">021</span>import static org.apache.hadoop.hbase.HConstants.ZEROES;<a name="line.21"></a>
+<span class="sourceLineNo">022</span>import static org.apache.hadoop.hbase.TableName.META_TABLE_NAME;<a name="line.22"></a>
+<span class="sourceLineNo">023</span>import static org.apache.hadoop.hbase.client.ConnectionUtils.createClosestRowAfter;<a name="line.23"></a>
+<span class="sourceLineNo">024</span>import static org.apache.hadoop.hbase.client.ConnectionUtils.isEmptyStopRow;<a name="line.24"></a>
+<span class="sourceLineNo">025</span>import static org.apache.hadoop.hbase.client.RegionInfo.createRegionName;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import static org.apache.hadoop.hbase.util.Bytes.BYTES_COMPARATOR;<a name="line.26"></a>
+<span class="sourceLineNo">027</span>import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent;<a name="line.27"></a>
+<span class="sourceLineNo">028</span><a name="line.28"></a>
+<span class="sourceLineNo">029</span>import java.io.IOException;<a name="line.29"></a>
+<span class="sourceLineNo">030</span>import java.util.Arrays;<a name="line.30"></a>
+<span class="sourceLineNo">031</span>import java.util.HashSet;<a name="line.31"></a>
+<span class="sourceLineNo">032</span>import java.util.Iterator;<a name="line.32"></a>
+<span class="sourceLineNo">033</span>import java.util.LinkedHashMap;<a name="line.33"></a>
+<span class="sourceLineNo">034</span>import java.util.Map;<a name="line.34"></a>
+<span class="sourceLineNo">035</span>import java.util.Optional;<a name="line.35"></a>
+<span class="sourceLineNo">036</span>import java.util.Set;<a name="line.36"></a>
+<span class="sourceLineNo">037</span>import java.util.concurrent.CompletableFuture;<a name="line.37"></a>
+<span class="sourceLineNo">038</span>import java.util.concurrent.ConcurrentHashMap;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import java.util.concurrent.ConcurrentMap;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import java.util.concurrent.ConcurrentNavigableMap;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>import java.util.concurrent.ConcurrentSkipListMap;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.DoNotRetryIOException;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.HConstants;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.HRegionLocation;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.MetaTableAccessor;<a name="line.45"></a>
+<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.RegionLocations;<a name="line.46"></a>
+<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.TableName;<a name="line.47"></a>
+<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.TableNotFoundException;<a name="line.48"></a>
+<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.client.Scan.ReadType;<a name="line.49"></a>
+<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.50"></a>
+<span class="sourceLineNo">051</span>import org.apache.yetus.audience.InterfaceAudience;<a name="line.51"></a>
+<span class="sourceLineNo">052</span>import org.slf4j.Logger;<a name="line.52"></a>
+<span class="sourceLineNo">053</span>import org.slf4j.LoggerFactory;<a name="line.53"></a>
+<span class="sourceLineNo">054</span><a name="line.54"></a>
+<span class="sourceLineNo">055</span>/**<a name="line.55"></a>
+<span class="sourceLineNo">056</span> * The asynchronous locator for regions other than meta.<a name="line.56"></a>
+<span class="sourceLineNo">057</span> */<a name="line.57"></a>
+<span class="sourceLineNo">058</span>@InterfaceAudience.Private<a name="line.58"></a>
+<span class="sourceLineNo">059</span>class AsyncNonMetaRegionLocator {<a name="line.59"></a>
+<span class="sourceLineNo">060</span><a name="line.60"></a>
+<span class="sourceLineNo">061</span>  private static final Logger LOG = LoggerFactory.getLogger(AsyncNonMetaRegionLocator.class);<a name="line.61"></a>
+<span class="sourceLineNo">062</span><a name="line.62"></a>
+<span class="sourceLineNo">063</span>  static final String MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE =<a name="line.63"></a>
+<span class="sourceLineNo">064</span>    "hbase.client.meta.max.concurrent.locate.per.table";<a name="line.64"></a>
+<span class="sourceLineNo">065</span><a name="line.65"></a>
+<span class="sourceLineNo">066</span>  private static final int DEFAULT_MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE = 8;<a name="line.66"></a>
+<span class="sourceLineNo">067</span><a name="line.67"></a>
+<span class="sourceLineNo">068</span>  private final AsyncConnectionImpl conn;<a name="line.68"></a>
+<span class="sourceLineNo">069</span><a name="line.69"></a>
+<span class="sourceLineNo">070</span>  private final int maxConcurrentLocateRequestPerTable;<a name="line.70"></a>
+<span class="sourceLineNo">071</span><a name="line.71"></a>
+<span class="sourceLineNo">072</span>  private final ConcurrentMap&lt;TableName, TableCache&gt; cache = new ConcurrentHashMap&lt;&gt;();<a name="line.72"></a>
+<span class="sourceLineNo">073</span><a name="line.73"></a>
+<span class="sourceLineNo">074</span>  private static final class LocateRequest {<a name="line.74"></a>
+<span class="sourceLineNo">075</span><a name="line.75"></a>
+<span class="sourceLineNo">076</span>    public final byte[] row;<a name="line.76"></a>
+<span class="sourceLineNo">077</span><a name="line.77"></a>
+<span class="sourceLineNo">078</span>    public final RegionLocateType locateType;<a name="line.78"></a>
+<span class="sourceLineNo">079</span><a name="line.79"></a>
+<span class="sourceLineNo">080</span>    public LocateRequest(byte[] row, RegionLocateType locateType) {<a name="line.80"></a>
+<span class="sourceLineNo">081</span>      this.row = row;<a name="line.81"></a>
+<span class="sourceLineNo">082</span>      this.locateType = locateType;<a name="line.82"></a>
+<span class="sourceLineNo">083</span>    }<a name="line.83"></a>
+<span class="sourceLineNo">084</span><a name="line.84"></a>
+<span class="sourceLineNo">085</span>    @Override<a name="line.85"></a>
+<span class="sourceLineNo">086</span>    public int hashCode() {<a name="line.86"></a>
+<span class="sourceLineNo">087</span>      return Bytes.hashCode(row) ^ locateType.hashCode();<a name="line.87"></a>
+<span class="sourceLineNo">088</span>    }<a name="line.88"></a>
+<span class="sourceLineNo">089</span><a name="line.89"></a>
+<span class="sourceLineNo">090</span>    @Override<a name="line.90"></a>
+<span class="sourceLineNo">091</span>    public boolean equals(Object obj) {<a name="line.91"></a>
+<span class="sourceLineNo">092</span>      if (obj == null || obj.getClass() != LocateRequest.class) {<a name="line.92"></a>
+<span class="sourceLineNo">093</span>        return false;<a name="line.93"></a>
+<span class="sourceLineNo">094</span>      }<a name="line.94"></a>
+<span class="sourceLineNo">095</span>      LocateRequest that = (LocateRequest) obj;<a name="line.95"></a>
+<span class="sourceLineNo">096</span>      return locateType.equals(that.locateType) &amp;&amp; Bytes.equals(row, that.row);<a name="line.96"></a>
+<span class="sourceLineNo">097</span>    }<a name="line.97"></a>
+<span class="sourceLineNo">098</span>  }<a name="line.98"></a>
+<span class="sourceLineNo">099</span><a name="line.99"></a>
+<span class="sourceLineNo">100</span>  private static final class TableCache {<a name="line.100"></a>
+<span class="sourceLineNo">101</span><a name="line.101"></a>
+<span class="sourceLineNo">102</span>    public final ConcurrentNavigableMap&lt;byte[], HRegionLocation&gt; cache =<a name="line.102"></a>
+<span class="sourceLineNo">103</span>      new ConcurrentSkipListMap&lt;&gt;(BYTES_COMPARATOR);<a name="line.103"></a>
+<span class="sourceLineNo">104</span><a name="line.104"></a>
+<span class="sourceLineNo">105</span>    public final Set&lt;LocateRequest&gt; pendingRequests = new HashSet&lt;&gt;();<a name="line.105"></a>
+<span class="sourceLineNo">106</span><a name="line.106"></a>
+<span class="sourceLineNo">107</span>    public final Map&lt;LocateRequest, CompletableFuture&lt;HRegionLocation&gt;&gt; allRequests =<a name="line.107"></a>
+<span class="sourceLineNo">108</span>      new LinkedHashMap&lt;&gt;();<a name="line.108"></a>
+<span class="sourceLineNo">109</span><a name="line.109"></a>
+<span class="sourceLineNo">110</span>    public boolean hasQuota(int max) {<a name="line.110"></a>
+<span class="sourceLineNo">111</span>      return pendingRequests.size() &lt; max;<a name="line.111"></a>
+<span class="sourceLineNo">112</span>    }<a name="line.112"></a>
+<span class="sourceLineNo">113</span><a name="line.113"></a>
+<span class="sourceLineNo">114</span>    public boolean isPending(LocateRequest req) {<a name="line.114"></a>
+<span class="sourceLineNo">115</span>      return pendingRequests.contains(req);<a name="line.115"></a>
+<span class="sourceLineNo">116</span>    }<a name="line.116"></a>
+<span class="sourceLineNo">117</span><a name="line.117"></a>
+<span class="sourceLineNo">118</span>    public void send(LocateRequest req) {<a name="line.118"></a>
+<span class="sourceLineNo">119</span>      pendingRequests.add(req);<a name="line.119"></a>
+<span class="sourceLineNo">120</span>    }<a name="line.120"></a>
+<span class="sourceLineNo">121</span><a name="line.121"></a>
+<span class="sourceLineNo">122</span>    public Optional&lt;LocateRequest&gt; getCandidate() {<a name="line.122"></a>
+<span class="sourceLineNo">123</span>      return allRequests.keySet().stream().filter(r -&gt; !isPending(r)).findFirst();<a name="line.123"></a>
+<span class="sourceLineNo">124</span>    }<a name="line.124"></a>
+<span class="sourceLineNo">125</span><a name="line.125"></a>
+<span class="sourceLineNo">126</span>    public void clearCompletedRequests(Optional&lt;HRegionLocation&gt; location) {<a name="line.126"></a>
+<span class="sourceLineNo">127</span>      for (Iterator&lt;Map.Entry&lt;LocateRequest, CompletableFuture&lt;HRegionLocation&gt;&gt;&gt; iter =<a name="line.127"></a>
+<span class="sourceLineNo">128</span>        allRequests.entrySet().iterator(); iter.hasNext();) {<a name="line.128"></a>
+<span class="sourceLineNo">129</span>        Map.Entry&lt;LocateRequest, CompletableFuture&lt;HRegionLocation&gt;&gt; entry = iter.next();<a name="line.129"></a>
+<span class="sourceLineNo">130</span>        if (tryComplete(entry.getKey(), entry.getValue(), location)) {<a name="line.130"></a>
+<span class="sourceLineNo">131</span>          iter.remove();<a name="line.131"></a>
+<span class="sourceLineNo">132</span>        }<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><a name="line.135"></a>
+<span class="sourceLineNo">136</span>    private boolean tryComplete(LocateRequest req, CompletableFuture&lt;HRegionLocation&gt; future,<a name="line.136"></a>
+<span class="sourceLineNo">137</span>        Optional&lt;HRegionLocation&gt; location) {<a name="line.137"></a>
+<span class="sourceLineNo">138</span>      if (future.isDone()) {<a name="line.138"></a>
+<span class="sourceLineNo">139</span>        return true;<a name="line.139"></a>
+<span class="sourceLineNo">140</span>      }<a name="line.140"></a>
+<span class="sourceLineNo">141</span>      if (!location.isPresent()) {<a name="line.141"></a>
+<span class="sourceLineNo">142</span>        return false;<a name="line.142"></a>
+<span class="sourceLineNo">143</span>      }<a name="line.143"></a>
+<span class="sourceLineNo">144</span>      HRegionLocation loc = location.get();<a name="line.144"></a>
+<span class="sourceLineNo">145</span>      boolean completed;<a name="line.145"></a>
+<span class="sourceLineNo">146</span>      if (req.locateType.equals(RegionLocateType.BEFORE)) {<a name="line.146"></a>
+<span class="sourceLineNo">147</span>        // for locating the row before current row, the common case is to find the previous region<a name="line.147"></a>
+<span class="sourceLineNo">148</span>        // in reverse scan, so we check the endKey first. In general, the condition should be<a name="line.148"></a>
+<span class="sourceLineNo">149</span>        // startKey &lt; req.row and endKey &gt;= req.row. Here we split it to endKey == req.row ||<a name="line.149"></a>
+<span class="sourceLineNo">150</span>        // (endKey &gt; req.row &amp;&amp; startKey &lt; req.row). The two conditions are equal since startKey &lt;<a name="line.150"></a>
+<span class="sourceLineNo">151</span>        // endKey.<a name="line.151"></a>
+<span class="sourceLineNo">152</span>        int c = Bytes.compareTo(loc.getRegion().getEndKey(), req.row);<a name="line.152"></a>
+<span class="sourceLineNo">153</span>        completed =<a name="line.153"></a>
+<span class="sourceLineNo">154</span>          c == 0 || (c &gt; 0 &amp;&amp; Bytes.compareTo(loc.getRegion().getStartKey(), req.row) &lt; 0);<a name="line.154"></a>
+<span class="sourceLineNo">155</span>      } else {<a name="line.155"></a>
+<span class="sourceLineNo">156</span>        completed = loc.getRegion().containsRow(req.row);<a name="line.156"></a>
+<span class="sourceLineNo">157</span>      }<a name="line.157"></a>
+<span class="sourceLineNo">158</span>      if (completed) {<a name="line.158"></a>
+<span class="sourceLineNo">159</span>        future.complete(loc);<a name="line.159"></a>
+<span class="sourceLineNo">160</span>        return true;<a name="line.160"></a>
+<span class="sourceLineNo">161</span>      } else {<a name="line.161"></a>
+<span class="sourceLineNo">162</span>        return false;<a name="line.162"></a>
+<span class="sourceLineNo">163</span>      }<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    }<a name="line.164"></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>  AsyncNonMetaRegionLocator(AsyncConnectionImpl conn) {<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    this.conn = conn;<a name="line.168"></a>
+<span class="sourceLineNo">169</span>    this.maxConcurrentLocateRequestPerTable = conn.getConfiguration().getInt(<a name="line.169"></a>
+<span class="sourceLineNo">170</span>      MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE, DEFAULT_MAX_CONCURRENT_LOCATE_REQUEST_PER_TABLE);<a name="line.170"></a>
+<span class="sourceLineNo">171</span>  }<a name="line.171"></a>
+<span class="sourceLineNo">172</span><a name="line.172"></a>
+<span class="sourceLineNo">173</span>  private TableCache getTableCache(TableName tableName) {<a name="line.173"></a>
+<span class="sourceLineNo">174</span>    return computeIfAbsent(cache, tableName, TableCache::new);<a name="line.174"></a>
+<span class="sourceLineNo">175</span>  }<a name="line.175"></a>
+<span class="sourceLineNo">176</span><a name="line.176"></a>
+<span class="sourceLineNo">177</span>  private void removeFromCache(HRegionLocation loc) {<a name="line.177"></a>
+<span class="sourceLineNo">178</span>    TableCache tableCache = cache.get(loc.getRegion().getTable());<a name="line.178"></a>
+<span class="sourceLineNo">179</span>    if (tableCache == null) {<a name="line.179"></a>
+<span class="sourceLineNo">180</span>      return;<a name="line.180"></a>
+<span class="sourceLineNo">181</span>    }<a name="line.181"></a>
+<span class="sourceLineNo">182</span>    tableCache.cache.computeIfPresent(loc.getRegion().getStartKey(), (k, oldLoc) -&gt; {<a name="line.182"></a>
+<span class="sourceLineNo">183</span>      if (oldLoc.getSeqNum() &gt; loc.getSeqNum() ||<a name="line.183"></a>
+<span class="sourceLineNo">184</span>        !oldLoc.getServerName().equals(loc.getServerName())) {<a name="line.184"></a>
+<span class="sourceLineNo">185</span>        return oldLoc;<a name="line.185"></a>
+<span class="sourceLineNo">186</span>      }<a name="line.186"></a>
+<span class="sourceLineNo">187</span>      return null;<a name="line.187"></a>
+<span class="sourceLineNo">188</span>    });<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>  // return whether we add this loc to cache<a name="line.191"></a>
+<span class="sourceLineNo">192</span>  private boolean addToCache(TableCache tableCache, HRegionLocation loc) {<a name="line.192"></a>
+<span class="sourceLineNo">193</span>    if (LOG.isTraceEnabled()) {<a name="line.193"></a>
+<span class="sourceLineNo">194</span>      LOG.trace("Try adding " + loc + " to cache");<a name="line.194"></a>
+<span class="sourceLineNo">195</span>    }<a name="line.195"></a>
+<span class="sourceLineNo">196</span>    byte[] startKey = loc.getRegion().getStartKey();<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    HRegionLocation oldLoc = tableCache.cache.putIfAbsent(startKey, loc);<a name="line.197"></a>
+<span class="sourceLineNo">198</span>    if (oldLoc == null) {<a name="line.198"></a>
+<span class="sourceLineNo">199</span>      return true;<a name="line.199"></a>
+<span class="sourceLineNo">200</span>    }<a name="line.200"></a>
+<span class="sourceLineNo">201</span>    if (oldLoc.getSeqNum() &gt; loc.getSeqNum() ||<a name="line.201"></a>
+<span class="sourceLineNo">202</span>      oldLoc.getServerName().equals(loc.getServerName())) {<a name="line.202"></a>
+<span class="sourceLineNo">203</span>      if (LOG.isTraceEnabled()) {<a name="line.203"></a>
+<span class="sourceLineNo">204</span>        LOG.trace("Will not add " + loc + " to cache because the old value " + oldLoc +<a name="line.204"></a>
+<span class="sourceLineNo">205</span>          " is newer than us or has the same server name");<a name="line.205"></a>
+<span class="sourceLineNo">206</span>      }<a name="line.206"></a>
+<span class="sourceLineNo">207</span>      return false;<a name="line.207"></a>
+<span class="sourceLineNo">208</span>    }<a name="line.208"></a>
+<span class="sourceLineNo">209</span>    return loc == tableCache.cache.compute(startKey, (k, oldValue) -&gt; {<a name="line.209"></a>
+<span class="sourceLineNo">210</span>      if (oldValue == null || oldValue.getSeqNum() &lt;= loc.getSeqNum()) {<a name="line.210"></a>
+<span class="sourceLineNo">211</span>        return loc;<a name="line.211"></a>
+<span class="sourceLineNo">212</span>      }<a name="line.212"></a>
+<span class="sourceLineNo">213</span>      if (LOG.isTraceEnabled()) {<a name="line.213"></a>
+<span class="sourceLineNo">214</span>        LOG.trace("Will not add " + loc + " to cache because the old value " + oldValue +<a name="line.214"></a>
+<span class="sourceLineNo">215</span>          " is newer than us or has the same server name." +<a name="line.215"></a>
+<span class="sourceLineNo">216</span>          " Maybe it is updated before we replace it");<a name="line.216"></a>
+<span class="sourceLineNo">217</span>      }<a name="line.217"></a>
+<span class="sourceLineNo">218</span>      return oldValue;<a name="line.218"></a>
+<span class="sourceLineNo">219</span>    });<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>  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",<a name="line.222"></a>
+<span class="sourceLineNo">223</span>      justification = "Called by lambda expression")<a name="line.223"></a>
+<span class="sourceLineNo">224</span>  private void addToCache(HRegionLocation loc) {<a name="line.224"></a>
+<span class="sourceLineNo">225</span>    addToCache(getTableCache(loc.getRegion().getTable()), loc);<a name="line.225"></a>
+<span class="sourceLineNo">226</span>    if (LOG.isTraceEnabled()) {<a name="line.226"></a>
+<span class="sourceLineNo">227</span>      LOG.trace("Try adding " + loc + " to cache");<a name="line.227"></a>
+<span class="sourceLineNo">228</span>    }<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>  private void complete(TableName tableName, LocateRequest req, HRegionLocation loc,<a name="line.231"></a>
+<span class="sourceLineNo">232</span>      Throwable error) {<a name="line.232"></a>
+<span class="sourceLineNo">233</span>    if (error != null) {<a name="line.233"></a>
+<span class="sourceLineNo">234</span>      LOG.warn("Failed to locate region in '" + tableName + "', row='" +<a name="line.234"></a>
+<span class="sourceLineNo">235</span>        Bytes.toStringBinary(req.row) + "', locateType=" + req.locateType, error);<a name="line.235"></a>
+<span class="sourceLineNo">236</span>    }<a name="line.236"></a>
+<span class="sourceLineNo">237</span>    Optional&lt;LocateRequest&gt; toSend = Optional.empty();<a name="line.237"></a>
+<span class="sourceLineNo">238</span>    TableCache tableCache = getTableCache(tableName);<a name="line.238"></a>
+<span class="sourceLineNo">239</span>    if (loc != null) {<a name="line.239"></a>
+<span class="sourceLineNo">240</span>      if (!addToCache(tableCache, loc)) {<a name="line.240"></a>
+<span class="sourceLineNo">241</span>        // someone is ahead of us.<a name="line.241"></a>
+<span class="sourceLineNo">242</span>        synchronized (tableCache) {<a name="line.242"></a>
+<span class="sourceLineNo">243</span>          tableCache.pendingRequests.remove(req);<a name="line.243"></a>
+<span class="sourceLineNo">244</span>          tableCache.clearCompletedRequests(Optional.empty());<a name="line.244"></a>
+<span class="sourceLineNo">245</span>          // Remove a complete locate request in a synchronized block, so the table cache must have<a name="line.245"></a>
+<span class="sourceLineNo">246</span>          // quota to send a candidate request.<a name="line.246"></a>
+<span class="sourceLineNo">247</span>          toSend = tableCache.getCandidate();<a name="line.247"></a>
+<span class="sourceLineNo">248</span>          toSend.ifPresent(r -&gt; tableCache.send(r));<a name="line.248"></a>
+<span class="sourceLineNo">249</span>        }<a name="line.249"></a>
+<span class="sourceLineNo">250</span>        toSend.ifPresent(r -&gt; locateInMeta(tableName, r));<a name="line.250"></a>
+<span class="sourceLineNo">251</span>        return;<a name="line.251"></a>
+<span class="sourceLineNo">252</span>      }<a name="line.252"></a>
+<span class="sourceLineNo">253</span>    }<a name="line.253"></a>
+<span class="sourceLineNo">254</span>    synchronized (tableCache) {<a name="line.254"></a>
+<span class="sourceLineNo">255</span>      tableCache.pendingRequests.remove(req);<a name="line.255"></a>
+<span class="sourceLineNo">256</span>      if (error instanceof DoNotRetryIOException) {<a name="line.256"></a>
+<span class="sourceLineNo">257</span>        CompletableFuture&lt;?&gt; future = tableCache.allRequests.remove(req);<a name="line.257"></a>
+<span class="sourceLineNo">258</span>        if (future != null) {<a name="line.258"></a>
+<span class="sourceLineNo">259</span>          future.completeExceptionally(error);<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>      tableCache.clearCompletedRequests(Optional.ofNullable(loc));<a name="line.262"></a>
+<span class="sourceLineNo">263</span>      // Remove a complete locate request in a synchronized block, so the table cache must have<a name="line.263"></a>
+<span class="sourceLineNo">264</span>      // quota to send a candidate request.<a name="line.264"></a>
+<span class="sourceLineNo">265</span>      toSend = tableCache.getCandidate();<a name="line.265"></a>
+<span class="sourceLineNo">266</span>      toSend.ifPresent(r -&gt; tableCache.send(r));<a name="line.266"></a>
+<span class="sourceLineNo">267</span>    }<a name="line.267"></a>
+<span class="sourceLineNo">268</span>    toSend.ifPresent(r -&gt; locateInMeta(tableName, r));<a name="line.268"></a>
+<span class="sourceLineNo">269</span>  }<a name="line.269"></a>
+<span class="sourceLineNo">270</span><a name="line.270"></a>
+<span class="sourceLineNo">271</span>  // return whether we should stop the scan<a name="line.271"></a>
+<span class="sourceLineNo">272</span>  private boolean onScanNext(TableName tableName, LocateRequest req, Result result,<a name="line.272"></a>
 <span class="sourceLineNo">273</span>      Throwable error) {<a name="line.273"></a>
 <span class="sourceLineNo">274</span>    if (error != null) {<a name="line.274"></a>
 <span class="sourceLineNo">275</span>      complete(tableName, req, null, error);<a name="line.275"></a>
-<span class="sourceLineNo">276</span>      return;<a name="line.276"></a>
+<span class="sourceLineNo">276</span>      return true;<a name="line.276"></a>
 <span class="sourceLineNo">277</span>    }<a name="line.277"></a>
-<span class="sourceLineNo">278</span>    if (results.isEmpty()) {<a name="line.278"></a>
-<span class="sourceLineNo">279</span>      complete(tableName, req, null, new TableNotFoundException(tableName));<a name="line.279"></a>
-<span class="sourceLineNo">280</span>      return;<a name="line.280"></a>
-<span class="sourceLineNo">281</span>    }<a name="line.281"></a>
-<span class="sourceLineNo">282</span>    RegionLocations locs = MetaTableAccessor.getRegionLocations(results.get(0));<a name="line.282"></a>
-<span class="sourceLineNo">283</span>    if (LOG.isDebugEnabled()) {<a name="line.283"></a>
-<span class="sourceLineNo">284</span>      LOG.debug("The fetched location of '" + tableName + "', row='" +<a name="line.284"></a>
-<span class="sourceLineNo">285</span>        Bytes.toStringBinary(req.row) + "', locateType=" + req.locateType + " is " + locs);<a name="line.285"></a>
-<span class="sourceLineNo">286</span>    }<a name="line.286"></a>
-<span class="sourceLineNo">287</span>    if (locs == null || locs.getDefaultRegionLocation() == null) {<a name="line.287"></a>
-<span class="sourceLineNo">288</span>      complete(tableName, req, null,<a name="line.288"></a>
-<span class="sourceLineNo">289</span>        new IOException(String.format("No location found for '%s', row='%s', locateType=%s",<a name="line.289"></a>
-<span class="sourceLineNo">290</span>          tableName, Bytes.toStringBinary(req.row), req.locateType)));<a name="line.290"></a>
-<span class="sourceLineNo">291</span>      return;<a name="line.291"></a>
-<span class="sourceLineNo">292</span>    }<a name="line.292"></a>
-<span class="sourceLineNo">293</span>    HRegionLocation loc = locs.getDefaultRegionLocation();<a name="line.293"></a>
-<span class="sourceLineNo">294</span>    RegionInfo info = loc.getRegion();<a name="line.294"></a>
-<span class="sourceLineNo">295</span>    if (info == null) {<a name="line.295"></a>
-<span class="sourceLineNo">296</span>      complete(tableName, req, null,<a name="line.296"></a>
-<span class="sourceLineNo">297</span>        new IOException(String.format("HRegionInfo is null for '%s', row='%s', locateType=%s",<a name="line.297"></a>
-<span class="sourceLineNo">298</span>          tableName, Bytes.toStringBinary(req.row), req.locateType)));<a name="line.298"></a>
-<span class="sourceLineNo">299</span>      return;<a name="line.299"></a>
-<span class="sourceLineNo">300</span>    }<a name="line.300"></a>
-<span class="sourceLineNo">301</span>    if (!info.getTable().equals(tableName)) {<a name="line.301"></a>
-<span class="sourceLineNo">302</span>      complete(tableName, req, null, new TableNotFoundException(<a name="line.302"></a>
-<span class="sourceLineNo">303</span>          "Table '" + tableName + "' was not found, got: '" + info.getTable() + "'"));<a name="line.303"></a>
-<span class="sourceLineNo">304</span>      return;<a name="line.304"></a>
+<span class="sourceLineNo">278</span>    RegionLocations locs = MetaTableAccessor.getRegionLocations(result);<a name="line.278"></a>
+<span class="sourceLineNo">279</span>    LOG.debug("The fetched location of '{}', row='{}', locateType={} is {}", tableName,<a name="line.279"></a>
+<span class="sourceLineNo">280</span>      Bytes.toStringBinary(req.row), req.locateType, locs);<a name="line.280"></a>
+<span class="sourceLineNo">281</span><a name="line.281"></a>
+<span class="sourceLineNo">282</span>    if (locs == null || locs.getDefaultRegionLocation() == null) {<a name="line.282"></a>
+<span class="sourceLineNo">283</span>      complete(tableName, req, null,<a name="line.283"></a>
+<span class="sourceLineNo">284</span>        new IOException(String.format("No location found for '%s', row='%s', locateType=%s",<a name="line.284"></a>
+<span class="sourceLineNo">285</span>          tableName, Bytes.toStringBinary(req.row), req.locateType)));<a name="line.285"></a>
+<span class="sourceLineNo">286</span>      return true;<a name="line.286"></a>
+<span class="sourceLineNo">287</span>    }<a name="line.287"></a>
+<span class="sourceLineNo">288</span>    HRegionLocation loc = locs.getDefaultRegionLocation();<a name="line.288"></a>
+<span class="sourceLineNo">289</span>    RegionInfo info = loc.getRegion();<a name="line.289"></a>
+<span class="sourceLineNo">290</span>    if (info == null) {<a name="line.290"></a>
+<span class="sourceLineNo">291</span>      complete(tableName, req, null,<a name="line.291"></a>
+<span class="sourceLineNo">292</span>        new IOException(String.format("HRegionInfo is null for '%s', row='%s', locateType=%s",<a name="line.292"></a>
+<span class="sourceLineNo">293</span>          tableName, Bytes.toStringBinary(req.row), req.locateType)));<a name="line.293"></a>
+<span class="sourceLineNo">294</span>      return true;<a name="line.294"></a>
+<span class="sourceLineNo">295</span>    }<a name="line.295"></a>
+<span class="sourceLineNo">296</span>    if (info.isSplitParent()) {<a name="line.296"></a>
+<span class="sourceLineNo">297</span>      return false;<a name="line.297"></a>
+<span class="sourceLineNo">298</span>    }<a name="line.298"></a>
+<span class="sourceLineNo">299</span>    if (loc.getServerName() == null) {<a name="line.299"></a>
+<span class="sourceLineNo">300</span>      complete(tableName, req, null,<a name="line.300"></a>
+<span class="sourceLineNo">301</span>        new NoServerForRegionException(<a name="line.301"></a>
+<span class="sourceLineNo">302</span>            String.format("No server address listed for region '%s', row='%s', locateType=%s",<a name="line.302"></a>
+<span class="sourceLineNo">303</span>              info.getRegionNameAsString(), Bytes.toStringBinary(req.row), req.locateType)));<a name="line.303"></a>
+<span class="sourceLineNo">304</span>      return true;<a name="line.304"></a>
 <span class="sourceLineNo">305</span>    }<a name="line.305"></a>
-<span class="sourceLineNo">306</span>    if (info.isSplit()) {<a name="line.306"></a>
-<span class="sourceLineNo">307</span>      complete(tableName, req, null,<a name="line.307"></a>
-<span class="sourceLineNo">308</span>        new RegionOfflineException(<a name="line.308"></a>
-<span class="sourceLineNo">309</span>            "the only available region for the required row is a split parent," +<a name="line.309"></a>
-<span class="sourceLineNo">310</span>              " the daughters should be online soon: '" + info.getRegionNameAsString() + "'"));<a name="line.310"></a>
-<span class="sourceLineNo">311</span>      return;<a name="line.311"></a>
-<span class="sourceLineNo">312</span>    }<a name="line.312"></a>
-<span class="sourceLineNo">313</span>    if (info.isOffline()) {<a name="line.313"></a>
-<span class="sourceLineNo">314</span>      complete(tableName, req, null, new RegionOfflineException("the region is offline, could" +<a name="line.314"></a>
-<span class="sourceLineNo">315</span>        " be caused by a disable table call: '" + info.getRegionNameAsString() + "'"));<a name="line.315"></a>
-<span class="sourceLineNo">316</span>      return;<a name="line.316"></a>
-<span class="sourceLineNo">317</span>    }<a name="line.317"></a>
-<span class="sourceLineNo">318</span>    if (loc.getServerName() == null) {<a name="line.318"></a>
-<span class="sourceLineNo">319</span>      complete(tableName, req, null,<a name="line.319"></a>
-<span class="sourceLineNo">320</span>        new NoServerForRegionException(<a name="line.320"></a>
-<span class="sourceLineNo">321</span>            String.format("No server address listed for region '%s', row='%s', locateType=%s",<a name="line.321"></a>
-<span class="sourceLineNo">322</span>              info.getRegionNameAsString(), Bytes.toStringBinary(req.row), req.locateType)));<a name="line.322"></a>
-<span class="sourceLineNo">323</span>      return;<a name="line.323"></a>
-<span class="sourceLineNo">324</span>    }<a name="line.324"></a>
-<span class="sourceLineNo">325</span>    complete(tableName, req, loc, null);<a name="line.325"></a>
+<span class="sourceLineNo">306</span>    complete(tableName, req, loc, null);<a name="line.306"></a>
+<span class="sourceLineNo">307</span>    return true;<a name="line.307"></a>
+<span class="sourceLineNo">308</span>  }<a name="line.308"></a>
+<span class="sourceLineNo">309</span><a name="line.309"></a>
+<span class="sourceLineNo">310</span>  private HRegionLocation locateRowInCache(TableCache tableCache, TableName tableName, byte[] row) {<a name="line.310"></a>
+<span class="sourceLineNo">311</span>    Map.Entry&lt;byte[], HRegionLocation&gt; entry = tableCache.cache.floorEntry(row);<a name="line.311"></a>
+<span class="sourceLineNo">312</span>    if (entry == null) {<a name="line.312"></a>
+<span class="sourceLineNo">313</span>      return null;<a name="line.313"></a>
+<span class="sourceLineNo">314</span>    }<a name="line.314"></a>
+<span class="sourceLineNo">315</span>    HRegionLocation loc = entry.getValue();<a name="line.315"></a>
+<span class="sourceLineNo">316</span>    byte[] endKey = loc.getRegion().getEndKey();<a name="line.316"></a>
+<span class="sourceLineNo">317</span>    if (isEmptyStopRow(endKey) || Bytes.compareTo(row, endKey) &lt; 0) {<a name="line.317"></a>
+<span class="sourceLineNo">318</span>      if (LOG.isTraceEnabled()) {<a name="line.318"></a>
+<span class="sourceLineNo">319</span>        LOG.trace("Found " + loc + " in cache for '" + tableName + "', row='" +<a name="line.319"></a>
+<span class="sourceLineNo">320</span>          Bytes.toStringBinary(row) + "', locateType=" + RegionLocateType.CURRENT);<a name="line.320"></a>
+<span class="sourceLineNo">321</span>      }<a name="line.321"></a>
+<span class="sourceLineNo">322</span>      return loc;<a name="line.322"></a>
+<span class="sourceLineNo">323</span>    } else {<a name="line.323"></a>
+<span class="sourceLineNo">324</span>      return null;<a name="line.324"></a>
+<span class="sourceLineNo">325</span>    }<a name="line.325"></a>
 <span class="sourceLineNo">326</span>  }<a name="line.326"></a>
 <span class="sourceLineNo">327</span><a name="line.327"></a>
-<span class="sourceLineNo">328</span>  private HRegionLocation locateRowInCache(TableCache tableCache, TableName tableName, byte[] row) {<a name="line.328"></a>
-<span class="sourceLineNo">329</span>    Map.Entry&lt;byte[], HRegionLocation&gt; entry = tableCache.cache.floorEntry(row);<a name="line.329"></a>
-<span class="sourceLineNo">330</span>    if (entry == null) {<a name="line.330"></a>
-<span class="sourceLineNo">331</span>      return null;<a name="line.331"></a>
-<span class="sourceLineNo">332</span>    }<a name="line.332"></a>
-<span class="sourceLineNo">333</span>    HRegionLocation loc = entry.getValue();<a name="line.333"></a>
-<span class="sourceLineNo">334</span>    byte[] endKey = loc.getRegion().getEndKey();<a name="line.334"></a>
-<span class="sourceLineNo">335</span>    if (isEmptyStopRow(endKey) || Bytes.compareTo(row, endKey) &lt; 0) {<a name="line.335"></a>
-<span class="sourceLineNo">336</span>      if (LOG.isTraceEnabled()) {<a name="line.336"></a>
-<span class="sourceLineNo">337</span>        LOG.trace("Found " + loc + " in cache for '" + tableName + "', row='" +<a name="line.337"></a>
-<span class="sourceLineNo">338</span>          Bytes.toStringBinary(row) + "', locateType=" + RegionLocateType.CURRENT);<a name="line.338"></a>
-<span class="sourceLineNo">339</span>      }<a name="line.339"></a>
-<span class="sourceLineNo">340</span>      return loc;<a name="line.340"></a>
-<span class="sourceLineNo">341</span>    } else {<a name="line.341"></a>
-<span class="sourceLineNo">342</span>      return null;<a name="line.342"></a>
-<span class="sourceLineNo">343</span>    }<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>  private HRegionLocation locateRowBeforeInCache(TableCache tableCache, TableName tableName,<a name="line.346"></a>
-<span class="sourceLineNo">347</span>      byte[] row) {<a name="line.347"></a>
-<span class="sourceLineNo">348</span>    Map.Entry&lt;byte[], HRegionLocation&gt; entry =<a name="line.348"></a>
-<span class="sourceLineNo">349</span>      isEmptyStopRow(row) ? tableCache.cache.lastEntry() : tableCache.cache.lowerEntry(row);<a name="line.349"></a>
-<span class="sourceLineNo">350</span>    if (entry == null) {<a name="line.350"></a>
-<span class="sourceLineNo">351</span>      return null;<a name="line.351"></a>
+<span class="sourceLineNo">328</span>  private HRegionLocation locateRowBeforeInCache(TableCache tableCache, TableName tableName,<a name="line.328"></a>
+<span class="sourceLineNo">329</span>      byte[] row) {<a name="line.329"></a>
+<span class="sourceLineNo">330</span>    Map.Entry&lt;byte[], HRegionLocation&gt; entry =<a name="line.330"></a>
+<span class="sourceLineNo">331</span>      isEmptyStopRow(row) ? tableCache.cache.lastEntry() : tableCache.cache.lowerEntry(row);<a name="line.331"></a>
+<span class="sourceLineNo">332</span>    if (entry == null) {<a name="line.332"></a>
+<span class="sourceLineNo">333</span>      return null;<a name="line.333"></a>
+<span class="sourceLineNo">334</span>    }<a name="line.334"></a>
+<span class="sourceLineNo">335</span>    HRegionLocation loc = entry.getValue();<a name="line.335"></a>
+<span class="sourceLineNo">336</span>    if (isEmptyStopRow(loc.getRegion().getEndKey()) ||<a name="line.336"></a>
+<span class="sourceLineNo">337</span>      Bytes.compareTo(loc.getRegion().getEndKey(), row) &gt;= 0) {<a name="line.337"></a>
+<span class="sourceLineNo">338</span>      if (LOG.isTraceEnabled()) {<a name="line.338"></a>
+<span class="sourceLineNo">339</span>        LOG.trace("Found " + loc + " in cache for '" + tableName + "', row='" +<a name="line.339"></a>
+<span class="sourceLineNo">340</span>          Bytes.toStringBinary(row) + "', locateType=" + RegionLocateType.BEFORE);<a name="line.340"></a>
+<span class="sourceLineNo">341</span>      }<a name="line.341"></a>
+<span class="sourceLineNo">342</span>      return loc;<a name="line.342"></a>
+<span class="sourceLineNo">343</span>    } else {<a name="line.343"></a>
+<span class="sourceLineNo">344</span>      return null;<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><a name="line.347"></a>
+<span class="sourceLineNo">348</span>  private void locateInMeta(TableName tableName, LocateRequest req) {<a name="line.348"></a>
+<span class="sourceLineNo">349</span>    if (LOG.isTraceEnabled()) {<a name="line.349"></a>
+<span class="sourceLineNo">350</span>      LOG.trace("Try locate '" + tableName + "', row='" + Bytes.toStringBinary(req.row) +<a name="line.350"></a>
+<span class="sourceLineNo">351</span>        "', locateType=" + req.locateType + " in meta");<a name="line.351"></a>
 <span class="sourceLineNo">352</span>    }<a name="line.352"></a>
-<span class="sourceLineNo">353</span>    HRegionLocation loc = entry.getValue();<a name="line.353"></a>
-<span class="sourceLineNo">354</span>    if (isEmptyStopRow(loc.getRegion().getEndKey()) ||<a name="line.354"></a>
-<span class="sourceLineNo">355</span>      Bytes.compareTo(loc.getRegion().getEndKey(), row) &gt;= 0) {<a name="line.355"></a>
-<span class="sourceLineNo">356</span>      if (LOG.isTraceEnabled()) {<a name="line.356"></a>
-<span class="sourceLineNo">357</span>        LOG.trace("Found " + loc + " in cache for '" + tableName + "', row='" +<a name="line.357"></a>
-<span class="sourceLineNo">358</span>          Bytes.toStringBinary(row) + "', locateType=" + RegionLocateType.BEFORE);<a name="line.358"></a>
-<span class="sourceLineNo">359</span>      }<a name="line.359"></a>
-<span class="sourceLineNo">360</span>      return loc;<a name="line.360"></a>
+<span class="sourceLineNo">353</span>    byte[] metaStartKey;<a name="line.353"></a>
+<span class="sourceLineNo">354</span>    if (req.locateType.equals(RegionLocateType.BEFORE)) {<a name="line.354"></a>
+<span class="sourceLineNo">355</span>      if (isEmptyStopRow(req.row)) {<a name="line.355"></a>
+<span class="sourceLineNo">356</span>        byte[] binaryTableName = tableName.getName();<a name="line.356"></a>
+<span class="sourceLineNo">357</span>        metaStartKey = Arrays.copyOf(binaryTableName, binaryTableName.length + 1);<a name="line.357"></a>
+<span class="sourceLineNo">358</span>      } else {<a name="line.358"></a>
+<span class="sourceLineNo">359</span>        metaStartKey = createRegionName(tableName, req.row, ZEROES, false);<a name="line.359"></a>
+<span class="sourceLineNo">360</span>      }<a name="line.360"></a>
 <span class="sourceLineNo">361</span>    } else {<a name="line.361"></a>
-<span class="sourceLineNo">362</span>      return null;<a name="line.362"></a>
+<span class="sourceLineNo">362</span>      metaStartKey = createRegionName(tableName, req.row, NINES, false);<a name="line.362"></a>
 <span class="sourceLineNo">363</span>    }<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>  private void locateInMeta(TableName tableName, LocateRequest req) {<a name="line.366"></a>
-<span class="sourceLineNo">367</span>    if (LOG.isTraceEnabled()) {<a name="line.367"></a>
-<span class="sourceLineNo">368</span>      LOG.trace("Try locate '" + tableName + "', row='" + Bytes.toStringBinary(req.row) +<a name="line.368"></a>
-<span class="sourceLineNo">369</span>        "', locateType=" + req.locateType + " in meta");<a name="line.369"></a>
-<span class="sourceLineNo">370</span>    }<a name="line.370"></a>
-<span class="sourceLineNo">371</span>    byte[] metaKey;<a name="line.371"></a>
-<span class="sourceLineNo">372</span>    if (req.locateType.equals(RegionLocateType.BEFORE)) {<a name="line.372"></a>
-<span class="sourceLineNo">373</span>      if (isEmptyStopRow(req.row)) {<a name="line.373"></a>
-<span class="sourceLineNo">374</span>        byte[] binaryTableName = tableName.getName();<a name="line.374"></a>
-<span class="sourceLineNo">375</span>        metaKey = Arrays.copyOf(binaryTableName, binaryTableName.length + 1);<a name="line.375"></a>
-<span class="sourceLineNo">376</span>      } else {<a name="line.376"></a>
-<span class="sourceLineNo">377</span>        metaKey = createRegionName(tableName, req.row, ZEROES, false);<a name="line.377"></a>
-<span class="sourceLineNo">378</span>      }<a name="line.378"></a>
-<span class="sourceLineNo">379</span>    } else {<a name="line.379"></a>
-<span class="sourceLineNo">380</span>      metaKey = createRegionName(tableName, req.row, NINES, false);<a name="line.380"></a>
-<span class="sourceLineNo">381</span>    }<a name="line.381"></a>
-<span class="sourceLineNo">382</span>    conn.getTable(META_TABLE_NAME)<a name="line.382"></a>
-<span class="sourceLineNo">383</span>        .scanAll(new Scan().withStartRow(metaKey).setReversed(true).addFamily(CATALOG_FAMILY)<a name="line.383"></a>
-<span class="sourceLineNo">384</span>            .setOneRowLimit())<a name="line.384"></a>
-<span class="sourceLineNo">385</span>        .whenComplete((results, error) -&gt; onScanComplete(tableName, req, results, error));<a name="line.385"></a>
-<span class="sourceLineNo">386</span>  }<a name="line.386"></a>
-<span class="sourceLineNo">387</span><a name="line.387"></a>
-<span class="sourceLineNo">388</span>  private HRegionLocation locateInCache(TableCache tableCache, TableName tableName, byte[] row,<a name="line.388"></a>
-<span class="sourceLineNo">389</span>      RegionLocateType locateType) {<a name="line.389"></a>
-<span class="sourceLineNo">390</span>    return locateType.equals(RegionLocateType.BEFORE)<a name="line.390"></a>
-<span class="sourceLineNo">391</span>      ? locateRowBeforeInCache(tableCache, tableName, row)<a name="line.391"></a>
-<span class="sourceLineNo">392</span>      : locateRowInCache(tableCache, tableName, row);<a name="line.392"></a>
-<span class="sourceLineNo">393</span>  }<a name="line.393"></a>
-<span class="sourceLineNo">394</span><a name="line.394"></a>
-<span class="sourceLineNo">395</span>  // locateToPrevious is true means we will use the start key of a region to locate the region<a name="line.395"></a>
-<span class="sourceLineNo">396</span>  // placed before it. Used for reverse scan. See the comment of<a name="line.396"></a>
-<span class="sourceLineNo">397</span>  // AsyncRegionLocator.getPreviousRegionLocation.<a name="line.397"></a>
-<span class="sourceLineNo">398</span>  private CompletableFuture&lt;HRegionLocation&gt; getRegionLocationInternal(TableName tableName,<a name="line.398"></a>
-<span class="sourceLineNo">399</span>      byte[] row, RegionLocateType locateType, boolean reload) {<a name="line.399"></a>
-<span class="sourceLineNo">400</span>    // AFTER should be convert to CURRENT before calling this method<a name="line.400"></a>
-<span class="sourceLineNo">401</span>    assert !locateType.equals(RegionLocateType.AFTER);<a name="line.401"></a>
-<span class="sourceLineNo">402</span>    TableCache tableCache = getTableCache(tableName);<a name="line.402"></a>
-<span class="sourceLineNo">403</span>    if (!reload) {<a name="line.403"></a>
-<span class="sourceLineNo">404</span>      HRegionLocation loc = locateInCache(tableCache, tableName, row, locateType);<a name="line.404"></a>
-<span class="sourceLineNo">405</span>      if (loc != null) {<a name="line.405"></a>
-<span class="sourceLineNo">406</span>        return CompletableFuture.completedFuture(loc);<a name="line.406"></a>
-<span class="sourceLineNo">407</span>      }<a name="line.407"></a>
-<span class="sourceLineNo">408</span>    }<a name="line.408"></a>
-<span class="sourceLineNo">409</span>    CompletableFuture&lt;HRegionLocation&gt; future;<a name="line.409"></a>
-<span class="sourceLineNo">410</span>    LocateRequest req;<a name="line.410"></a>
-<span class="sourceLineNo">411</span>    boolean sendRequest = false;<a name="line.411"></a>
-<span class="sourceLineNo">412</span>    synchronized (tableCache) {<a name="line.412"></a>
-<span class="sourceLineNo">413</span>      // check again<a name="line.413"></a>
-<span class="sourceLineNo">414</span>      if (!reload) {<a name="line.414"></a>
-<span class="sourceLineNo">415</span>        HRegionLocation loc = locateInCache(tableCache, tableName, row, locateType);<a name="line.415"></a>
-<span class="sourceLineNo">416</span>        if (loc != null) {<a name="line.416"></a>
-<span class="sourceLineNo">417</span>          return CompletableFuture.completedFuture(loc);<a name="line.417"></a>
-<span class="sourceLineNo">418</span>        }<a name="line.418"></a>
-<span class="sourceLineNo">419</span>      }<a name="line.419"></a>
-<span class="sourceLineNo">420</span>      req = new LocateRequest(row, locateType);<a name="line.420"></a>
-<span class="sourceLineNo">421</span>      future = tableCache.allRequests.get(req);<a name="line.421"></a>
-<span class="sourceLineNo">422</span>      if (future == null) {<a name="line.422"></a>
-<span class="sourceLineNo">423</span>        future = new CompletableFuture&lt;&gt;();<a name="line.423"></a>
-<span class="sourceLineNo">424</span>        tableCache.allRequests.put(req, future);<a name="line.424"></a>
-<span class="sourceLineNo">425</span>        if (tableCache.hasQuota(maxConcurrentLocateRequestPerTable) &amp;&amp; !tableCache.isPending(req)) {<a name="line.425"></a>
-<span class="sourceLineNo">426</span>          tableCache.send(req);<a name="line.426"></a>
-<span class="sourceLineNo">427</span>          sendRequest = true;<a name="line.427"></a>
+<span class="sourceLineNo">364</span>    byte[] metaStopKey =<a name="line.364"></a>
+<span class="sourceLineNo">365</span>      RegionInfo.createRegionName(tableName, HConstants.EMPTY_START_ROW, "", false);<a name="line.365"></a>
+<span class="sourceLineNo">366</span>    conn.getTable(META_TABLE_NAME)<a name="line.366"></a>
+<span class="sourceLineNo">367</span>      .scan(new Scan().withStartRow(metaStartKey).withStopRow(metaStopKey, true)<a name="line.367"></a>
+<span class="sourceLineNo">368</span>        .addFamily(HConstants.CATALOG_FAMILY).setReversed(true).setCaching(5)<a name="line.368"></a>
+<span class="sourceLineNo">369</span>        .setReadType(ReadType.PREAD), new AdvancedScanResultConsumer() {<a name="line.369"></a>
+<span class="sourceLineNo">370</span><a name="line.370"></a>
+<span class="sourceLineNo">371</span>          private boolean completeNormally = false;<a name="line.371"></a>
+<span class="sourceLineNo">372</span><a name="line.372"></a>
+<span class="sourceLineNo">373</span>          @Override<a name="line.373"></a>
+<span class="sourceLineNo">374</span>          public void onError(Throwable error) {<a name="line.374"></a>
+<span class="sourceLineNo">375</span>            onScanNext(tableName, req, null, error);<a name="line.375"></a>
+<span class="sourceLineNo">376</span>          }<a name="line.376"></a>
+<span class="sourceLineNo">377</span><a name="line.377"></a>
+<span class="sourceLineNo">378</span>          @Override<a name="line.378"></a>
+<span class="sourceLineNo">379</span>          public void onComplete() {<a name="line.379"></a>
+<span class="sourceLineNo">380</span>            if (!completeNormally) {<a name="line.380"></a>
+<span class="sourceLineNo">381</span>              onScanNext(tableName, req, null, new TableNotFoundException(tableName));<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><a name="line.384"></a>
+<span class="sourceLineNo">385</span>          @Override<a name="line.385"></a>
+<span class="sourceLineNo">386</span>          public void onNext(Result[] results, ScanController controller) {<a name="line.386"></a>
+<span class="sourceLineNo">387</span>            for (Result result : results) {<a name="line.387"></a>
+<span class="sourceLineNo">388</span>              if (onScanNext(tableName, req, result, null)) {<a name="line.388"></a>
+<span class="sourceLineNo">389</span>                completeNormally = true;<a name="line.389"></a>
+<span class="sourceLineNo">390</span>                controller.terminate();<a name="line.390"></a>
+<span class="sourceLineNo">391</span>                return;<a name="line.391"></a>
+<span class="sourceLineNo">392</span>              }<a name="line.392"></a>
+<span class="sourceLineNo">393</span>            }<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>  }<a name="line.396"></a>
+<span class="sourceLineNo">397</span><a name="line.397"></a>
+<span class="sourceLineNo">398</span>  private HRegionLocation locateInCache(TableCache tableCache, TableName tableName, byte[] row,<a name="line.398"></a>
+<span class="sourceLineNo">399</span>      RegionLocateType locateType) {<a name="line.399"></a>
+<span class="sourceLineNo">400</span>    return locateType.equals(RegionLocateType.BEFORE)<a name="line.400"></a>
+<span class="sourceLineNo">401</span>      ? locateRowBeforeInCache(tableCache, tableName, row)<a name="line.401"></a>
+<span class="sourceLineNo">402</span>      : locateRowInCache(tableCache, tableName, row);<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>  // locateToPrevious is true means we will use the start key of a region to locate the region<a name="line.405"></a>
+<span class="sourceLineNo">406</span>  // placed before it. Used for reverse scan. See the comment of<a name="line.406"></a>
+<span class="sourceLineNo">407</span>  // AsyncRegionLocator.getPreviousRegionLocation.<a name="line.407"></a>
+<span class="sourceLineNo">408</span>  private CompletableFuture&lt;HRegionLocation&gt; getRegionLocationInternal(TableName tableName,<a name="line.408"></a>
+<span class="sourceLineNo">409</span>      byte[] row, RegionLocateType locateType, boolean reload) {<a name="line.409"></a>
+<span class="sourceLineNo">410</span>    // AFTER should be convert to CURRENT before calling this method<a name="line.410"></a>
+<span class="sourceLineNo">411</span>    assert !locateType.equals(RegionLocateType.AFTER);<a name="line.411"></a>
+<span class="sourceLineNo">412</span>    TableCache tableCache = getTableCache(tableName);<a name="line.412"></a>
+<span class="sourceLineNo">413</span>    if (!reload) {<a name="line.413"></a>
+<span class="sourceLineNo">414</span>      HRegionLocation loc = locateInCache(tableCache, tableName, row, locateType);<a name="line.414"></a>
+<span class="sourceLineNo">415</span>      if (loc != null) {<a name="line.415"></a>
+<span class="sourceLineNo">416</span>        return CompletableFuture.completedFuture(loc);<a name="line.416"></a>
+<span class="sourceLineNo">417</span>      }<a name="line.417"></a>
+<span class="sourceLineNo">418</span>    }<a name="line.418"></a>
+<span class="sourceLineNo">419</span>    CompletableFuture&lt;HRegionLocation&gt; future;<a name="line.419"></a>
+<span class="sourceLineNo">420</span>    LocateRequest req;<a name="line.420"></a>
+<span class="sourceLineNo">421</span>    boolean sendRequest = false;<a name="line.421"></a>
+<span class="sourceLineNo">422</span>    synchronized (tableCache) {<a name="line.422"></a>
+<span class="sourceLineNo">423</span>      // check again<a name="line.423"></a>
+<span class="sourceLineNo">424</span>      if (!reload) {<a name="line.424"></a>
+<span class="sourceLineNo">425</span>        HRegionLocation loc = locateInCache(tableCache, tableName, row, locateType);<a name="line.425"></a>
+<span class="sourceLineNo">426</span>        if (loc != null) {<a name="line.426"></a>
+<span class="sourceLineNo">427</span>          return CompletableFuture.completedFuture(loc);<a name="line.427"></a>
 <span class="sourceLineNo">428</span>        }<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>    if (sendRequest) {<a name="line.431"></a>
-<span class="sourceLineNo">432</span>      locateInMeta(tableName, req);<a name="line.432"></a>
-<span class="sourceLineNo">433</span>    }<a name="line.433"></a>
-<span class="sourceLineNo">434</span>    return future;<a name="line.434"></a>
-<span class="sourceLineNo">435</span>  }<a name="line.435"></a>
-<span class="sourceLineNo">436</span><a name="line.436"></a>
-<span class="sourceLineNo">437</span>  CompletableFuture&lt;HRegionLocation&gt; getRegionLocation(TableName tableName, byte[] row,<a name="line.437"></a>
-<span class="sourceLineNo">438</span>      RegionLocateType locateType, boolean reload) {<a name="line.438"></a>
-<span class="sourceLineNo">439</span>    if (locateType.equals(RegionLocateType.BEFORE)) {<a name="line.439"></a>
-<span class="sourceLineNo">440</span>      return getRegionLocationInternal(tableName, row, locateType, reload);<a name="line.440"></a>
-<span class="sourceLineNo">441</span>    } else {<a name="line.441"></a>
-<span class="sourceLineNo">442</span>      // as we know the exact row after us, so we can just create the new row, and use the same<a name="line.442"></a>
-<span class="sourceLineNo">443</span>      // algorithm to locate it.<a name="line.443"></a>
-<span class="sourceLineNo">444</span>      if (locateType.equals(RegionLocateType.AFTER)) {<a name="line.444"></a>
-<span class="sourceLineNo">445</span>        row = createClosestRowAfter(row);<a name="line.445"></a>
-<span class="sourceLineNo">446</span>      }<a name="line.446"></a>
-<span class="sourceLineNo">447</span>      return getRegionLocationInternal(tableName, row, RegionLocateType.CURRENT, reload);<a name="line.447"></a>
-<span class="sourceLineNo">448</span>    }<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>  void updateCachedLocation(HRegionLocation loc, Throwable exception) {<a name="line.451"></a>
-<span class="sourceLineNo">452</span>    AsyncRegionLocator.updateCachedLocation(loc, exception, l -&gt; {<a name="line.452"></a>
-<span class="sourceLineNo">453</span>      TableCache tableCache = cache.get(l.getRegion().getTable());<a name="line.453"></a>
-<span class="sourceLineNo">454</span>      if (tableCache == null) {<a name="line.454"></a>
-<span class="sourceLineNo">455</span>        return null;<a name="line.455"></a>
+<span class="sourceLineNo">430</span>      req = new LocateRequest(row, locateType);<a name="line.430"></a>
+<span class="sourceLineNo">431</span>      future = tableCache.allRequests.get(req);<a name="line.431"></a>
+<span class="sourceLineNo">432</span>      if (future == null) {<a name="line.432"></a>
+<span class="sourceLineNo">433</span>        future = new CompletableFuture&lt;&gt;();<a name="line.433"></a>
+<span class="sourceLineNo">434</span>        tableCache.allRequests.put(req, future);<a name="line.434"></a>
+<span class="sourceLineNo">435</span>        if (tableCache.hasQuota(maxConcurrentLocateRequestPerTable) &amp;&amp; !tableCache.isPending(req)) {<a name="line.435"></a>
+<span class="sourceLineNo">436</span>          tableCache.send(req);<a name="line.436"></a>
+<span class="sourceLineNo">437</span>          sendRequest = true;<a name="line.437"></a>
+<span class="sourceLineNo">438</span>        }<a name="line.438"></a>
+<span class="sourceLineNo">439</span>      }<a name="line.439"></a>
+<span class="sourceLineNo">440</span>    }<a name="line.440"></a>
+<span class="sourceLineNo">441</span>    if (sendRequest) {<a name="line.441"></a>
+<span class="sourceLineNo">442</span>      locateInMeta(tableName, req);<a name="line.442"></a>
+<span class="sourceLineNo">443</span>    }<a name="line.443"></a>
+<span class="sourceLineNo">444</span>    return future;<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>  CompletableFuture&lt;HRegionLocation&gt; getRegionLocation(TableName tableName, byte[] row,<a name="line.447"></a>
+<span class="sourceLineNo">448</span>      RegionLocateType locateType, boolean reload) {<a name="line.448"></a>
+<span class="sourceLineNo">449</span>    if (locateType.equals(RegionLocateType.BEFORE)) {<a name="line.449"></a>
+<span class="sourceLineNo">450</span>      return getRegionLocationInternal(tableName, row, locateType, reload);<a name="line.450"></a>
+<span class="sourceLineNo">451</span>    } else {<a name="line.451"></a>
+<span class="sourceLineNo">452</span>      // as we know the exact row after us, so we can just create the new row, and use the same<a name="line.452"></a>
+<span class="sourceLineNo">453</span>      // algorithm to locate it.<a name="line.453"></a>
+<span class="sourceLineNo">454</span>      if (locateType.equals(RegionLocateType.AFTER)) {<a name="line.454"></a>
+<span class="sourceLineNo">455</span>        row = createClosestRowAfter(row);<a name="line.455"></a>
 <span class="sourceLineNo">456</span>      }<a name="line.456"></a>
-<span class="sourceLineNo">457</span>      return tableCache.cache.get(l.getRegion().getStartKey());<a name="line.457"></a>
-<span class="sourceLineNo">458</span>    }, this::addToCache, this::removeFromCache);<a name="line.458"></a>
+<span class="sourceLineNo">457</span>      return getRegionLocationInternal(tableName, row, RegionLocateType.CURRENT, reload);<a name="line.457"></a>
+<span class="sourceLineNo">458</span>    }<a name="line.458"></a>
 <span class="sourceLineNo">459</span>  }<a name="line.459"></a>
 <span class="sourceLineNo">460</span><a name="line.460"></a>
-<span class="sourceLineNo">461</span>  void clearCache(TableName tableName) {<a name="line.461"></a>
-<span class="sourceLineNo">462</span>    TableCache tableCache = cache.remove(tableName);<a name="line.462"></a>
-<span class="sourceLineNo">463</span>    if (tableCache == null) {<a name="line.463"></a>
-<span class="sourceLineNo">464</span>      return;<a name="line.464"></a>
-<span class="sourceLineNo">465</span>    }<a name="line.465"></a>
-<span class="sourceLineNo">466</span>    synchronized (tableCache) {<a name="line.466"></a>
-<span class="sourceLineNo">467</span>      if (!tableCache.allRequests.isEmpty()) {<a name="line.467"></a>
-<span class="sourceLineNo">468</span>        IOException error = new IOException("Cache cleared");<a name="line.468"></a>
-<span class="sourceLineNo">469</span>        tableCache.allRequests.values().forEach(f -&gt; f.completeExceptionally(error));<a name="line.469"></a>
-<span class="sourceLineNo">470</span>      }<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">461</span>  void updateCachedLocation(HRegionLocation loc, Throwable exception) {<a name="line.461"></a>
+<span class="sourceLineNo">462</span>    AsyncRegionLocator.updateCachedLocation(loc, exception, l -&gt; {<a name="line.462"></a>
+<span class="sourceLineNo">463</span>      TableCache tableCache = cache.get(l.getRegion().getTable());<a name="line.463"></a>
+<span class="sourceLineNo">464</span>      if (tableCache == null) {<a name="line.464"></a>
+<span class="sourceLineNo">465</span>        return null;<a name="line.465"></a>
+<span class="sourceLineNo">466</span>      }<a name="line.466"></a>
+<span class="sourceLineNo">467</span>      return tableCache.cache.get(l.getRegion().getStartKey());<a name="line.467"></a>
+<span class="sourceLineNo">468</span>    }, this::addToCache, this::removeFromCache);<a name="line.468"></a>
+<span class="sourceLineNo">469</span>  }<a name="line.469"></a>
+<span cla

<TRUNCATED>

Mime
View raw message