hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [21/51] [partial] hbase-site git commit: Published site at 05161fcbfdd78f5684b9cb52c49a02be5ad14499.
Date Mon, 07 Mar 2016 16:13:57 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/2211f347/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncProcess.AsyncRequestFutureImpl.SingleServerRequestRunnable.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncProcess.AsyncRequestFutureImpl.SingleServerRequestRunnable.html b/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncProcess.AsyncRequestFutureImpl.SingleServerRequestRunnable.html
index d813e71..1eb85f1 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncProcess.AsyncRequestFutureImpl.SingleServerRequestRunnable.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/client/AsyncProcess.AsyncRequestFutureImpl.SingleServerRequestRunnable.html
@@ -63,1786 +63,1816 @@
 <span class="sourceLineNo">055</span>import org.apache.hadoop.hbase.client.coprocessor.Batch;<a name="line.55"></a>
 <span class="sourceLineNo">056</span>import org.apache.hadoop.hbase.exceptions.ClientExceptionsUtil;<a name="line.56"></a>
 <span class="sourceLineNo">057</span>import org.apache.hadoop.hbase.ipc.RpcControllerFactory;<a name="line.57"></a>
-<span class="sourceLineNo">058</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.58"></a>
-<span class="sourceLineNo">059</span>import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;<a name="line.59"></a>
-<span class="sourceLineNo">060</span>import org.apache.htrace.Trace;<a name="line.60"></a>
-<span class="sourceLineNo">061</span><a name="line.61"></a>
-<span class="sourceLineNo">062</span>import com.google.common.annotations.VisibleForTesting;<a name="line.62"></a>
-<span class="sourceLineNo">063</span><a name="line.63"></a>
-<span class="sourceLineNo">064</span>/**<a name="line.64"></a>
-<span class="sourceLineNo">065</span> * This class  allows a continuous flow of requests. It's written to be compatible with a<a name="line.65"></a>
-<span class="sourceLineNo">066</span> * synchronous caller such as HTable.<a name="line.66"></a>
-<span class="sourceLineNo">067</span> * &lt;p&gt;<a name="line.67"></a>
-<span class="sourceLineNo">068</span> * The caller sends a buffer of operation, by calling submit. This class extract from this list<a name="line.68"></a>
-<span class="sourceLineNo">069</span> * the operations it can send, i.e. the operations that are on region that are not considered<a name="line.69"></a>
-<span class="sourceLineNo">070</span> * as busy. The process is asynchronous, i.e. it returns immediately when if has finished to<a name="line.70"></a>
-<span class="sourceLineNo">071</span> * iterate on the list. If, and only if, the maximum number of current task is reached, the call<a name="line.71"></a>
-<span class="sourceLineNo">072</span> * to submit will block. Alternatively, the caller can call submitAll, in which case all the<a name="line.72"></a>
-<span class="sourceLineNo">073</span> * operations will be sent. Each call to submit returns a future-like object that can be used<a name="line.73"></a>
-<span class="sourceLineNo">074</span> * to track operation progress.<a name="line.74"></a>
-<span class="sourceLineNo">075</span> * &lt;/p&gt;<a name="line.75"></a>
-<span class="sourceLineNo">076</span> * &lt;p&gt;<a name="line.76"></a>
-<span class="sourceLineNo">077</span> * The class manages internally the retries.<a name="line.77"></a>
-<span class="sourceLineNo">078</span> * &lt;/p&gt;<a name="line.78"></a>
-<span class="sourceLineNo">079</span> * &lt;p&gt;<a name="line.79"></a>
-<span class="sourceLineNo">080</span> * The class can be constructed in regular mode, or "global error" mode. In global error mode,<a name="line.80"></a>
-<span class="sourceLineNo">081</span> * AP tracks errors across all calls (each "future" also has global view of all errors). That<a name="line.81"></a>
-<span class="sourceLineNo">082</span> * mode is necessary for backward compat with HTable behavior, where multiple submissions are<a name="line.82"></a>
-<span class="sourceLineNo">083</span> * made and the errors can propagate using any put/flush call, from previous calls.<a name="line.83"></a>
-<span class="sourceLineNo">084</span> * In "regular" mode, the errors are tracked inside the Future object that is returned.<a name="line.84"></a>
-<span class="sourceLineNo">085</span> * The results are always tracked inside the Future object and can be retrieved when the call<a name="line.85"></a>
-<span class="sourceLineNo">086</span> * has finished. Partial results can also be retrieved if some part of multi-request failed.<a name="line.86"></a>
-<span class="sourceLineNo">087</span> * &lt;/p&gt;<a name="line.87"></a>
-<span class="sourceLineNo">088</span> * &lt;p&gt;<a name="line.88"></a>
-<span class="sourceLineNo">089</span> * This class is thread safe in regular mode; in global error code, submitting operations and<a name="line.89"></a>
-<span class="sourceLineNo">090</span> * retrieving errors from different threads may be not thread safe.<a name="line.90"></a>
-<span class="sourceLineNo">091</span> * Internally, the class is thread safe enough to manage simultaneously new submission and results<a name="line.91"></a>
-<span class="sourceLineNo">092</span> * arising from older operations.<a name="line.92"></a>
-<span class="sourceLineNo">093</span> * &lt;/p&gt;<a name="line.93"></a>
-<span class="sourceLineNo">094</span> * &lt;p&gt;<a name="line.94"></a>
-<span class="sourceLineNo">095</span> * Internally, this class works with {@link Row}, this mean it could be theoretically used for<a name="line.95"></a>
-<span class="sourceLineNo">096</span> * gets as well.<a name="line.96"></a>
-<span class="sourceLineNo">097</span> * &lt;/p&gt;<a name="line.97"></a>
-<span class="sourceLineNo">098</span> */<a name="line.98"></a>
-<span class="sourceLineNo">099</span>@InterfaceAudience.Private<a name="line.99"></a>
-<span class="sourceLineNo">100</span>class AsyncProcess {<a name="line.100"></a>
-<span class="sourceLineNo">101</span>  private static final Log LOG = LogFactory.getLog(AsyncProcess.class);<a name="line.101"></a>
-<span class="sourceLineNo">102</span>  protected static final AtomicLong COUNTER = new AtomicLong();<a name="line.102"></a>
-<span class="sourceLineNo">103</span><a name="line.103"></a>
-<span class="sourceLineNo">104</span>  public static final String PRIMARY_CALL_TIMEOUT_KEY = "hbase.client.primaryCallTimeout.multiget";<a name="line.104"></a>
-<span class="sourceLineNo">105</span><a name="line.105"></a>
-<span class="sourceLineNo">106</span>  /**<a name="line.106"></a>
-<span class="sourceLineNo">107</span>   * Configure the number of failures after which the client will start logging. A few failures<a name="line.107"></a>
-<span class="sourceLineNo">108</span>   * is fine: region moved, then is not opened, then is overloaded. We try to have an acceptable<a name="line.108"></a>
-<span class="sourceLineNo">109</span>   * heuristic for the number of errors we don't log. 9 was chosen because we wait for 1s at<a name="line.109"></a>
-<span class="sourceLineNo">110</span>   * this stage.<a name="line.110"></a>
-<span class="sourceLineNo">111</span>   */<a name="line.111"></a>
-<span class="sourceLineNo">112</span>  public static final String START_LOG_ERRORS_AFTER_COUNT_KEY =<a name="line.112"></a>
-<span class="sourceLineNo">113</span>      "hbase.client.start.log.errors.counter";<a name="line.113"></a>
-<span class="sourceLineNo">114</span>  public static final int DEFAULT_START_LOG_ERRORS_AFTER_COUNT = 9;<a name="line.114"></a>
-<span class="sourceLineNo">115</span><a name="line.115"></a>
-<span class="sourceLineNo">116</span>  /**<a name="line.116"></a>
-<span class="sourceLineNo">117</span>   * The context used to wait for results from one submit call.<a name="line.117"></a>
-<span class="sourceLineNo">118</span>   * 1) If AsyncProcess is set to track errors globally, and not per call (for HTable puts),<a name="line.118"></a>
-<span class="sourceLineNo">119</span>   *    then errors and failed operations in this object will reflect global errors.<a name="line.119"></a>
-<span class="sourceLineNo">120</span>   * 2) If submit call is made with needResults false, results will not be saved.<a name="line.120"></a>
-<span class="sourceLineNo">121</span>   *  */<a name="line.121"></a>
-<span class="sourceLineNo">122</span>  public static interface AsyncRequestFuture {<a name="line.122"></a>
-<span class="sourceLineNo">123</span>    public boolean hasError();<a name="line.123"></a>
-<span class="sourceLineNo">124</span>    public RetriesExhaustedWithDetailsException getErrors();<a name="line.124"></a>
-<span class="sourceLineNo">125</span>    public List&lt;? extends Row&gt; getFailedOperations();<a name="line.125"></a>
-<span class="sourceLineNo">126</span>    public Object[] getResults() throws InterruptedIOException;<a name="line.126"></a>
-<span class="sourceLineNo">127</span>    /** Wait until all tasks are executed, successfully or not. */<a name="line.127"></a>
-<span class="sourceLineNo">128</span>    public void waitUntilDone() throws InterruptedIOException;<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>  /**<a name="line.131"></a>
-<span class="sourceLineNo">132</span>   * Return value from a submit that didn't contain any requests.<a name="line.132"></a>
-<span class="sourceLineNo">133</span>   */<a name="line.133"></a>
-<span class="sourceLineNo">134</span>  private static final AsyncRequestFuture NO_REQS_RESULT = new AsyncRequestFuture() {<a name="line.134"></a>
-<span class="sourceLineNo">135</span>    final Object[] result = new Object[0];<a name="line.135"></a>
-<span class="sourceLineNo">136</span><a name="line.136"></a>
-<span class="sourceLineNo">137</span>    @Override<a name="line.137"></a>
-<span class="sourceLineNo">138</span>    public boolean hasError() {<a name="line.138"></a>
-<span class="sourceLineNo">139</span>      return false;<a name="line.139"></a>
-<span class="sourceLineNo">140</span>    }<a name="line.140"></a>
-<span class="sourceLineNo">141</span><a name="line.141"></a>
-<span class="sourceLineNo">142</span>    @Override<a name="line.142"></a>
-<span class="sourceLineNo">143</span>    public RetriesExhaustedWithDetailsException getErrors() {<a name="line.143"></a>
-<span class="sourceLineNo">144</span>      return null;<a name="line.144"></a>
-<span class="sourceLineNo">145</span>    }<a name="line.145"></a>
-<span class="sourceLineNo">146</span><a name="line.146"></a>
-<span class="sourceLineNo">147</span>    @Override<a name="line.147"></a>
-<span class="sourceLineNo">148</span>    public List&lt;? extends Row&gt; getFailedOperations() {<a name="line.148"></a>
-<span class="sourceLineNo">149</span>      return null;<a name="line.149"></a>
-<span class="sourceLineNo">150</span>    }<a name="line.150"></a>
-<span class="sourceLineNo">151</span><a name="line.151"></a>
-<span class="sourceLineNo">152</span>    @Override<a name="line.152"></a>
-<span class="sourceLineNo">153</span>    public Object[] getResults() {<a name="line.153"></a>
-<span class="sourceLineNo">154</span>      return result;<a name="line.154"></a>
-<span class="sourceLineNo">155</span>    }<a name="line.155"></a>
-<span class="sourceLineNo">156</span><a name="line.156"></a>
-<span class="sourceLineNo">157</span>    @Override<a name="line.157"></a>
-<span class="sourceLineNo">158</span>    public void waitUntilDone() throws InterruptedIOException {<a name="line.158"></a>
-<span class="sourceLineNo">159</span>    }<a name="line.159"></a>
-<span class="sourceLineNo">160</span>  };<a name="line.160"></a>
-<span class="sourceLineNo">161</span><a name="line.161"></a>
-<span class="sourceLineNo">162</span>  /** Sync point for calls to multiple replicas for the same user request (Get).<a name="line.162"></a>
-<span class="sourceLineNo">163</span>   * Created and put in the results array (we assume replica calls require results) when<a name="line.163"></a>
-<span class="sourceLineNo">164</span>   * the replica calls are launched. See results for details of this process.<a name="line.164"></a>
-<span class="sourceLineNo">165</span>   * POJO, all fields are public. To modify them, the object itself is locked. */<a name="line.165"></a>
-<span class="sourceLineNo">166</span>  private static class ReplicaResultState {<a name="line.166"></a>
-<span class="sourceLineNo">167</span>    public ReplicaResultState(int callCount) {<a name="line.167"></a>
-<span class="sourceLineNo">168</span>      this.callCount = callCount;<a name="line.168"></a>
-<span class="sourceLineNo">169</span>    }<a name="line.169"></a>
-<span class="sourceLineNo">170</span><a name="line.170"></a>
-<span class="sourceLineNo">171</span>    /** Number of calls outstanding, or 0 if a call succeeded (even with others outstanding). */<a name="line.171"></a>
-<span class="sourceLineNo">172</span>    int callCount;<a name="line.172"></a>
-<span class="sourceLineNo">173</span>    /** Errors for which it is not decided whether we will report them to user. If one of the<a name="line.173"></a>
-<span class="sourceLineNo">174</span>     * calls succeeds, we will discard the errors that may have happened in the other calls. */<a name="line.174"></a>
-<span class="sourceLineNo">175</span>    BatchErrors replicaErrors = null;<a name="line.175"></a>
-<span class="sourceLineNo">176</span><a name="line.176"></a>
-<span class="sourceLineNo">177</span>    @Override<a name="line.177"></a>
-<span class="sourceLineNo">178</span>    public String toString() {<a name="line.178"></a>
-<span class="sourceLineNo">179</span>      return "[call count " + callCount + "; errors " + replicaErrors + "]";<a name="line.179"></a>
-<span class="sourceLineNo">180</span>    }<a name="line.180"></a>
-<span class="sourceLineNo">181</span>  }<a name="line.181"></a>
-<span class="sourceLineNo">182</span><a name="line.182"></a>
+<span class="sourceLineNo">058</span>import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;<a name="line.58"></a>
+<span class="sourceLineNo">059</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.59"></a>
+<span class="sourceLineNo">060</span>import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;<a name="line.60"></a>
+<span class="sourceLineNo">061</span>import org.apache.htrace.Trace;<a name="line.61"></a>
+<span class="sourceLineNo">062</span><a name="line.62"></a>
+<span class="sourceLineNo">063</span>import com.google.common.annotations.VisibleForTesting;<a name="line.63"></a>
+<span class="sourceLineNo">064</span><a name="line.64"></a>
+<span class="sourceLineNo">065</span>/**<a name="line.65"></a>
+<span class="sourceLineNo">066</span> * This class  allows a continuous flow of requests. It's written to be compatible with a<a name="line.66"></a>
+<span class="sourceLineNo">067</span> * synchronous caller such as HTable.<a name="line.67"></a>
+<span class="sourceLineNo">068</span> * &lt;p&gt;<a name="line.68"></a>
+<span class="sourceLineNo">069</span> * The caller sends a buffer of operation, by calling submit. This class extract from this list<a name="line.69"></a>
+<span class="sourceLineNo">070</span> * the operations it can send, i.e. the operations that are on region that are not considered<a name="line.70"></a>
+<span class="sourceLineNo">071</span> * as busy. The process is asynchronous, i.e. it returns immediately when if has finished to<a name="line.71"></a>
+<span class="sourceLineNo">072</span> * iterate on the list. If, and only if, the maximum number of current task is reached, the call<a name="line.72"></a>
+<span class="sourceLineNo">073</span> * to submit will block. Alternatively, the caller can call submitAll, in which case all the<a name="line.73"></a>
+<span class="sourceLineNo">074</span> * operations will be sent. Each call to submit returns a future-like object that can be used<a name="line.74"></a>
+<span class="sourceLineNo">075</span> * to track operation progress.<a name="line.75"></a>
+<span class="sourceLineNo">076</span> * &lt;/p&gt;<a name="line.76"></a>
+<span class="sourceLineNo">077</span> * &lt;p&gt;<a name="line.77"></a>
+<span class="sourceLineNo">078</span> * The class manages internally the retries.<a name="line.78"></a>
+<span class="sourceLineNo">079</span> * &lt;/p&gt;<a name="line.79"></a>
+<span class="sourceLineNo">080</span> * &lt;p&gt;<a name="line.80"></a>
+<span class="sourceLineNo">081</span> * The class can be constructed in regular mode, or "global error" mode. In global error mode,<a name="line.81"></a>
+<span class="sourceLineNo">082</span> * AP tracks errors across all calls (each "future" also has global view of all errors). That<a name="line.82"></a>
+<span class="sourceLineNo">083</span> * mode is necessary for backward compat with HTable behavior, where multiple submissions are<a name="line.83"></a>
+<span class="sourceLineNo">084</span> * made and the errors can propagate using any put/flush call, from previous calls.<a name="line.84"></a>
+<span class="sourceLineNo">085</span> * In "regular" mode, the errors are tracked inside the Future object that is returned.<a name="line.85"></a>
+<span class="sourceLineNo">086</span> * The results are always tracked inside the Future object and can be retrieved when the call<a name="line.86"></a>
+<span class="sourceLineNo">087</span> * has finished. Partial results can also be retrieved if some part of multi-request failed.<a name="line.87"></a>
+<span class="sourceLineNo">088</span> * &lt;/p&gt;<a name="line.88"></a>
+<span class="sourceLineNo">089</span> * &lt;p&gt;<a name="line.89"></a>
+<span class="sourceLineNo">090</span> * This class is thread safe in regular mode; in global error code, submitting operations and<a name="line.90"></a>
+<span class="sourceLineNo">091</span> * retrieving errors from different threads may be not thread safe.<a name="line.91"></a>
+<span class="sourceLineNo">092</span> * Internally, the class is thread safe enough to manage simultaneously new submission and results<a name="line.92"></a>
+<span class="sourceLineNo">093</span> * arising from older operations.<a name="line.93"></a>
+<span class="sourceLineNo">094</span> * &lt;/p&gt;<a name="line.94"></a>
+<span class="sourceLineNo">095</span> * &lt;p&gt;<a name="line.95"></a>
+<span class="sourceLineNo">096</span> * Internally, this class works with {@link Row}, this mean it could be theoretically used for<a name="line.96"></a>
+<span class="sourceLineNo">097</span> * gets as well.<a name="line.97"></a>
+<span class="sourceLineNo">098</span> * &lt;/p&gt;<a name="line.98"></a>
+<span class="sourceLineNo">099</span> */<a name="line.99"></a>
+<span class="sourceLineNo">100</span>@InterfaceAudience.Private<a name="line.100"></a>
+<span class="sourceLineNo">101</span>class AsyncProcess {<a name="line.101"></a>
+<span class="sourceLineNo">102</span>  private static final Log LOG = LogFactory.getLog(AsyncProcess.class);<a name="line.102"></a>
+<span class="sourceLineNo">103</span>  protected static final AtomicLong COUNTER = new AtomicLong();<a name="line.103"></a>
+<span class="sourceLineNo">104</span><a name="line.104"></a>
+<span class="sourceLineNo">105</span>  public static final String PRIMARY_CALL_TIMEOUT_KEY = "hbase.client.primaryCallTimeout.multiget";<a name="line.105"></a>
+<span class="sourceLineNo">106</span><a name="line.106"></a>
+<span class="sourceLineNo">107</span>  /**<a name="line.107"></a>
+<span class="sourceLineNo">108</span>   * Configure the number of failures after which the client will start logging. A few failures<a name="line.108"></a>
+<span class="sourceLineNo">109</span>   * is fine: region moved, then is not opened, then is overloaded. We try to have an acceptable<a name="line.109"></a>
+<span class="sourceLineNo">110</span>   * heuristic for the number of errors we don't log. 9 was chosen because we wait for 1s at<a name="line.110"></a>
+<span class="sourceLineNo">111</span>   * this stage.<a name="line.111"></a>
+<span class="sourceLineNo">112</span>   */<a name="line.112"></a>
+<span class="sourceLineNo">113</span>  public static final String START_LOG_ERRORS_AFTER_COUNT_KEY =<a name="line.113"></a>
+<span class="sourceLineNo">114</span>      "hbase.client.start.log.errors.counter";<a name="line.114"></a>
+<span class="sourceLineNo">115</span>  public static final int DEFAULT_START_LOG_ERRORS_AFTER_COUNT = 9;<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>   * The context used to wait for results from one submit call.<a name="line.118"></a>
+<span class="sourceLineNo">119</span>   * 1) If AsyncProcess is set to track errors globally, and not per call (for HTable puts),<a name="line.119"></a>
+<span class="sourceLineNo">120</span>   *    then errors and failed operations in this object will reflect global errors.<a name="line.120"></a>
+<span class="sourceLineNo">121</span>   * 2) If submit call is made with needResults false, results will not be saved.<a name="line.121"></a>
+<span class="sourceLineNo">122</span>   *  */<a name="line.122"></a>
+<span class="sourceLineNo">123</span>  public static interface AsyncRequestFuture {<a name="line.123"></a>
+<span class="sourceLineNo">124</span>    public boolean hasError();<a name="line.124"></a>
+<span class="sourceLineNo">125</span>    public RetriesExhaustedWithDetailsException getErrors();<a name="line.125"></a>
+<span class="sourceLineNo">126</span>    public List&lt;? extends Row&gt; getFailedOperations();<a name="line.126"></a>
+<span class="sourceLineNo">127</span>    public Object[] getResults() throws InterruptedIOException;<a name="line.127"></a>
+<span class="sourceLineNo">128</span>    /** Wait until all tasks are executed, successfully or not. */<a name="line.128"></a>
+<span class="sourceLineNo">129</span>    public void waitUntilDone() throws InterruptedIOException;<a name="line.129"></a>
+<span class="sourceLineNo">130</span>  }<a name="line.130"></a>
+<span class="sourceLineNo">131</span><a name="line.131"></a>
+<span class="sourceLineNo">132</span>  /**<a name="line.132"></a>
+<span class="sourceLineNo">133</span>   * Return value from a submit that didn't contain any requests.<a name="line.133"></a>
+<span class="sourceLineNo">134</span>   */<a name="line.134"></a>
+<span class="sourceLineNo">135</span>  private static final AsyncRequestFuture NO_REQS_RESULT = new AsyncRequestFuture() {<a name="line.135"></a>
+<span class="sourceLineNo">136</span>    final Object[] result = new Object[0];<a name="line.136"></a>
+<span class="sourceLineNo">137</span><a name="line.137"></a>
+<span class="sourceLineNo">138</span>    @Override<a name="line.138"></a>
+<span class="sourceLineNo">139</span>    public boolean hasError() {<a name="line.139"></a>
+<span class="sourceLineNo">140</span>      return false;<a name="line.140"></a>
+<span class="sourceLineNo">141</span>    }<a name="line.141"></a>
+<span class="sourceLineNo">142</span><a name="line.142"></a>
+<span class="sourceLineNo">143</span>    @Override<a name="line.143"></a>
+<span class="sourceLineNo">144</span>    public RetriesExhaustedWithDetailsException getErrors() {<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>    @Override<a name="line.148"></a>
+<span class="sourceLineNo">149</span>    public List&lt;? extends Row&gt; getFailedOperations() {<a name="line.149"></a>
+<span class="sourceLineNo">150</span>      return null;<a name="line.150"></a>
+<span class="sourceLineNo">151</span>    }<a name="line.151"></a>
+<span class="sourceLineNo">152</span><a name="line.152"></a>
+<span class="sourceLineNo">153</span>    @Override<a name="line.153"></a>
+<span class="sourceLineNo">154</span>    public Object[] getResults() {<a name="line.154"></a>
+<span class="sourceLineNo">155</span>      return result;<a name="line.155"></a>
+<span class="sourceLineNo">156</span>    }<a name="line.156"></a>
+<span class="sourceLineNo">157</span><a name="line.157"></a>
+<span class="sourceLineNo">158</span>    @Override<a name="line.158"></a>
+<span class="sourceLineNo">159</span>    public void waitUntilDone() throws InterruptedIOException {<a name="line.159"></a>
+<span class="sourceLineNo">160</span>    }<a name="line.160"></a>
+<span class="sourceLineNo">161</span>  };<a name="line.161"></a>
+<span class="sourceLineNo">162</span><a name="line.162"></a>
+<span class="sourceLineNo">163</span>  /** Sync point for calls to multiple replicas for the same user request (Get).<a name="line.163"></a>
+<span class="sourceLineNo">164</span>   * Created and put in the results array (we assume replica calls require results) when<a name="line.164"></a>
+<span class="sourceLineNo">165</span>   * the replica calls are launched. See results for details of this process.<a name="line.165"></a>
+<span class="sourceLineNo">166</span>   * POJO, all fields are public. To modify them, the object itself is locked. */<a name="line.166"></a>
+<span class="sourceLineNo">167</span>  private static class ReplicaResultState {<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    public ReplicaResultState(int callCount) {<a name="line.168"></a>
+<span class="sourceLineNo">169</span>      this.callCount = callCount;<a name="line.169"></a>
+<span class="sourceLineNo">170</span>    }<a name="line.170"></a>
+<span class="sourceLineNo">171</span><a name="line.171"></a>
+<span class="sourceLineNo">172</span>    /** Number of calls outstanding, or 0 if a call succeeded (even with others outstanding). */<a name="line.172"></a>
+<span class="sourceLineNo">173</span>    int callCount;<a name="line.173"></a>
+<span class="sourceLineNo">174</span>    /** Errors for which it is not decided whether we will report them to user. If one of the<a name="line.174"></a>
+<span class="sourceLineNo">175</span>     * calls succeeds, we will discard the errors that may have happened in the other calls. */<a name="line.175"></a>
+<span class="sourceLineNo">176</span>    BatchErrors replicaErrors = null;<a name="line.176"></a>
+<span class="sourceLineNo">177</span><a name="line.177"></a>
+<span class="sourceLineNo">178</span>    @Override<a name="line.178"></a>
+<span class="sourceLineNo">179</span>    public String toString() {<a name="line.179"></a>
+<span class="sourceLineNo">180</span>      return "[call count " + callCount + "; errors " + replicaErrors + "]";<a name="line.180"></a>
+<span class="sourceLineNo">181</span>    }<a name="line.181"></a>
+<span class="sourceLineNo">182</span>  }<a name="line.182"></a>
 <span class="sourceLineNo">183</span><a name="line.183"></a>
-<span class="sourceLineNo">184</span>  // TODO: many of the fields should be made private<a name="line.184"></a>
-<span class="sourceLineNo">185</span>  protected final long id;<a name="line.185"></a>
-<span class="sourceLineNo">186</span><a name="line.186"></a>
-<span class="sourceLineNo">187</span>  protected final ClusterConnection connection;<a name="line.187"></a>
-<span class="sourceLineNo">188</span>  protected final RpcRetryingCallerFactory rpcCallerFactory;<a name="line.188"></a>
-<span class="sourceLineNo">189</span>  protected final RpcControllerFactory rpcFactory;<a name="line.189"></a>
-<span class="sourceLineNo">190</span>  protected final BatchErrors globalErrors;<a name="line.190"></a>
-<span class="sourceLineNo">191</span>  protected final ExecutorService pool;<a name="line.191"></a>
-<span class="sourceLineNo">192</span><a name="line.192"></a>
-<span class="sourceLineNo">193</span>  protected final AtomicLong tasksInProgress = new AtomicLong(0);<a name="line.193"></a>
-<span class="sourceLineNo">194</span>  protected final ConcurrentMap&lt;byte[], AtomicInteger&gt; taskCounterPerRegion =<a name="line.194"></a>
-<span class="sourceLineNo">195</span>      new ConcurrentSkipListMap&lt;byte[], AtomicInteger&gt;(Bytes.BYTES_COMPARATOR);<a name="line.195"></a>
-<span class="sourceLineNo">196</span>  protected final ConcurrentMap&lt;ServerName, AtomicInteger&gt; taskCounterPerServer =<a name="line.196"></a>
-<span class="sourceLineNo">197</span>      new ConcurrentHashMap&lt;ServerName, AtomicInteger&gt;();<a name="line.197"></a>
-<span class="sourceLineNo">198</span><a name="line.198"></a>
-<span class="sourceLineNo">199</span>  // Start configuration settings.<a name="line.199"></a>
-<span class="sourceLineNo">200</span>  private final int startLogErrorsCnt;<a name="line.200"></a>
-<span class="sourceLineNo">201</span><a name="line.201"></a>
-<span class="sourceLineNo">202</span>  /**<a name="line.202"></a>
-<span class="sourceLineNo">203</span>   * The number of tasks simultaneously executed on the cluster.<a name="line.203"></a>
-<span class="sourceLineNo">204</span>   */<a name="line.204"></a>
-<span class="sourceLineNo">205</span>  protected final int maxTotalConcurrentTasks;<a name="line.205"></a>
-<span class="sourceLineNo">206</span><a name="line.206"></a>
-<span class="sourceLineNo">207</span>  /**<a name="line.207"></a>
-<span class="sourceLineNo">208</span>   * The number of tasks we run in parallel on a single region.<a name="line.208"></a>
-<span class="sourceLineNo">209</span>   * With 1 (the default) , we ensure that the ordering of the queries is respected: we don't start<a name="line.209"></a>
-<span class="sourceLineNo">210</span>   * a set of operations on a region before the previous one is done. As well, this limits<a name="line.210"></a>
-<span class="sourceLineNo">211</span>   * the pressure we put on the region server.<a name="line.211"></a>
-<span class="sourceLineNo">212</span>   */<a name="line.212"></a>
-<span class="sourceLineNo">213</span>  protected final int maxConcurrentTasksPerRegion;<a name="line.213"></a>
-<span class="sourceLineNo">214</span><a name="line.214"></a>
-<span class="sourceLineNo">215</span>  /**<a name="line.215"></a>
-<span class="sourceLineNo">216</span>   * The number of task simultaneously executed on a single region server.<a name="line.216"></a>
-<span class="sourceLineNo">217</span>   */<a name="line.217"></a>
-<span class="sourceLineNo">218</span>  protected final int maxConcurrentTasksPerServer;<a name="line.218"></a>
-<span class="sourceLineNo">219</span>  protected final long pause;<a name="line.219"></a>
-<span class="sourceLineNo">220</span>  protected int numTries;<a name="line.220"></a>
-<span class="sourceLineNo">221</span>  protected int serverTrackerTimeout;<a name="line.221"></a>
-<span class="sourceLineNo">222</span>  protected int timeout;<a name="line.222"></a>
-<span class="sourceLineNo">223</span>  protected long primaryCallTimeoutMicroseconds;<a name="line.223"></a>
-<span class="sourceLineNo">224</span>  // End configuration settings.<a name="line.224"></a>
-<span class="sourceLineNo">225</span><a name="line.225"></a>
-<span class="sourceLineNo">226</span>  protected static class BatchErrors {<a name="line.226"></a>
-<span class="sourceLineNo">227</span>    private final List&lt;Throwable&gt; throwables = new ArrayList&lt;Throwable&gt;();<a name="line.227"></a>
-<span class="sourceLineNo">228</span>    private final List&lt;Row&gt; actions = new ArrayList&lt;Row&gt;();<a name="line.228"></a>
-<span class="sourceLineNo">229</span>    private final List&lt;String&gt; addresses = new ArrayList&lt;String&gt;();<a name="line.229"></a>
-<span class="sourceLineNo">230</span><a name="line.230"></a>
-<span class="sourceLineNo">231</span>    public synchronized void add(Throwable ex, Row row, ServerName serverName) {<a name="line.231"></a>
-<span class="sourceLineNo">232</span>      if (row == null){<a name="line.232"></a>
-<span class="sourceLineNo">233</span>        throw new IllegalArgumentException("row cannot be null. location=" + serverName);<a name="line.233"></a>
-<span class="sourceLineNo">234</span>      }<a name="line.234"></a>
-<span class="sourceLineNo">235</span><a name="line.235"></a>
-<span class="sourceLineNo">236</span>      throwables.add(ex);<a name="line.236"></a>
-<span class="sourceLineNo">237</span>      actions.add(row);<a name="line.237"></a>
-<span class="sourceLineNo">238</span>      addresses.add(serverName != null ? serverName.toString() : "null");<a name="line.238"></a>
-<span class="sourceLineNo">239</span>    }<a name="line.239"></a>
-<span class="sourceLineNo">240</span><a name="line.240"></a>
-<span class="sourceLineNo">241</span>    public boolean hasErrors() {<a name="line.241"></a>
-<span class="sourceLineNo">242</span>      return !throwables.isEmpty();<a name="line.242"></a>
-<span class="sourceLineNo">243</span>    }<a name="line.243"></a>
-<span class="sourceLineNo">244</span><a name="line.244"></a>
-<span class="sourceLineNo">245</span>    private synchronized RetriesExhaustedWithDetailsException makeException() {<a name="line.245"></a>
-<span class="sourceLineNo">246</span>      return new RetriesExhaustedWithDetailsException(<a name="line.246"></a>
-<span class="sourceLineNo">247</span>          new ArrayList&lt;Throwable&gt;(throwables),<a name="line.247"></a>
-<span class="sourceLineNo">248</span>          new ArrayList&lt;Row&gt;(actions), new ArrayList&lt;String&gt;(addresses));<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>    public synchronized void clear() {<a name="line.251"></a>
-<span class="sourceLineNo">252</span>      throwables.clear();<a name="line.252"></a>
-<span class="sourceLineNo">253</span>      actions.clear();<a name="line.253"></a>
-<span class="sourceLineNo">254</span>      addresses.clear();<a name="line.254"></a>
-<span class="sourceLineNo">255</span>    }<a name="line.255"></a>
-<span class="sourceLineNo">256</span><a name="line.256"></a>
-<span class="sourceLineNo">257</span>    public synchronized void merge(BatchErrors other) {<a name="line.257"></a>
-<span class="sourceLineNo">258</span>      throwables.addAll(other.throwables);<a name="line.258"></a>
-<span class="sourceLineNo">259</span>      actions.addAll(other.actions);<a name="line.259"></a>
-<span class="sourceLineNo">260</span>      addresses.addAll(other.addresses);<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><a name="line.263"></a>
-<span class="sourceLineNo">264</span>  public AsyncProcess(ClusterConnection hc, Configuration conf, ExecutorService pool,<a name="line.264"></a>
-<span class="sourceLineNo">265</span>      RpcRetryingCallerFactory rpcCaller, boolean useGlobalErrors,<a name="line.265"></a>
-<span class="sourceLineNo">266</span>      RpcControllerFactory rpcFactory) {<a name="line.266"></a>
-<span class="sourceLineNo">267</span>    if (hc == null) {<a name="line.267"></a>
-<span class="sourceLineNo">268</span>      throw new IllegalArgumentException("HConnection cannot be null.");<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>    this.connection = hc;<a name="line.271"></a>
-<span class="sourceLineNo">272</span>    this.pool = pool;<a name="line.272"></a>
-<span class="sourceLineNo">273</span>    this.globalErrors = useGlobalErrors ? new BatchErrors() : null;<a name="line.273"></a>
-<span class="sourceLineNo">274</span><a name="line.274"></a>
-<span class="sourceLineNo">275</span>    this.id = COUNTER.incrementAndGet();<a name="line.275"></a>
-<span class="sourceLineNo">276</span><a name="line.276"></a>
-<span class="sourceLineNo">277</span>    this.pause = conf.getLong(HConstants.HBASE_CLIENT_PAUSE,<a name="line.277"></a>
-<span class="sourceLineNo">278</span>        HConstants.DEFAULT_HBASE_CLIENT_PAUSE);<a name="line.278"></a>
-<span class="sourceLineNo">279</span>    // how many times we could try in total, one more than retry number<a name="line.279"></a>
-<span class="sourceLineNo">280</span>    this.numTries = conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,<a name="line.280"></a>
-<span class="sourceLineNo">281</span>        HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER) + 1;<a name="line.281"></a>
-<span class="sourceLineNo">282</span>    this.timeout = conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY,<a name="line.282"></a>
-<span class="sourceLineNo">283</span>        HConstants.DEFAULT_HBASE_RPC_TIMEOUT);<a name="line.283"></a>
-<span class="sourceLineNo">284</span>    this.primaryCallTimeoutMicroseconds = conf.getInt(PRIMARY_CALL_TIMEOUT_KEY, 10000);<a name="line.284"></a>
-<span class="sourceLineNo">285</span><a name="line.285"></a>
-<span class="sourceLineNo">286</span>    this.maxTotalConcurrentTasks = conf.getInt(HConstants.HBASE_CLIENT_MAX_TOTAL_TASKS,<a name="line.286"></a>
-<span class="sourceLineNo">287</span>      HConstants.DEFAULT_HBASE_CLIENT_MAX_TOTAL_TASKS);<a name="line.287"></a>
-<span class="sourceLineNo">288</span>    this.maxConcurrentTasksPerServer = conf.getInt(HConstants.HBASE_CLIENT_MAX_PERSERVER_TASKS,<a name="line.288"></a>
-<span class="sourceLineNo">289</span>          HConstants.DEFAULT_HBASE_CLIENT_MAX_PERSERVER_TASKS);<a name="line.289"></a>
-<span class="sourceLineNo">290</span>    this.maxConcurrentTasksPerRegion = conf.getInt(HConstants.HBASE_CLIENT_MAX_PERREGION_TASKS,<a name="line.290"></a>
-<span class="sourceLineNo">291</span>          HConstants.DEFAULT_HBASE_CLIENT_MAX_PERREGION_TASKS);<a name="line.291"></a>
-<span class="sourceLineNo">292</span><a name="line.292"></a>
-<span class="sourceLineNo">293</span>    this.startLogErrorsCnt =<a name="line.293"></a>
-<span class="sourceLineNo">294</span>        conf.getInt(START_LOG_ERRORS_AFTER_COUNT_KEY, DEFAULT_START_LOG_ERRORS_AFTER_COUNT);<a name="line.294"></a>
-<span class="sourceLineNo">295</span><a name="line.295"></a>
-<span class="sourceLineNo">296</span>    if (this.maxTotalConcurrentTasks &lt;= 0) {<a name="line.296"></a>
-<span class="sourceLineNo">297</span>      throw new IllegalArgumentException("maxTotalConcurrentTasks=" + maxTotalConcurrentTasks);<a name="line.297"></a>
-<span class="sourceLineNo">298</span>    }<a name="line.298"></a>
-<span class="sourceLineNo">299</span>    if (this.maxConcurrentTasksPerServer &lt;= 0) {<a name="line.299"></a>
-<span class="sourceLineNo">300</span>      throw new IllegalArgumentException("maxConcurrentTasksPerServer=" +<a name="line.300"></a>
-<span class="sourceLineNo">301</span>          maxConcurrentTasksPerServer);<a name="line.301"></a>
-<span class="sourceLineNo">302</span>    }<a name="line.302"></a>
-<span class="sourceLineNo">303</span>    if (this.maxConcurrentTasksPerRegion &lt;= 0) {<a name="line.303"></a>
-<span class="sourceLineNo">304</span>      throw new IllegalArgumentException("maxConcurrentTasksPerRegion=" +<a name="line.304"></a>
-<span class="sourceLineNo">305</span>          maxConcurrentTasksPerRegion);<a name="line.305"></a>
-<span class="sourceLineNo">306</span>    }<a name="line.306"></a>
-<span class="sourceLineNo">307</span><a name="line.307"></a>
-<span class="sourceLineNo">308</span>    // Server tracker allows us to do faster, and yet useful (hopefully), retries.<a name="line.308"></a>
-<span class="sourceLineNo">309</span>    // However, if we are too useful, we might fail very quickly due to retry count limit.<a name="line.309"></a>
-<span class="sourceLineNo">310</span>    // To avoid this, we are going to cheat for now (see HBASE-7659), and calculate maximum<a name="line.310"></a>
-<span class="sourceLineNo">311</span>    // retry time if normal retries were used. Then we will retry until this time runs out.<a name="line.311"></a>
-<span class="sourceLineNo">312</span>    // If we keep hitting one server, the net effect will be the incremental backoff, and<a name="line.312"></a>
-<span class="sourceLineNo">313</span>    // essentially the same number of retries as planned. If we have to do faster retries,<a name="line.313"></a>
-<span class="sourceLineNo">314</span>    // we will do more retries in aggregate, but the user will be none the wiser.<a name="line.314"></a>
-<span class="sourceLineNo">315</span>    this.serverTrackerTimeout = 0;<a name="line.315"></a>
-<span class="sourceLineNo">316</span>    for (int i = 0; i &lt; this.numTries; ++i) {<a name="line.316"></a>
-<span class="sourceLineNo">317</span>      serverTrackerTimeout += ConnectionUtils.getPauseTime(this.pause, i);<a name="line.317"></a>
-<span class="sourceLineNo">318</span>    }<a name="line.318"></a>
-<span class="sourceLineNo">319</span><a name="line.319"></a>
-<span class="sourceLineNo">320</span>    this.rpcCallerFactory = rpcCaller;<a name="line.320"></a>
-<span class="sourceLineNo">321</span>    this.rpcFactory = rpcFactory;<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>  /**<a name="line.324"></a>
-<span class="sourceLineNo">325</span>   * @return pool if non null, otherwise returns this.pool if non null, otherwise throws<a name="line.325"></a>
-<span class="sourceLineNo">326</span>   *         RuntimeException<a name="line.326"></a>
-<span class="sourceLineNo">327</span>   */<a name="line.327"></a>
-<span class="sourceLineNo">328</span>  private ExecutorService getPool(ExecutorService pool) {<a name="line.328"></a>
-<span class="sourceLineNo">329</span>    if (pool != null) {<a name="line.329"></a>
-<span class="sourceLineNo">330</span>      return pool;<a name="line.330"></a>
-<span class="sourceLineNo">331</span>    }<a name="line.331"></a>
-<span class="sourceLineNo">332</span>    if (this.pool != null) {<a name="line.332"></a>
-<span class="sourceLineNo">333</span>      return this.pool;<a name="line.333"></a>
-<span class="sourceLineNo">334</span>    }<a name="line.334"></a>
-<span class="sourceLineNo">335</span>    throw new RuntimeException("Neither AsyncProcess nor request have ExecutorService");<a name="line.335"></a>
-<span class="sourceLineNo">336</span>  }<a name="line.336"></a>
-<span class="sourceLineNo">337</span><a name="line.337"></a>
-<span class="sourceLineNo">338</span>  /**<a name="line.338"></a>
-<span class="sourceLineNo">339</span>   * See {@link #submit(ExecutorService, TableName, List, boolean, Batch.Callback, boolean)}.<a name="line.339"></a>
-<span class="sourceLineNo">340</span>   * Uses default ExecutorService for this AP (must have been created with one).<a name="line.340"></a>
-<span class="sourceLineNo">341</span>   */<a name="line.341"></a>
-<span class="sourceLineNo">342</span>  public &lt;CResult&gt; AsyncRequestFuture submit(TableName tableName, List&lt;? extends Row&gt; rows,<a name="line.342"></a>
-<span class="sourceLineNo">343</span>      boolean atLeastOne, Batch.Callback&lt;CResult&gt; callback, boolean needResults)<a name="line.343"></a>
-<span class="sourceLineNo">344</span>      throws InterruptedIOException {<a name="line.344"></a>
-<span class="sourceLineNo">345</span>    return submit(null, tableName, rows, atLeastOne, callback, needResults);<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>  /**<a name="line.348"></a>
-<span class="sourceLineNo">349</span>   * Extract from the rows list what we can submit. The rows we can not submit are kept in the<a name="line.349"></a>
-<span class="sourceLineNo">350</span>   * list. Does not send requests to replicas (not currently used for anything other<a name="line.350"></a>
-<span class="sourceLineNo">351</span>   * than streaming puts anyway).<a name="line.351"></a>
-<span class="sourceLineNo">352</span>   *<a name="line.352"></a>
-<span class="sourceLineNo">353</span>   * @param pool ExecutorService to use.<a name="line.353"></a>
-<span class="sourceLineNo">354</span>   * @param tableName The table for which this request is needed.<a name="line.354"></a>
-<span class="sourceLineNo">355</span>   * @param callback Batch callback. Only called on success (94 behavior).<a name="line.355"></a>
-<span class="sourceLineNo">356</span>   * @param needResults Whether results are needed, or can be discarded.<a name="line.356"></a>
-<span class="sourceLineNo">357</span>   * @param rows - the submitted row. Modified by the method: we remove the rows we took.<a name="line.357"></a>
-<span class="sourceLineNo">358</span>   * @param atLeastOne true if we should submit at least a subset.<a name="line.358"></a>
-<span class="sourceLineNo">359</span>   */<a name="line.359"></a>
-<span class="sourceLineNo">360</span>  public &lt;CResult&gt; AsyncRequestFuture submit(ExecutorService pool, TableName tableName,<a name="line.360"></a>
-<span class="sourceLineNo">361</span>      List&lt;? extends Row&gt; rows, boolean atLeastOne, Batch.Callback&lt;CResult&gt; callback,<a name="line.361"></a>
-<span class="sourceLineNo">362</span>      boolean needResults) throws InterruptedIOException {<a name="line.362"></a>
-<span class="sourceLineNo">363</span>    if (rows.isEmpty()) {<a name="line.363"></a>
-<span class="sourceLineNo">364</span>      return NO_REQS_RESULT;<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>    Map&lt;ServerName, MultiAction&lt;Row&gt;&gt; actionsByServer =<a name="line.367"></a>
-<span class="sourceLineNo">368</span>        new HashMap&lt;ServerName, MultiAction&lt;Row&gt;&gt;();<a name="line.368"></a>
-<span class="sourceLineNo">369</span>    List&lt;Action&lt;Row&gt;&gt; retainedActions = new ArrayList&lt;Action&lt;Row&gt;&gt;(rows.size());<a name="line.369"></a>
-<span class="sourceLineNo">370</span><a name="line.370"></a>
-<span class="sourceLineNo">371</span>    NonceGenerator ng = this.connection.getNonceGenerator();<a name="line.371"></a>
-<span class="sourceLineNo">372</span>    long nonceGroup = ng.getNonceGroup(); // Currently, nonce group is per entire client.<a name="line.372"></a>
-<span class="sourceLineNo">373</span><a name="line.373"></a>
-<span class="sourceLineNo">374</span>    // Location errors that happen before we decide what requests to take.<a name="line.374"></a>
-<span class="sourceLineNo">375</span>    List&lt;Exception&gt; locationErrors = null;<a name="line.375"></a>
-<span class="sourceLineNo">376</span>    List&lt;Integer&gt; locationErrorRows = null;<a name="line.376"></a>
-<span class="sourceLineNo">377</span>    do {<a name="line.377"></a>
-<span class="sourceLineNo">378</span>      // Wait until there is at least one slot for a new task.<a name="line.378"></a>
-<span class="sourceLineNo">379</span>      waitForMaximumCurrentTasks(maxTotalConcurrentTasks - 1);<a name="line.379"></a>
-<span class="sourceLineNo">380</span><a name="line.380"></a>
-<span class="sourceLineNo">381</span>      // Remember the previous decisions about regions or region servers we put in the<a name="line.381"></a>
-<span class="sourceLineNo">382</span>      //  final multi.<a name="line.382"></a>
-<span class="sourceLineNo">383</span>      Map&lt;Long, Boolean&gt; regionIncluded = new HashMap&lt;Long, Boolean&gt;();<a name="line.383"></a>
-<span class="sourceLineNo">384</span>      Map&lt;ServerName, Boolean&gt; serverIncluded = new HashMap&lt;ServerName, Boolean&gt;();<a name="line.384"></a>
-<span class="sourceLineNo">385</span><a name="line.385"></a>
-<span class="sourceLineNo">386</span>      int posInList = -1;<a name="line.386"></a>
-<span class="sourceLineNo">387</span>      Iterator&lt;? extends Row&gt; it = rows.iterator();<a name="line.387"></a>
-<span class="sourceLineNo">388</span>      while (it.hasNext()) {<a name="line.388"></a>
-<span class="sourceLineNo">389</span>        Row r = it.next();<a name="line.389"></a>
-<span class="sourceLineNo">390</span>        HRegionLocation loc;<a name="line.390"></a>
-<span class="sourceLineNo">391</span>        try {<a name="line.391"></a>
-<span class="sourceLineNo">392</span>          if (r == null) {<a name="line.392"></a>
-<span class="sourceLineNo">393</span>            throw new IllegalArgumentException("#" + id + ", row cannot be null");<a name="line.393"></a>
-<span class="sourceLineNo">394</span>          }<a name="line.394"></a>
-<span class="sourceLineNo">395</span>          // Make sure we get 0-s replica.<a name="line.395"></a>
-<span class="sourceLineNo">396</span>          RegionLocations locs = connection.locateRegion(<a name="line.396"></a>
-<span class="sourceLineNo">397</span>              tableName, r.getRow(), true, true, RegionReplicaUtil.DEFAULT_REPLICA_ID);<a name="line.397"></a>
-<span class="sourceLineNo">398</span>          if (locs == null || locs.isEmpty() || locs.getDefaultRegionLocation() == null) {<a name="line.398"></a>
-<span class="sourceLineNo">399</span>            throw new IOException("#" + id + ", no location found, aborting submit for"<a name="line.399"></a>
-<span class="sourceLineNo">400</span>                + " tableName=" + tableName + " rowkey=" + Bytes.toStringBinary(r.getRow()));<a name="line.400"></a>
-<span class="sourceLineNo">401</span>          }<a name="line.401"></a>
-<span class="sourceLineNo">402</span>          loc = locs.getDefaultRegionLocation();<a name="line.402"></a>
-<span class="sourceLineNo">403</span>        } catch (IOException ex) {<a name="line.403"></a>
-<span class="sourceLineNo">404</span>          locationErrors = new ArrayList&lt;Exception&gt;();<a name="line.404"></a>
-<span class="sourceLineNo">405</span>          locationErrorRows = new ArrayList&lt;Integer&gt;();<a name="line.405"></a>
-<span class="sourceLineNo">406</span>          LOG.error("Failed to get region location ", ex);<a name="line.406"></a>
-<span class="sourceLineNo">407</span>          // This action failed before creating ars. Retain it, but do not add to submit list.<a name="line.407"></a>
-<span class="sourceLineNo">408</span>          // We will then add it to ars in an already-failed state.<a name="line.408"></a>
-<span class="sourceLineNo">409</span>          retainedActions.add(new Action&lt;Row&gt;(r, ++posInList));<a name="line.409"></a>
-<span class="sourceLineNo">410</span>          locationErrors.add(ex);<a name="line.410"></a>
-<span class="sourceLineNo">411</span>          locationErrorRows.add(posInList);<a name="line.411"></a>
-<span class="sourceLineNo">412</span>          it.remove();<a name="line.412"></a>
-<span class="sourceLineNo">413</span>          break; // Backward compat: we stop considering actions on location error.<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>        if (canTakeOperation(loc, regionIncluded, serverIncluded)) {<a name="line.416"></a>
-<span class="sourceLineNo">417</span>          Action&lt;Row&gt; action = new Action&lt;Row&gt;(r, ++posInList);<a name="line.417"></a>
-<span class="sourceLineNo">418</span>          setNonce(ng, r, action);<a name="line.418"></a>
-<span class="sourceLineNo">419</span>          retainedActions.add(action);<a name="line.419"></a>
-<span class="sourceLineNo">420</span>          // TODO: replica-get is not supported on this path<a name="line.420"></a>
-<span class="sourceLineNo">421</span>          byte[] regionName = loc.getRegionInfo().getRegionName();<a name="line.421"></a>
-<span class="sourceLineNo">422</span>          addAction(loc.getServerName(), regionName, action, actionsByServer, nonceGroup);<a name="line.422"></a>
-<span class="sourceLineNo">423</span>          it.remove();<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>    } while (retainedActions.isEmpty() &amp;&amp; atLeastOne &amp;&amp; (locationErrors == null));<a name="line.426"></a>
-<span class="sourceLineNo">427</span><a name="line.427"></a>
-<span class="sourceLineNo">428</span>    if (retainedActions.isEmpty()) return NO_REQS_RESULT;<a name="line.428"></a>
-<span class="sourceLineNo">429</span><a name="line.429"></a>
-<span class="sourceLineNo">430</span>    return submitMultiActions(tableName, retainedActions, nonceGroup, callback, null, needResults,<a name="line.430"></a>
-<span class="sourceLineNo">431</span>      locationErrors, locationErrorRows, actionsByServer, pool);<a name="line.431"></a>
-<span class="sourceLineNo">432</span>  }<a name="line.432"></a>
-<span class="sourceLineNo">433</span><a name="line.433"></a>
-<span class="sourceLineNo">434</span>  &lt;CResult&gt; AsyncRequestFuture submitMultiActions(TableName tableName,<a name="line.434"></a>
-<span class="sourceLineNo">435</span>      List&lt;Action&lt;Row&gt;&gt; retainedActions, long nonceGroup, Batch.Callback&lt;CResult&gt; callback,<a name="line.435"></a>
-<span class="sourceLineNo">436</span>      Object[] results, boolean needResults, List&lt;Exception&gt; locationErrors,<a name="line.436"></a>
-<span class="sourceLineNo">437</span>      List&lt;Integer&gt; locationErrorRows, Map&lt;ServerName, MultiAction&lt;Row&gt;&gt; actionsByServer,<a name="line.437"></a>
-<span class="sourceLineNo">438</span>      ExecutorService pool) {<a name="line.438"></a>
-<span class="sourceLineNo">439</span>    AsyncRequestFutureImpl&lt;CResult&gt; ars = createAsyncRequestFuture(<a name="line.439"></a>
-<span class="sourceLineNo">440</span>      tableName, retainedActions, nonceGroup, pool, callback, results, needResults);<a name="line.440"></a>
-<span class="sourceLineNo">441</span>    // Add location errors if any<a name="line.441"></a>
-<span class="sourceLineNo">442</span>    if (locationErrors != null) {<a name="line.442"></a>
-<span class="sourceLineNo">443</span>      for (int i = 0; i &lt; locationErrors.size(); ++i) {<a name="line.443"></a>
-<span class="sourceLineNo">444</span>        int originalIndex = locationErrorRows.get(i);<a name="line.444"></a>
-<span class="sourceLineNo">445</span>        Row row = retainedActions.get(originalIndex).getAction();<a name="line.445"></a>
-<span class="sourceLineNo">446</span>        ars.manageError(originalIndex, row,<a name="line.446"></a>
-<span class="sourceLineNo">447</span>          Retry.NO_LOCATION_PROBLEM, locationErrors.get(i), null);<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>    ars.sendMultiAction(actionsByServer, 1, null, false);<a name="line.450"></a>
-<span class="sourceLineNo">451</span>    return ars;<a name="line.451"></a>
-<span class="sourceLineNo">452</span>  }<a name="line.452"></a>
-<span class="sourceLineNo">453</span><a name="line.453"></a>
-<span class="sourceLineNo">454</span>  /**<a name="line.454"></a>
-<span class="sourceLineNo">455</span>   * Helper that is used when grouping the actions per region server.<a name="line.455"></a>
-<span class="sourceLineNo">456</span>   *<a name="line.456"></a>
-<span class="sourceLineNo">457</span>   * @param loc - the destination. Must not be null.<a name="line.457"></a>
-<span class="sourceLineNo">458</span>   * @param action - the action to add to the multiaction<a name="line.458"></a>
-<span class="sourceLineNo">459</span>   * @param actionsByServer the multiaction per server<a name="line.459"></a>
-<span class="sourceLineNo">460</span>   * @param nonceGroup Nonce group.<a name="line.460"></a>
-<span class="sourceLineNo">461</span>   */<a name="line.461"></a>
-<span class="sourceLineNo">462</span>  private static void addAction(ServerName server, byte[] regionName, Action&lt;Row&gt; action,<a name="line.462"></a>
-<span class="sourceLineNo">463</span>      Map&lt;ServerName, MultiAction&lt;Row&gt;&gt; actionsByServer, long nonceGroup) {<a name="line.463"></a>
-<span class="sourceLineNo">464</span>    MultiAction&lt;Row&gt; multiAction = actionsByServer.get(server);<a name="line.464"></a>
-<span class="sourceLineNo">465</span>    if (multiAction == null) {<a name="line.465"></a>
-<span class="sourceLineNo">466</span>      multiAction = new MultiAction&lt;Row&gt;();<a name="line.466"></a>
-<span class="sourceLineNo">467</span>      actionsByServer.put(server, multiAction);<a name="line.467"></a>
-<span class="sourceLineNo">468</span>    }<a name="line.468"></a>
-<span class="sourceLineNo">469</span>    if (action.hasNonce() &amp;&amp; !multiAction.hasNonceGroup()) {<a name="line.469"></a>
-<span class="sourceLineNo">470</span>      multiAction.setNonceGroup(nonceGroup);<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>    multiAction.add(regionName, action);<a name="line.473"></a>
-<span class="sourceLineNo">474</span>  }<a name="line.474"></a>
-<span class="sourceLineNo">475</span><a name="line.475"></a>
-<span class="sourceLineNo">476</span>  /**<a name="line.476"></a>
-<span class="sourceLineNo">477</span>   * Check if we should send new operations to this region or region server.<a name="line.477"></a>
-<span class="sourceLineNo">478</span>   * We're taking into account the past decision; if we have already accepted<a name="line.478"></a>
-<span class="sourceLineNo">479</span>   * operation on a given region, we accept all operations for this region.<a name="line.479"></a>
-<span class="sourceLineNo">480</span>   *<a name="line.480"></a>
-<span class="sourceLineNo">481</span>   * @param loc; the region and the server name we want to use.<a name="line.481"></a>
-<span class="sourceLineNo">482</span>   * @return true if this region is considered as busy.<a name="line.482"></a>
-<span class="sourceLineNo">483</span>   */<a name="line.483"></a>
-<span class="sourceLineNo">484</span>  protected boolean canTakeOperation(HRegionLocation loc,<a name="line.484"></a>
-<span class="sourceLineNo">485</span>                                     Map&lt;Long, Boolean&gt; regionsIncluded,<a name="line.485"></a>
-<span class="sourceLineNo">486</span>                                     Map&lt;ServerName, Boolean&gt; serversIncluded) {<a name="line.486"></a>
-<span class="sourceLineNo">487</span>    long regionId = loc.getRegionInfo().getRegionId();<a name="line.487"></a>
-<span class="sourceLineNo">488</span>    Boolean regionPrevious = regionsIncluded.get(regionId);<a name="line.488"></a>
-<span class="sourceLineNo">489</span><a name="line.489"></a>
-<span class="sourceLineNo">490</span>    if (regionPrevious != null) {<a name="line.490"></a>
-<span class="sourceLineNo">491</span>      // We already know what to do with this region.<a name="line.491"></a>
-<span class="sourceLineNo">492</span>      return regionPrevious;<a name="line.492"></a>
-<span class="sourceLineNo">493</span>    }<a name="line.493"></a>
-<span class="sourceLineNo">494</span><a name="line.494"></a>
-<span class="sourceLineNo">495</span>    Boolean serverPrevious = serversIncluded.get(loc.getServerName());<a name="line.495"></a>
-<span class="sourceLineNo">496</span>    if (Boolean.FALSE.equals(serverPrevious)) {<a name="line.496"></a>
-<span class="sourceLineNo">497</span>      // It's a new region, on a region server that we have already excluded.<a name="line.497"></a>
-<span class="sourceLineNo">498</span>      regionsIncluded.put(regionId, Boolean.FALSE);<a name="line.498"></a>
-<span class="sourceLineNo">499</span>      return false;<a name="line.499"></a>
-<span class="sourceLineNo">500</span>    }<a name="line.500"></a>
-<span class="sourceLineNo">501</span><a name="line.501"></a>
-<span class="sourceLineNo">502</span>    AtomicInteger regionCnt = taskCounterPerRegion.get(loc.getRegionInfo().getRegionName());<a name="line.502"></a>
-<span class="sourceLineNo">503</span>    if (regionCnt != null &amp;&amp; regionCnt.get() &gt;= maxConcurrentTasksPerRegion) {<a name="line.503"></a>
-<span class="sourceLineNo">504</span>      // Too many tasks on this region already.<a name="line.504"></a>
-<span class="sourceLineNo">505</span>      regionsIncluded.put(regionId, Boolean.FALSE);<a name="line.505"></a>
-<span class="sourceLineNo">506</span>      return false;<a name="line.506"></a>
-<span class="sourceLineNo">507</span>    }<a name="line.507"></a>
-<span class="sourceLineNo">508</span><a name="line.508"></a>
-<span class="sourceLineNo">509</span>    if (serverPrevious == null) {<a name="line.509"></a>
-<span class="sourceLineNo">510</span>      // The region is ok, but we need to decide for this region server.<a name="line.510"></a>
-<span class="sourceLineNo">511</span>      int newServers = 0; // number of servers we're going to contact so far<a name="line.511"></a>
-<span class="sourceLineNo">512</span>      for (Map.Entry&lt;ServerName, Boolean&gt; kv : serversIncluded.entrySet()) {<a name="line.512"></a>
-<span class="sourceLineNo">513</span>        if (kv.getValue()) {<a name="line.513"></a>
-<span class="sourceLineNo">514</span>          newServers++;<a name="line.514"></a>
-<span class="sourceLineNo">515</span>        }<a name="line.515"></a>
-<span class="sourceLineNo">516</span>      }<a name="line.516"></a>
-<span class="sourceLineNo">517</span><a name="line.517"></a>
-<span class="sourceLineNo">518</span>      // Do we have too many total tasks already?<a name="line.518"></a>
-<span class="sourceLineNo">519</span>      boolean ok = (newServers + tasksInProgress.get()) &lt; maxTotalConcurrentTasks;<a name="line.519"></a>
-<span class="sourceLineNo">520</span><a name="line.520"></a>
-<span class="sourceLineNo">521</span>      if (ok) {<a name="line.521"></a>
-<span class="sourceLineNo">522</span>        // If the total is fine, is it ok for this individual server?<a name="line.522"></a>
-<span class="sourceLineNo">523</span>        AtomicInteger serverCnt = taskCounterPerServer.get(loc.getServerName());<a name="line.523"></a>
-<span class="sourceLineNo">524</span>        ok = (serverCnt == null || serverCnt.get() &lt; maxConcurrentTasksPerServer);<a name="line.524"></a>
-<span class="sourceLineNo">525</span>      }<a name="line.525"></a>
-<span class="sourceLineNo">526</span><a name="line.526"></a>
-<span class="sourceLineNo">527</span>      if (!ok) {<a name="line.527"></a>
-<span class="sourceLineNo">528</span>        regionsIncluded.put(regionId, Boolean.FALSE);<a name="line.528"></a>
-<span class="sourceLineNo">529</span>        serversIncluded.put(loc.getServerName(), Boolean.FALSE);<a name="line.529"></a>
-<span class="sourceLineNo">530</span>        return false;<a name="line.530"></a>
-<span class="sourceLineNo">531</span>      }<a name="line.531"></a>
-<span class="sourceLineNo">532</span><a name="line.532"></a>
-<span class="sourceLineNo">533</span>      serversIncluded.put(loc.getServerName(), Boolean.TRUE);<a name="line.533"></a>
-<span class="sourceLineNo">534</span>    } else {<a name="line.534"></a>
-<span class="sourceLineNo">535</span>      assert serverPrevious.equals(Boolean.TRUE);<a name="line.535"></a>
-<span class="sourceLineNo">536</span>    }<a name="line.536"></a>
-<span class="sourceLineNo">537</span><a name="line.537"></a>
-<span class="sourceLineNo">538</span>    regionsIncluded.put(regionId, Boolean.TRUE);<a name="line.538"></a>
-<span class="sourceLineNo">539</span><a name="line.539"></a>
-<span class="sourceLineNo">540</span>    return true;<a name="line.540"></a>
-<span class="sourceLineNo">541</span>  }<a name="line.541"></a>
-<span class="sourceLineNo">542</span><a name="line.542"></a>
-<span class="sourceLineNo">543</span>  /**<a name="line.543"></a>
-<span class="sourceLineNo">544</span>   * See {@link #submitAll(ExecutorService, TableName, List, Batch.Callback, Object[])}.<a name="line.544"></a>
-<span class="sourceLineNo">545</span>   * Uses default ExecutorService for this AP (must have been created with one).<a name="line.545"></a>
-<span class="sourceLineNo">546</span>   */<a name="line.546"></a>
-<span class="sourceLineNo">547</span>  public &lt;CResult&gt; AsyncRequestFuture submitAll(TableName tableName,<a name="line.547"></a>
-<span class="sourceLineNo">548</span>      List&lt;? extends Row&gt; rows, Batch.Callback&lt;CResult&gt; callback, Object[] results) {<a name="line.548"></a>
-<span class="sourceLineNo">549</span>    return submitAll(null, tableName, rows, callback, results);<a name="line.549"></a>
-<span class="sourceLineNo">550</span>  }<a name="line.550"></a>
-<span class="sourceLineNo">551</span><a name="line.551"></a>
-<span class="sourceLineNo">552</span>  /**<a name="line.552"></a>
-<span class="sourceLineNo">553</span>   * Submit immediately the list of rows, whatever the server status. Kept for backward<a name="line.553"></a>
-<span class="sourceLineNo">554</span>   * compatibility: it allows to be used with the batch interface that return an array of objects.<a name="line.554"></a>
-<span class="sourceLineNo">555</span>   *<a name="line.555"></a>
-<span class="sourceLineNo">556</span>   * @param pool ExecutorService to use.<a name="line.556"></a>
-<span class="sourceLineNo">557</span>   * @param tableName name of the table for which the submission is made.<a name="line.557"></a>
-<span class="sourceLineNo">558</span>   * @param rows the list of rows.<a name="line.558"></a>
-<span class="sourceLineNo">559</span>   * @param callback the callback.<a name="line.559"></a>
-<span class="sourceLineNo">560</span>   * @param results Optional array to return the results thru; backward compat.<a name="line.560"></a>
-<span class="sourceLineNo">561</span>   */<a name="line.561"></a>
-<span class="sourceLineNo">562</span>  public &lt;CResult&gt; AsyncRequestFuture submitAll(ExecutorService pool, TableName tableName,<a name="line.562"></a>
-<span class="sourceLineNo">563</span>      List&lt;? extends Row&gt; rows, Batch.Callback&lt;CResult&gt; callback, Object[] results) {<a name="line.563"></a>
-<span class="sourceLineNo">564</span>    List&lt;Action&lt;Row&gt;&gt; actions = new ArrayList&lt;Action&lt;Row&gt;&gt;(rows.size());<a name="line.564"></a>
-<span class="sourceLineNo">565</span><a name="line.565"></a>
-<span class="sourceLineNo">566</span>    // The position will be used by the processBatch to match the object array returned.<a name="line.566"></a>
-<span class="sourceLineNo">567</span>    int posInList = -1;<a name="line.567"></a>
-<span class="sourceLineNo">568</span>    NonceGenerator ng = this.connection.getNonceGenerator();<a name="line.568"></a>
-<span class="sourceLineNo">569</span>    for (Row r : rows) {<a name="line.569"></a>
-<span class="sourceLineNo">570</span>      posInList++;<a name="line.570"></a>
-<span class="sourceLineNo">571</span>      if (r instanceof Put) {<a name="line.571"></a>
-<span class="sourceLineNo">572</span>        Put put = (Put) r;<a name="line.572"></a>
-<span class="sourceLineNo">573</span>        if (put.isEmpty()) {<a name="line.573"></a>
-<span class="sourceLineNo">574</span>          throw new IllegalArgumentException("No columns to insert for #" + (posInList+1)+ " item");<a name="line.574"></a>
-<span class="sourceLineNo">575</span>        }<a name="line.575"></a>
-<span class="sourceLineNo">576</span>      }<a name="line.576"></a>
-<span class="sourceLineNo">577</span>      Action&lt;Row&gt; action = new Action&lt;Row&gt;(r, posInList);<a name="line.577"></a>
-<span class="sourceLineNo">578</span>      setNonce(ng, r, action);<a name="line.578"></a>
-<span class="sourceLineNo">579</span>      actions.add(action);<a name="line.579"></a>
-<span class="sourceLineNo">580</span>    }<a name="line.580"></a>
-<span class="sourceLineNo">581</span>    AsyncRequestFutureImpl&lt;CResult&gt; ars = createAsyncRequestFuture(<a name="line.581"></a>
-<span class="sourceLineNo">582</span>        tableName, actions, ng.getNonceGroup(), getPool(pool), callback, results, results != null);<a name="line.582"></a>
-<span class="sourceLineNo">583</span>    ars.groupAndSendMultiAction(actions, 1);<a name="line.583"></a>
-<span class="sourceLineNo">584</span>    return ars;<a name="line.584"></a>
-<span class="sourceLineNo">585</span>  }<a name="line.585"></a>
-<span class="sourceLineNo">586</span><a name="line.586"></a>
-<span class="sourceLineNo">587</span>  private static void setNonce(NonceGenerator ng, Row r, Action&lt;Row&gt; action) {<a name="line.587"></a>
-<span class="sourceLineNo">588</span>    if (!(r instanceof Append) &amp;&amp; !(r instanceof Increment)) return;<a name="line.588"></a>
-<span class="sourceLineNo">589</span>    action.setNonce(ng.newNonce()); // Action handles NO_NONCE, so it's ok if ng is disabled.<a name="line.589"></a>
-<span class="sourceLineNo">590</span>  }<a name="line.590"></a>
-<span class="sourceLineNo">591</span><a name="line.591"></a>
-<span class="sourceLineNo">592</span>  /**<a name="line.592"></a>
-<span class="sourceLineNo">593</span>   * The context, and return value, for a single submit/submitAll call.<a name="line.593"></a>
-<span class="sourceLineNo">594</span>   * Note on how this class (one AP submit) works. Initially, all requests are split into groups<a name="line.594"></a>
-<span class="sourceLineNo">595</span>   * by server; request is sent to each server in parallel; the RPC calls are not async so a<a name="line.595"></a>
-<span class="sourceLineNo">596</span>   * thread per server is used. Every time some actions fail, regions/locations might have<a name="line.596"></a>
-<span class="sourceLineNo">597</span>   * changed, so we re-group them by server and region again and send these groups in parallel<a name="line.597"></a>
-<span class="sourceLineNo">598</span>   * too. The result, in case of retries, is a "tree" of threads, with parent exiting after<a name="line.598"></a>
-<span class="sourceLineNo">599</span>   * scheduling children. This is why lots of code doesn't require any synchronization.<a name="line.599"></a>
-<span class="sourceLineNo">600</span>   */<a name="line.600"></a>
-<span class="sourceLineNo">601</span>  protected class AsyncRequestFutureImpl&lt;CResult&gt; implements AsyncRequestFuture {<a name="line.601"></a>
-<span class="sourceLineNo">602</span><a name="line.602"></a>
-<span class="sourceLineNo">603</span>    /**<a name="line.603"></a>
-<span class="sourceLineNo">604</span>     * Runnable (that can be submitted to thread pool) that waits for when it's time<a name="line.604"></a>
-<span class="sourceLineNo">605</span>     * to issue replica calls, finds region replicas, groups the requests by replica and<a name="line.605"></a>
-<span class="sourceLineNo">606</span>     * issues the calls (on separate threads, via sendMultiAction).<a name="line.606"></a>
-<span class="sourceLineNo">607</span>     * This is done on a separate thread because we don't want to wait on user thread for<a name="line.607"></a>
-<span class="sourceLineNo">608</span>     * our asynchronous call, and usually we have to wait before making replica calls.<a name="line.608"></a>
-<span class="sourceLineNo">609</span>     */<a name="line.609"></a>
-<span class="sourceLineNo">610</span>    private final class ReplicaCallIssuingRunnable implements Runnable {<a name="line.610"></a>
-<span class="sourceLineNo">611</span>      private final long startTime;<a name="line.611"></a>
-<span class="sourceLineNo">612</span>      private final List&lt;Action&lt;Row&gt;&gt; initialActions;<a name="line.612"></a>
-<span class="sourceLineNo">613</span><a name="line.613"></a>
-<span class="sourceLineNo">614</span>      public ReplicaCallIssuingRunnable(List&lt;Action&lt;Row&gt;&gt; initialActions, long startTime) {<a name="line.614"></a>
-<span class="sourceLineNo">615</span>        this.initialActions = initialActions;<a name="line.615"></a>
-<span class="sourceLineNo">616</span>        this.startTime = startTime;<a name="line.616"></a>
-<span class="sourceLineNo">617</span>      }<a name="line.617"></a>
-<span class="sourceLineNo">618</span><a name="line.618"></a>
-<span class="sourceLineNo">619</span>      @Override<a name="line.619"></a>
-<span class="sourceLineNo">620</span>      public void run() {<a name="line.620"></a>
-<span class="sourceLineNo">621</span>        boolean done = false;<a name="line.621"></a>
-<span class="sourceLineNo">622</span>        if (primaryCallTimeoutMicroseconds &gt; 0) {<a name="line.622"></a>
-<span class="sourceLineNo">623</span>          try {<a name="line.623"></a>
-<span class="sourceLineNo">624</span>            done = waitUntilDone(startTime * 1000L + primaryCallTimeoutMicroseconds);<a name="line.624"></a>
-<span class="sourceLineNo">625</span>          } catch (InterruptedException ex) {<a name="line.625"></a>
-<span class="sourceLineNo">626</span>            LOG.error("Replica thread was interrupted - no replica calls: " + ex.getMessage());<a name="line.626"></a>
-<span class="sourceLineNo">627</span>            return;<a name="line.627"></a>
-<span class="sourceLineNo">628</span>          }<a name="line.628"></a>
-<span class="sourceLineNo">629</span>        }<a name="line.629"></a>
-<span class="sourceLineNo">630</span>        if (done) return; // Done within primary timeout<a name="line.630"></a>
-<span class="sourceLineNo">631</span>        Map&lt;ServerName, MultiAction&lt;Row&gt;&gt; actionsByServer =<a name="line.631"></a>
-<span class="sourceLineNo">632</span>            new HashMap&lt;ServerName, MultiAction&lt;Row&gt;&gt;();<a name="line.632"></a>
-<span class="sourceLineNo">633</span>        List&lt;Action&lt;Row&gt;&gt; unknownLocActions = new ArrayList&lt;Action&lt;Row&gt;&gt;();<a name="line.633"></a>
-<span class="sourceLineNo">634</span>        if (replicaGetIndices == null) {<a name="line.634"></a>
-<span class="sourceLineNo">635</span>          for (int i = 0; i &lt; results.length; ++i) {<a name="line.635"></a>
-<span class="sourceLineNo">636</span>            addReplicaActions(i, actionsByServer, unknownLocActions);<a name="line.636"></a>
-<span class="sourceLineNo">637</span>          }<a name="line.637"></a>
-<span class="sourceLineNo">638</span>        } else {<a name="line.638"></a>
-<span class="sourceLineNo">639</span>          for (int replicaGetIndice : replicaGetIndices) {<a name="line.639"></a>
-<span class="sourceLineNo">640</span>            addReplicaActions(replicaGetIndice, actionsByServer, unknownLocActions);<a name="line.640"></a>
-<span class="sourceLineNo">641</span>          }<a name="line.641"></a>
-<span class="sourceLineNo">642</span>        }<a name="line.642"></a>
-<span class="sourceLineNo">643</span>        if (!actionsByServer.isEmpty()) {<a name="line.643"></a>
-<span class="sourceLineNo">644</span>          sendMultiAction(actionsByServer, 1, null, unknownLocActions.isEmpty());<a name="line.644"></a>
-<span class="sourceLineNo">645</span>        }<a name="line.645"></a>
-<span class="sourceLineNo">646</span>        if (!unknownLocActions.isEmpty()) {<a name="line.646"></a>
-<span class="sourceLineNo">647</span>          actionsByServer = new HashMap&lt;ServerName, MultiAction&lt;Row&gt;&gt;();<a name="line.647"></a>
-<span class="sourceLineNo">648</span>          for (Action&lt;Row&gt; action : unknownLocActions) {<a name="line.648"></a>
-<span class="sourceLineNo">649</span>            addReplicaActionsAgain(action, actionsByServer);<a name="line.649"></a>
-<span class="sourceLineNo">650</span>          }<a name="line.650"></a>
-<span class="sourceLineNo">651</span>          // Some actions may have completely failed, they are handled inside addAgain.<a name="line.651"></a>
-<span class="sourceLineNo">652</span>          if (!actionsByServer.isEmpty()) {<a name="line.652"></a>
-<span class="sourceLineNo">653</span>            sendMultiAction(actionsByServer, 1, null, true);<a name="line.653"></a>
-<span class="sourceLineNo">654</span>          }<a name="line.654"></a>
-<span class="sourceLineNo">655</span>        }<a name="line.655"></a>
-<span class="sourceLineNo">656</span>      }<a name="line.656"></a>
-<span class="sourceLineNo">657</span><a name="line.657"></a>
-<span class="sourceLineNo">658</span>      /**<a name="line.658"></a>
-<span class="sourceLineNo">659</span>       * Add replica actions to action map by server.<a name="line.659"></a>
-<span class="sourceLineNo">660</span>       * @param index Index of the original action.<a name="line.660"></a>
-<span class="sourceLineNo">661</span>       * @param actionsByServer The map by server to add it to.<a name="line.661"></a>
-<span class="sourceLineNo">662</span>       */<a name="line.662"></a>
-<span class="sourceLineNo">663</span>      private void addReplicaActions(int index, Map&lt;ServerName, MultiAction&lt;Row&gt;&gt; actionsByServer,<a name="line.663"></a>
-<span class="sourceLineNo">664</span>          List&lt;Action&lt;Row&gt;&gt; unknownReplicaActions) {<a name="line.664"></a>
-<span class="sourceLineNo">665</span>        if (results[index] != null) return; // opportunistic. Never goes from non-null to null.<a name="line.665"></a>
-<span class="sourceLineNo">666</span>        Action&lt;Row&gt; action = initialActions.get(index);<a name="line.666"></a>
-<span class="sourceLineNo">667</span>        RegionLocations loc = findAllLocationsOrFail(action, true);<a name="line.667"></a>
-<span class="sourceLineNo">668</span>        if (loc == null) return;<a name="line.668"></a>
-<span class="sourceLineNo">669</span>        HRegionLocation[] locs = loc.getRegionLocations();<a name="line.669"></a>
-<span class="sourceLineNo">670</span>        if (locs.length == 1) {<a name="line.670"></a>
-<span class="sourceLineNo">671</span>          LOG.warn("No replicas found for " + action.getAction());<a name="line.671"></a>
-<span class="sourceLineNo">672</span>          return;<a name="line.672"></a>
-<span class="sourceLineNo">673</span>        }<a name="line.673"></a>
-<span class="sourceLineNo">674</span>        synchronized (replicaResultLock) {<a name="line.674"></a>
-<span class="sourceLineNo">675</span>          // Don't run replica calls if the original has finished. We could do it e.g. if<a name="line.675"></a>
-<span class="sourceLineNo">676</span>          // original has already failed before first replica call (unlikely given retries),<a name="line.676"></a>
-<span class="sourceLineNo">677</span>          // but that would require additional synchronization w.r.t. returning to caller.<a name="line.677"></a>
-<span class="sourceLineNo">678</span>          if (results[index] != null) return;<a name="line.678"></a>
-<span class="sourceLineNo">679</span>          // We set the number of calls here. After that any path must call setResult/setError.<a name="line.679"></a>
-<span class="sourceLineNo">680</span>          // True even for replicas that are not found - if we refuse to send we MUST set error.<a name="line.680"></a>
-<span class="sourceLineNo">681</span>          results[index] = new ReplicaResultState(locs.length);<a name="line.681"></a>
-<span class="sourceLineNo">682</span>        }<a name="line.682"></a>
-<span class="sourceLineNo">683</span>        for (int i = 1; i &lt; locs.length; ++i) {<a name="line.683"></a>
-<span class="sourceLineNo">684</span>          Action&lt;Row&gt; replicaAction = new Action&lt;Row&gt;(action, i);<a name="line.684"></a>
-<span class="sourceLineNo">685</span>          if (locs[i] != null) {<a name="line.685"></a>
-<span class="sourceLineNo">686</span>            addAction(locs[i].getServerName(), locs[i].getRegionInfo().getRegionName(),<a name="line.686"></a>
-<span class="sourceLineNo">687</span>                replicaAction, actionsByServer, nonceGroup);<a name="line.687"></a>
-<span class="sourceLineNo">688</span>          } else {<a name="line.688"></a>
-<span class="sourceLineNo">689</span>            unknownReplicaActions.add(replicaAction);<a name="line.689"></a>
-<span class="sourceLineNo">690</span>          }<a name="line.690"></a>
-<span class="sourceLineNo">691</span>        }<a name="line.691"></a>
-<span class="sourceLineNo">692</span>      }<a name="line.692"></a>
-<span class="sourceLineNo">693</span><a name="line.693"></a>
-<span class="sourceLineNo">694</span>      private void addReplicaActionsAgain(<a name="line.694"></a>
-<span class="sourceLineNo">695</span>          Action&lt;Row&gt; action, Map&lt;ServerName, MultiAction&lt;Row&gt;&gt; actionsByServer) {<a name="line.695"></a>
-<span class="sourceLineNo">696</span>        if (action.getReplicaId() == RegionReplicaUtil.DEFAULT_REPLICA_ID) {<a name="line.696"></a>
-<span class="sourceLineNo">697</span>          throw new AssertionError("Cannot have default replica here");<a name="line.697"></a>
+<span class="sourceLineNo">184</span><a name="line.184"></a>
+<span class="sourceLineNo">185</span>  // TODO: many of the fields should be made private<a name="line.185"></a>
+<span class="sourceLineNo">186</span>  protected final long id;<a name="line.186"></a>
+<span class="sourceLineNo">187</span><a name="line.187"></a>
+<span class="sourceLineNo">188</span>  protected final ClusterConnection connection;<a name="line.188"></a>
+<span class="sourceLineNo">189</span>  protected final RpcRetryingCallerFactory rpcCallerFactory;<a name="line.189"></a>
+<span class="sourceLineNo">190</span>  protected final RpcControllerFactory rpcFactory;<a name="line.190"></a>
+<span class="sourceLineNo">191</span>  protected final BatchErrors globalErrors;<a name="line.191"></a>
+<span class="sourceLineNo">192</span>  protected final ExecutorService pool;<a name="line.192"></a>
+<span class="sourceLineNo">193</span><a name="line.193"></a>
+<span class="sourceLineNo">194</span>  protected final AtomicLong tasksInProgress = new AtomicLong(0);<a name="line.194"></a>
+<span class="sourceLineNo">195</span>  protected final ConcurrentMap&lt;byte[], AtomicInteger&gt; taskCounterPerRegion =<a name="line.195"></a>
+<span class="sourceLineNo">196</span>      new ConcurrentSkipListMap&lt;byte[], AtomicInteger&gt;(Bytes.BYTES_COMPARATOR);<a name="line.196"></a>
+<span class="sourceLineNo">197</span>  protected final ConcurrentMap&lt;ServerName, AtomicInteger&gt; taskCounterPerServer =<a name="line.197"></a>
+<span class="sourceLineNo">198</span>      new ConcurrentHashMap&lt;ServerName, AtomicInteger&gt;();<a name="line.198"></a>
+<span class="sourceLineNo">199</span><a name="line.199"></a>
+<span class="sourceLineNo">200</span>  // Start configuration settings.<a name="line.200"></a>
+<span class="sourceLineNo">201</span>  private final int startLogErrorsCnt;<a name="line.201"></a>
+<span class="sourceLineNo">202</span><a name="line.202"></a>
+<span class="sourceLineNo">203</span>  /**<a name="line.203"></a>
+<span class="sourceLineNo">204</span>   * The number of tasks simultaneously executed on the cluster.<a name="line.204"></a>
+<span class="sourceLineNo">205</span>   */<a name="line.205"></a>
+<span class="sourceLineNo">206</span>  protected final int maxTotalConcurrentTasks;<a name="line.206"></a>
+<span class="sourceLineNo">207</span><a name="line.207"></a>
+<span class="sourceLineNo">208</span>  /**<a name="line.208"></a>
+<span class="sourceLineNo">209</span>   * The number of tasks we run in parallel on a single region.<a name="line.209"></a>
+<span class="sourceLineNo">210</span>   * With 1 (the default) , we ensure that the ordering of the queries is respected: we don't start<a name="line.210"></a>
+<span class="sourceLineNo">211</span>   * a set of operations on a region before the previous one is done. As well, this limits<a name="line.211"></a>
+<span class="sourceLineNo">212</span>   * the pressure we put on the region server.<a name="line.212"></a>
+<span class="sourceLineNo">213</span>   */<a name="line.213"></a>
+<span class="sourceLineNo">214</span>  protected final int maxConcurrentTasksPerRegion;<a name="line.214"></a>
+<span class="sourceLineNo">215</span><a name="line.215"></a>
+<span class="sourceLineNo">216</span>  /**<a name="line.216"></a>
+<span class="sourceLineNo">217</span>   * The number of task simultaneously executed on a single region server.<a name="line.217"></a>
+<span class="sourceLineNo">218</span>   */<a name="line.218"></a>
+<span class="sourceLineNo">219</span>  protected final int maxConcurrentTasksPerServer;<a name="line.219"></a>
+<span class="sourceLineNo">220</span>  protected final long pause;<a name="line.220"></a>
+<span class="sourceLineNo">221</span>  protected int numTries;<a name="line.221"></a>
+<span class="sourceLineNo">222</span>  protected int serverTrackerTimeout;<a name="line.222"></a>
+<span class="sourceLineNo">223</span>  protected int timeout;<a name="line.223"></a>
+<span class="sourceLineNo">224</span>  protected long primaryCallTimeoutMicroseconds;<a name="line.224"></a>
+<span class="sourceLineNo">225</span>  // End configuration settings.<a name="line.225"></a>
+<span class="sourceLineNo">226</span><a name="line.226"></a>
+<span class="sourceLineNo">227</span>  protected static class BatchErrors {<a name="line.227"></a>
+<span class="sourceLineNo">228</span>    private final List&lt;Throwable&gt; throwables = new ArrayList&lt;Throwable&gt;();<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    private final List&lt;Row&gt; actions = new ArrayList&lt;Row&gt;();<a name="line.229"></a>
+<span class="sourceLineNo">230</span>    private final List&lt;String&gt; addresses = new ArrayList&lt;String&gt;();<a name="line.230"></a>
+<span class="sourceLineNo">231</span><a name="line.231"></a>
+<span class="sourceLineNo">232</span>    public synchronized void add(Throwable ex, Row row, ServerName serverName) {<a name="line.232"></a>
+<span class="sourceLineNo">233</span>      if (row == null){<a name="line.233"></a>
+<span class="sourceLineNo">234</span>        throw new IllegalArgumentException("row cannot be null. location=" + serverName);<a name="line.234"></a>
+<span class="sourceLineNo">235</span>      }<a name="line.235"></a>
+<span class="sourceLineNo">236</span><a name="line.236"></a>
+<span class="sourceLineNo">237</span>      throwables.add(ex);<a name="line.237"></a>
+<span class="sourceLineNo">238</span>      actions.add(row);<a name="line.238"></a>
+<span class="sourceLineNo">239</span>      addresses.add(serverName != null ? serverName.toString() : "null");<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>    public boolean hasErrors() {<a name="line.242"></a>
+<span class="sourceLineNo">243</span>      return !throwables.isEmpty();<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    }<a name="line.244"></a>
+<span class="sourceLineNo">245</span><a name="line.245"></a>
+<span class="sourceLineNo">246</span>    private synchronized RetriesExhaustedWithDetailsException makeException() {<a name="line.246"></a>
+<span class="sourceLineNo">247</span>      return new RetriesExhaustedWithDetailsException(<a name="line.247"></a>
+<span class="sourceLineNo">248</span>          new ArrayList&lt;Throwable&gt;(throwables),<a name="line.248"></a>
+<span class="sourceLineNo">249</span>          new ArrayList&lt;Row&gt;(actions), new ArrayList&lt;String&gt;(addresses));<a name="line.249"></a>
+<span class="sourceLineNo">250</span>    }<a name="line.250"></a>
+<span class="sourceLineNo">251</span><a name="line.251"></a>
+<span class="sourceLineNo">252</span>    public synchronized void clear() {<a name="line.252"></a>
+<span class="sourceLineNo">253</span>      throwables.clear();<a name="line.253"></a>
+<span class="sourceLineNo">254</span>      actions.clear();<a name="line.254"></a>
+<span class="sourceLineNo">255</span>      addresses.clear();<a name="line.255"></a>
+<span class="sourceLineNo">256</span>    }<a name="line.256"></a>
+<span class="sourceLineNo">257</span><a name="line.257"></a>
+<span class="sourceLineNo">258</span>    public synchronized void merge(BatchErrors other) {<a name="line.258"></a>
+<span class="sourceLineNo">259</span>      throwables.addAll(other.throwables);<a name="line.259"></a>
+<span class="sourceLineNo">260</span>      actions.addAll(other.actions);<a name="line.260"></a>
+<span class="sourceLineNo">261</span>      addresses.addAll(other.addresses);<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><a name="line.264"></a>
+<span class="sourceLineNo">265</span>  public AsyncProcess(ClusterConnection hc, Configuration conf, ExecutorService pool,<a name="line.265"></a>
+<span class="sourceLineNo">266</span>      RpcRetryingCallerFactory rpcCaller, boolean useGlobalErrors,<a name="line.266"></a>
+<span class="sourceLineNo">267</span>      RpcControllerFactory rpcFa

<TRUNCATED>

Mime
View raw message