hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [23/51] [partial] hbase-site git commit: Published site at .
Date Wed, 11 Oct 2017 15:13:28 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/c0571676/devapidocs/src-html/org/apache/hadoop/hbase/procedure/flush/RegionServerFlushTableProcedureManager.FlushTableSubprocedurePool.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/procedure/flush/RegionServerFlushTableProcedureManager.FlushTableSubprocedurePool.html b/devapidocs/src-html/org/apache/hadoop/hbase/procedure/flush/RegionServerFlushTableProcedureManager.FlushTableSubprocedurePool.html
index 9bbfc18..d22fccc 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/procedure/flush/RegionServerFlushTableProcedureManager.FlushTableSubprocedurePool.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/procedure/flush/RegionServerFlushTableProcedureManager.FlushTableSubprocedurePool.html
@@ -54,299 +54,300 @@
 <span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.procedure.Subprocedure;<a name="line.46"></a>
 <span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.procedure.SubprocedureFactory;<a name="line.47"></a>
 <span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.procedure.ZKProcedureMemberRpcs;<a name="line.48"></a>
-<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.regionserver.HRegionServer;<a name="line.49"></a>
-<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.regionserver.Region;<a name="line.50"></a>
-<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.regionserver.RegionServerServices;<a name="line.51"></a>
-<span class="sourceLineNo">052</span>import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;<a name="line.52"></a>
-<span class="sourceLineNo">053</span>import org.apache.zookeeper.KeeperException;<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> * This manager class handles flushing of the regions for table on a {@link HRegionServer}.<a name="line.56"></a>
-<span class="sourceLineNo">057</span> */<a name="line.57"></a>
-<span class="sourceLineNo">058</span>@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)<a name="line.58"></a>
-<span class="sourceLineNo">059</span>public class RegionServerFlushTableProcedureManager extends RegionServerProcedureManager {<a name="line.59"></a>
-<span class="sourceLineNo">060</span>  private static final Log LOG = LogFactory.getLog(RegionServerFlushTableProcedureManager.class);<a name="line.60"></a>
-<span class="sourceLineNo">061</span><a name="line.61"></a>
-<span class="sourceLineNo">062</span>  private static final String CONCURENT_FLUSH_TASKS_KEY =<a name="line.62"></a>
-<span class="sourceLineNo">063</span>      "hbase.flush.procedure.region.concurrentTasks";<a name="line.63"></a>
-<span class="sourceLineNo">064</span>  private static final int DEFAULT_CONCURRENT_FLUSH_TASKS = 3;<a name="line.64"></a>
-<span class="sourceLineNo">065</span><a name="line.65"></a>
-<span class="sourceLineNo">066</span>  public static final String FLUSH_REQUEST_THREADS_KEY =<a name="line.66"></a>
-<span class="sourceLineNo">067</span>      "hbase.flush.procedure.region.pool.threads";<a name="line.67"></a>
-<span class="sourceLineNo">068</span>  public static final int FLUSH_REQUEST_THREADS_DEFAULT = 10;<a name="line.68"></a>
-<span class="sourceLineNo">069</span><a name="line.69"></a>
-<span class="sourceLineNo">070</span>  public static final String FLUSH_TIMEOUT_MILLIS_KEY =<a name="line.70"></a>
-<span class="sourceLineNo">071</span>      "hbase.flush.procedure.region.timeout";<a name="line.71"></a>
-<span class="sourceLineNo">072</span>  public static final long FLUSH_TIMEOUT_MILLIS_DEFAULT = 60000;<a name="line.72"></a>
-<span class="sourceLineNo">073</span><a name="line.73"></a>
-<span class="sourceLineNo">074</span>  public static final String FLUSH_REQUEST_WAKE_MILLIS_KEY =<a name="line.74"></a>
-<span class="sourceLineNo">075</span>      "hbase.flush.procedure.region.wakefrequency";<a name="line.75"></a>
-<span class="sourceLineNo">076</span>  private static final long FLUSH_REQUEST_WAKE_MILLIS_DEFAULT = 500;<a name="line.76"></a>
-<span class="sourceLineNo">077</span><a name="line.77"></a>
-<span class="sourceLineNo">078</span>  private RegionServerServices rss;<a name="line.78"></a>
-<span class="sourceLineNo">079</span>  private ProcedureMemberRpcs memberRpcs;<a name="line.79"></a>
-<span class="sourceLineNo">080</span>  private ProcedureMember member;<a name="line.80"></a>
-<span class="sourceLineNo">081</span><a name="line.81"></a>
-<span class="sourceLineNo">082</span>  /**<a name="line.82"></a>
-<span class="sourceLineNo">083</span>   * Exposed for testing.<a name="line.83"></a>
-<span class="sourceLineNo">084</span>   * @param conf HBase configuration.<a name="line.84"></a>
-<span class="sourceLineNo">085</span>   * @param server region server.<a name="line.85"></a>
-<span class="sourceLineNo">086</span>   * @param memberRpc use specified memberRpc instance<a name="line.86"></a>
-<span class="sourceLineNo">087</span>   * @param procMember use specified ProcedureMember<a name="line.87"></a>
-<span class="sourceLineNo">088</span>   */<a name="line.88"></a>
-<span class="sourceLineNo">089</span>   RegionServerFlushTableProcedureManager(Configuration conf, HRegionServer server,<a name="line.89"></a>
-<span class="sourceLineNo">090</span>      ProcedureMemberRpcs memberRpc, ProcedureMember procMember) {<a name="line.90"></a>
-<span class="sourceLineNo">091</span>    this.rss = server;<a name="line.91"></a>
-<span class="sourceLineNo">092</span>    this.memberRpcs = memberRpc;<a name="line.92"></a>
-<span class="sourceLineNo">093</span>    this.member = procMember;<a name="line.93"></a>
-<span class="sourceLineNo">094</span>  }<a name="line.94"></a>
-<span class="sourceLineNo">095</span><a name="line.95"></a>
-<span class="sourceLineNo">096</span>  public RegionServerFlushTableProcedureManager() {}<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>   * Start accepting flush table requests.<a name="line.99"></a>
-<span class="sourceLineNo">100</span>   */<a name="line.100"></a>
-<span class="sourceLineNo">101</span>  @Override<a name="line.101"></a>
-<span class="sourceLineNo">102</span>  public void start() {<a name="line.102"></a>
-<span class="sourceLineNo">103</span>    LOG.debug("Start region server flush procedure manager " + rss.getServerName().toString());<a name="line.103"></a>
-<span class="sourceLineNo">104</span>    this.memberRpcs.start(rss.getServerName().toString(), member);<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>  /**<a name="line.107"></a>
-<span class="sourceLineNo">108</span>   * Close &lt;tt&gt;this&lt;/tt&gt; and all running tasks<a name="line.108"></a>
-<span class="sourceLineNo">109</span>   * @param force forcefully stop all running tasks<a name="line.109"></a>
-<span class="sourceLineNo">110</span>   * @throws IOException<a name="line.110"></a>
-<span class="sourceLineNo">111</span>   */<a name="line.111"></a>
-<span class="sourceLineNo">112</span>  @Override<a name="line.112"></a>
-<span class="sourceLineNo">113</span>  public void stop(boolean force) throws IOException {<a name="line.113"></a>
-<span class="sourceLineNo">114</span>    String mode = force ? "abruptly" : "gracefully";<a name="line.114"></a>
-<span class="sourceLineNo">115</span>    LOG.info("Stopping region server flush procedure manager " + mode + ".");<a name="line.115"></a>
-<span class="sourceLineNo">116</span><a name="line.116"></a>
-<span class="sourceLineNo">117</span>    try {<a name="line.117"></a>
-<span class="sourceLineNo">118</span>      this.member.close();<a name="line.118"></a>
-<span class="sourceLineNo">119</span>    } finally {<a name="line.119"></a>
-<span class="sourceLineNo">120</span>      this.memberRpcs.close();<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><a name="line.123"></a>
-<span class="sourceLineNo">124</span>  /**<a name="line.124"></a>
-<span class="sourceLineNo">125</span>   * If in a running state, creates the specified subprocedure to flush table regions.<a name="line.125"></a>
-<span class="sourceLineNo">126</span>   *<a name="line.126"></a>
-<span class="sourceLineNo">127</span>   * Because this gets the local list of regions to flush and not the set the master had,<a name="line.127"></a>
-<span class="sourceLineNo">128</span>   * there is a possibility of a race where regions may be missed.<a name="line.128"></a>
-<span class="sourceLineNo">129</span>   *<a name="line.129"></a>
-<span class="sourceLineNo">130</span>   * @param table<a name="line.130"></a>
-<span class="sourceLineNo">131</span>   * @return Subprocedure to submit to the ProcedureMemeber.<a name="line.131"></a>
-<span class="sourceLineNo">132</span>   */<a name="line.132"></a>
-<span class="sourceLineNo">133</span>  public Subprocedure buildSubprocedure(String table) {<a name="line.133"></a>
-<span class="sourceLineNo">134</span><a name="line.134"></a>
-<span class="sourceLineNo">135</span>    // don't run the subprocedure if the parent is stop(ping)<a name="line.135"></a>
-<span class="sourceLineNo">136</span>    if (rss.isStopping() || rss.isStopped()) {<a name="line.136"></a>
-<span class="sourceLineNo">137</span>      throw new IllegalStateException("Can't start flush region subprocedure on RS: "<a name="line.137"></a>
-<span class="sourceLineNo">138</span>          + rss.getServerName() + ", because stopping/stopped!");<a name="line.138"></a>
-<span class="sourceLineNo">139</span>    }<a name="line.139"></a>
-<span class="sourceLineNo">140</span><a name="line.140"></a>
-<span class="sourceLineNo">141</span>    // check to see if this server is hosting any regions for the table<a name="line.141"></a>
-<span class="sourceLineNo">142</span>    List&lt;Region&gt; involvedRegions;<a name="line.142"></a>
-<span class="sourceLineNo">143</span>    try {<a name="line.143"></a>
-<span class="sourceLineNo">144</span>      involvedRegions = getRegionsToFlush(table);<a name="line.144"></a>
-<span class="sourceLineNo">145</span>    } catch (IOException e1) {<a name="line.145"></a>
-<span class="sourceLineNo">146</span>      throw new IllegalStateException("Failed to figure out if there is region to flush.", e1);<a name="line.146"></a>
-<span class="sourceLineNo">147</span>    }<a name="line.147"></a>
-<span class="sourceLineNo">148</span><a name="line.148"></a>
-<span class="sourceLineNo">149</span>    // We need to run the subprocedure even if we have no relevant regions.  The coordinator<a name="line.149"></a>
-<span class="sourceLineNo">150</span>    // expects participation in the procedure and without sending message the master procedure<a name="line.150"></a>
-<span class="sourceLineNo">151</span>    // will hang and fail.<a name="line.151"></a>
-<span class="sourceLineNo">152</span><a name="line.152"></a>
-<span class="sourceLineNo">153</span>    LOG.debug("Launching subprocedure to flush regions for " + table);<a name="line.153"></a>
-<span class="sourceLineNo">154</span>    ForeignExceptionDispatcher exnDispatcher = new ForeignExceptionDispatcher(table);<a name="line.154"></a>
-<span class="sourceLineNo">155</span>    Configuration conf = rss.getConfiguration();<a name="line.155"></a>
-<span class="sourceLineNo">156</span>    long timeoutMillis = conf.getLong(FLUSH_TIMEOUT_MILLIS_KEY,<a name="line.156"></a>
-<span class="sourceLineNo">157</span>        FLUSH_TIMEOUT_MILLIS_DEFAULT);<a name="line.157"></a>
-<span class="sourceLineNo">158</span>    long wakeMillis = conf.getLong(FLUSH_REQUEST_WAKE_MILLIS_KEY,<a name="line.158"></a>
-<span class="sourceLineNo">159</span>        FLUSH_REQUEST_WAKE_MILLIS_DEFAULT);<a name="line.159"></a>
-<span class="sourceLineNo">160</span><a name="line.160"></a>
-<span class="sourceLineNo">161</span>    FlushTableSubprocedurePool taskManager =<a name="line.161"></a>
-<span class="sourceLineNo">162</span>        new FlushTableSubprocedurePool(rss.getServerName().toString(), conf, rss);<a name="line.162"></a>
-<span class="sourceLineNo">163</span>    return new FlushTableSubprocedure(member, exnDispatcher, wakeMillis,<a name="line.163"></a>
-<span class="sourceLineNo">164</span>      timeoutMillis, involvedRegions, table, taskManager);<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>   * Get the list of regions to flush for the table on this server<a name="line.168"></a>
-<span class="sourceLineNo">169</span>   *<a name="line.169"></a>
-<span class="sourceLineNo">170</span>   * It is possible that if a region moves somewhere between the calls<a name="line.170"></a>
-<span class="sourceLineNo">171</span>   * we'll miss the region.<a name="line.171"></a>
-<span class="sourceLineNo">172</span>   *<a name="line.172"></a>
-<span class="sourceLineNo">173</span>   * @param table<a name="line.173"></a>
-<span class="sourceLineNo">174</span>   * @return the list of online regions. Empty list is returned if no regions.<a name="line.174"></a>
-<span class="sourceLineNo">175</span>   * @throws IOException<a name="line.175"></a>
-<span class="sourceLineNo">176</span>   */<a name="line.176"></a>
-<span class="sourceLineNo">177</span>  private List&lt;Region&gt; getRegionsToFlush(String table) throws IOException {<a name="line.177"></a>
-<span class="sourceLineNo">178</span>    return rss.getRegions(TableName.valueOf(table));<a name="line.178"></a>
-<span class="sourceLineNo">179</span>  }<a name="line.179"></a>
-<span class="sourceLineNo">180</span><a name="line.180"></a>
-<span class="sourceLineNo">181</span>  public class FlushTableSubprocedureBuilder implements SubprocedureFactory {<a name="line.181"></a>
-<span class="sourceLineNo">182</span><a name="line.182"></a>
-<span class="sourceLineNo">183</span>    @Override<a name="line.183"></a>
-<span class="sourceLineNo">184</span>    public Subprocedure buildSubprocedure(String name, byte[] data) {<a name="line.184"></a>
-<span class="sourceLineNo">185</span>      // The name of the procedure instance from the master is the table name.<a name="line.185"></a>
-<span class="sourceLineNo">186</span>      return RegionServerFlushTableProcedureManager.this.buildSubprocedure(name);<a name="line.186"></a>
-<span class="sourceLineNo">187</span>    }<a name="line.187"></a>
-<span class="sourceLineNo">188</span><a name="line.188"></a>
-<span class="sourceLineNo">189</span>  }<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>   * We use the FlushTableSubprocedurePool, a class specific thread pool instead of<a name="line.192"></a>
-<span class="sourceLineNo">193</span>   * {@link org.apache.hadoop.hbase.executor.ExecutorService}.<a name="line.193"></a>
-<span class="sourceLineNo">194</span>   *<a name="line.194"></a>
-<span class="sourceLineNo">195</span>   * It uses a {@link java.util.concurrent.ExecutorCompletionService} which provides queuing of<a name="line.195"></a>
-<span class="sourceLineNo">196</span>   * completed tasks which lets us efficiently cancel pending tasks upon the earliest operation<a name="line.196"></a>
-<span class="sourceLineNo">197</span>   * failures.<a name="line.197"></a>
-<span class="sourceLineNo">198</span>   */<a name="line.198"></a>
-<span class="sourceLineNo">199</span>  static class FlushTableSubprocedurePool {<a name="line.199"></a>
-<span class="sourceLineNo">200</span>    private final Abortable abortable;<a name="line.200"></a>
-<span class="sourceLineNo">201</span>    private final ExecutorCompletionService&lt;Void&gt; taskPool;<a name="line.201"></a>
-<span class="sourceLineNo">202</span>    private final ThreadPoolExecutor executor;<a name="line.202"></a>
-<span class="sourceLineNo">203</span>    private volatile boolean stopped;<a name="line.203"></a>
-<span class="sourceLineNo">204</span>    private final List&lt;Future&lt;Void&gt;&gt; futures = new ArrayList&lt;&gt;();<a name="line.204"></a>
-<span class="sourceLineNo">205</span>    private final String name;<a name="line.205"></a>
-<span class="sourceLineNo">206</span><a name="line.206"></a>
-<span class="sourceLineNo">207</span>    FlushTableSubprocedurePool(String name, Configuration conf, Abortable abortable) {<a name="line.207"></a>
-<span class="sourceLineNo">208</span>      this.abortable = abortable;<a name="line.208"></a>
-<span class="sourceLineNo">209</span>      // configure the executor service<a name="line.209"></a>
-<span class="sourceLineNo">210</span>      long keepAlive = conf.getLong(<a name="line.210"></a>
-<span class="sourceLineNo">211</span>        RegionServerFlushTableProcedureManager.FLUSH_TIMEOUT_MILLIS_KEY,<a name="line.211"></a>
-<span class="sourceLineNo">212</span>        RegionServerFlushTableProcedureManager.FLUSH_TIMEOUT_MILLIS_DEFAULT);<a name="line.212"></a>
-<span class="sourceLineNo">213</span>      int threads = conf.getInt(CONCURENT_FLUSH_TASKS_KEY, DEFAULT_CONCURRENT_FLUSH_TASKS);<a name="line.213"></a>
-<span class="sourceLineNo">214</span>      this.name = name;<a name="line.214"></a>
-<span class="sourceLineNo">215</span>      executor = new ThreadPoolExecutor(threads, threads, keepAlive, TimeUnit.MILLISECONDS,<a name="line.215"></a>
-<span class="sourceLineNo">216</span>          new LinkedBlockingQueue&lt;&gt;(), new DaemonThreadFactory("rs("<a name="line.216"></a>
-<span class="sourceLineNo">217</span>              + name + ")-flush-proc-pool"));<a name="line.217"></a>
-<span class="sourceLineNo">218</span>      executor.allowCoreThreadTimeOut(true);<a name="line.218"></a>
-<span class="sourceLineNo">219</span>      taskPool = new ExecutorCompletionService&lt;&gt;(executor);<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>    boolean hasTasks() {<a name="line.222"></a>
-<span class="sourceLineNo">223</span>      return futures.size() != 0;<a name="line.223"></a>
-<span class="sourceLineNo">224</span>    }<a name="line.224"></a>
-<span class="sourceLineNo">225</span><a name="line.225"></a>
-<span class="sourceLineNo">226</span>    /**<a name="line.226"></a>
-<span class="sourceLineNo">227</span>     * Submit a task to the pool.<a name="line.227"></a>
-<span class="sourceLineNo">228</span>     *<a name="line.228"></a>
-<span class="sourceLineNo">229</span>     * NOTE: all must be submitted before you can safely {@link #waitForOutstandingTasks()}.<a name="line.229"></a>
-<span class="sourceLineNo">230</span>     */<a name="line.230"></a>
-<span class="sourceLineNo">231</span>    void submitTask(final Callable&lt;Void&gt; task) {<a name="line.231"></a>
-<span class="sourceLineNo">232</span>      Future&lt;Void&gt; f = this.taskPool.submit(task);<a name="line.232"></a>
-<span class="sourceLineNo">233</span>      futures.add(f);<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>    /**<a name="line.236"></a>
-<span class="sourceLineNo">237</span>     * Wait for all of the currently outstanding tasks submitted via {@link #submitTask(Callable)}.<a name="line.237"></a>
-<span class="sourceLineNo">238</span>     * This *must* be called after all tasks are submitted via submitTask.<a name="line.238"></a>
-<span class="sourceLineNo">239</span>     *<a name="line.239"></a>
-<span class="sourceLineNo">240</span>     * @return &lt;tt&gt;true&lt;/tt&gt; on success, &lt;tt&gt;false&lt;/tt&gt; otherwise<a name="line.240"></a>
-<span class="sourceLineNo">241</span>     * @throws InterruptedException<a name="line.241"></a>
-<span class="sourceLineNo">242</span>     */<a name="line.242"></a>
-<span class="sourceLineNo">243</span>    boolean waitForOutstandingTasks() throws ForeignException, InterruptedException {<a name="line.243"></a>
-<span class="sourceLineNo">244</span>      LOG.debug("Waiting for local region flush to finish.");<a name="line.244"></a>
-<span class="sourceLineNo">245</span><a name="line.245"></a>
-<span class="sourceLineNo">246</span>      int sz = futures.size();<a name="line.246"></a>
-<span class="sourceLineNo">247</span>      try {<a name="line.247"></a>
-<span class="sourceLineNo">248</span>        // Using the completion service to process the futures.<a name="line.248"></a>
-<span class="sourceLineNo">249</span>        for (int i = 0; i &lt; sz; i++) {<a name="line.249"></a>
-<span class="sourceLineNo">250</span>          Future&lt;Void&gt; f = taskPool.take();<a name="line.250"></a>
-<span class="sourceLineNo">251</span>          f.get();<a name="line.251"></a>
-<span class="sourceLineNo">252</span>          if (!futures.remove(f)) {<a name="line.252"></a>
-<span class="sourceLineNo">253</span>            LOG.warn("unexpected future" + f);<a name="line.253"></a>
-<span class="sourceLineNo">254</span>          }<a name="line.254"></a>
-<span class="sourceLineNo">255</span>          LOG.debug("Completed " + (i+1) + "/" + sz +  " local region flush tasks.");<a name="line.255"></a>
-<span class="sourceLineNo">256</span>        }<a name="line.256"></a>
-<span class="sourceLineNo">257</span>        LOG.debug("Completed " + sz +  " local region flush tasks.");<a name="line.257"></a>
-<span class="sourceLineNo">258</span>        return true;<a name="line.258"></a>
-<span class="sourceLineNo">259</span>      } catch (InterruptedException e) {<a name="line.259"></a>
-<span class="sourceLineNo">260</span>        LOG.warn("Got InterruptedException in FlushSubprocedurePool", e);<a name="line.260"></a>
-<span class="sourceLineNo">261</span>        if (!stopped) {<a name="line.261"></a>
-<span class="sourceLineNo">262</span>          Thread.currentThread().interrupt();<a name="line.262"></a>
-<span class="sourceLineNo">263</span>          throw new ForeignException("FlushSubprocedurePool", e);<a name="line.263"></a>
-<span class="sourceLineNo">264</span>        }<a name="line.264"></a>
-<span class="sourceLineNo">265</span>        // we are stopped so we can just exit.<a name="line.265"></a>
-<span class="sourceLineNo">266</span>      } catch (ExecutionException e) {<a name="line.266"></a>
-<span class="sourceLineNo">267</span>        Throwable cause = e.getCause();<a name="line.267"></a>
-<span class="sourceLineNo">268</span>        if (cause instanceof ForeignException) {<a name="line.268"></a>
-<span class="sourceLineNo">269</span>          LOG.warn("Rethrowing ForeignException from FlushSubprocedurePool", e);<a name="line.269"></a>
-<span class="sourceLineNo">270</span>          throw (ForeignException)e.getCause();<a name="line.270"></a>
-<span class="sourceLineNo">271</span>        } else if (cause instanceof DroppedSnapshotException) {<a name="line.271"></a>
-<span class="sourceLineNo">272</span>          // we have to abort the region server according to contract of flush<a name="line.272"></a>
-<span class="sourceLineNo">273</span>          abortable.abort("Received DroppedSnapshotException, aborting", cause);<a name="line.273"></a>
-<span class="sourceLineNo">274</span>        }<a name="line.274"></a>
-<span class="sourceLineNo">275</span>        LOG.warn("Got Exception in FlushSubprocedurePool", e);<a name="line.275"></a>
-<span class="sourceLineNo">276</span>        throw new ForeignException(name, e.getCause());<a name="line.276"></a>
-<span class="sourceLineNo">277</span>      } finally {<a name="line.277"></a>
-<span class="sourceLineNo">278</span>        cancelTasks();<a name="line.278"></a>
-<span class="sourceLineNo">279</span>      }<a name="line.279"></a>
-<span class="sourceLineNo">280</span>      return false;<a name="line.280"></a>
-<span class="sourceLineNo">281</span>    }<a name="line.281"></a>
-<span class="sourceLineNo">282</span><a name="line.282"></a>
-<span class="sourceLineNo">283</span>    /**<a name="line.283"></a>
-<span class="sourceLineNo">284</span>     * This attempts to cancel out all pending and in progress tasks. Does not interrupt the running<a name="line.284"></a>
-<span class="sourceLineNo">285</span>     * tasks itself. An ongoing HRegion.flush() should not be interrupted (see HBASE-13877).<a name="line.285"></a>
-<span class="sourceLineNo">286</span>     * @throws InterruptedException<a name="line.286"></a>
-<span class="sourceLineNo">287</span>     */<a name="line.287"></a>
-<span class="sourceLineNo">288</span>    void cancelTasks() throws InterruptedException {<a name="line.288"></a>
-<span class="sourceLineNo">289</span>      Collection&lt;Future&lt;Void&gt;&gt; tasks = futures;<a name="line.289"></a>
-<span class="sourceLineNo">290</span>      LOG.debug("cancelling " + tasks.size() + " flush region tasks " + name);<a name="line.290"></a>
-<span class="sourceLineNo">291</span>      for (Future&lt;Void&gt; f: tasks) {<a name="line.291"></a>
-<span class="sourceLineNo">292</span>        f.cancel(false);<a name="line.292"></a>
-<span class="sourceLineNo">293</span>      }<a name="line.293"></a>
-<span class="sourceLineNo">294</span><a name="line.294"></a>
-<span class="sourceLineNo">295</span>      // evict remaining tasks and futures from taskPool.<a name="line.295"></a>
-<span class="sourceLineNo">296</span>      futures.clear();<a name="line.296"></a>
-<span class="sourceLineNo">297</span>      while (taskPool.poll() != null) {}<a name="line.297"></a>
-<span class="sourceLineNo">298</span>      stop();<a name="line.298"></a>
-<span class="sourceLineNo">299</span>    }<a name="line.299"></a>
-<span class="sourceLineNo">300</span><a name="line.300"></a>
-<span class="sourceLineNo">301</span>    /**<a name="line.301"></a>
-<span class="sourceLineNo">302</span>     * Gracefully shutdown the thread pool. An ongoing HRegion.flush() should not be<a name="line.302"></a>
-<span class="sourceLineNo">303</span>     * interrupted (see HBASE-13877)<a name="line.303"></a>
-<span class="sourceLineNo">304</span>     */<a name="line.304"></a>
-<span class="sourceLineNo">305</span>    void stop() {<a name="line.305"></a>
-<span class="sourceLineNo">306</span>      if (this.stopped) return;<a name="line.306"></a>
-<span class="sourceLineNo">307</span><a name="line.307"></a>
-<span class="sourceLineNo">308</span>      this.stopped = true;<a name="line.308"></a>
-<span class="sourceLineNo">309</span>      this.executor.shutdown();<a name="line.309"></a>
-<span class="sourceLineNo">310</span>    }<a name="line.310"></a>
-<span class="sourceLineNo">311</span>  }<a name="line.311"></a>
-<span class="sourceLineNo">312</span><a name="line.312"></a>
-<span class="sourceLineNo">313</span>  /**<a name="line.313"></a>
-<span class="sourceLineNo">314</span>   * Initialize this region server flush procedure manager<a name="line.314"></a>
-<span class="sourceLineNo">315</span>   * Uses a zookeeper based member controller.<a name="line.315"></a>
-<span class="sourceLineNo">316</span>   * @param rss region server<a name="line.316"></a>
-<span class="sourceLineNo">317</span>   * @throws KeeperException if the zookeeper cannot be reached<a name="line.317"></a>
-<span class="sourceLineNo">318</span>   */<a name="line.318"></a>
-<span class="sourceLineNo">319</span>  @Override<a name="line.319"></a>
-<span class="sourceLineNo">320</span>  public void initialize(RegionServerServices rss) throws KeeperException {<a name="line.320"></a>
-<span class="sourceLineNo">321</span>    this.rss = rss;<a name="line.321"></a>
-<span class="sourceLineNo">322</span>    ZooKeeperWatcher zkw = rss.getZooKeeper();<a name="line.322"></a>
-<span class="sourceLineNo">323</span>    this.memberRpcs = new ZKProcedureMemberRpcs(zkw,<a name="line.323"></a>
-<span class="sourceLineNo">324</span>      MasterFlushTableProcedureManager.FLUSH_TABLE_PROCEDURE_SIGNATURE);<a name="line.324"></a>
-<span class="sourceLineNo">325</span><a name="line.325"></a>
-<span class="sourceLineNo">326</span>    Configuration conf = rss.getConfiguration();<a name="line.326"></a>
-<span class="sourceLineNo">327</span>    long keepAlive = conf.getLong(FLUSH_TIMEOUT_MILLIS_KEY, FLUSH_TIMEOUT_MILLIS_DEFAULT);<a name="line.327"></a>
-<span class="sourceLineNo">328</span>    int opThreads = conf.getInt(FLUSH_REQUEST_THREADS_KEY, FLUSH_REQUEST_THREADS_DEFAULT);<a name="line.328"></a>
-<span class="sourceLineNo">329</span><a name="line.329"></a>
-<span class="sourceLineNo">330</span>    // create the actual flush table procedure member<a name="line.330"></a>
-<span class="sourceLineNo">331</span>    ThreadPoolExecutor pool = ProcedureMember.defaultPool(rss.getServerName().toString(),<a name="line.331"></a>
-<span class="sourceLineNo">332</span>      opThreads, keepAlive);<a name="line.332"></a>
-<span class="sourceLineNo">333</span>    this.member = new ProcedureMember(memberRpcs, pool, new FlushTableSubprocedureBuilder());<a name="line.333"></a>
-<span class="sourceLineNo">334</span>  }<a name="line.334"></a>
-<span class="sourceLineNo">335</span><a name="line.335"></a>
-<span class="sourceLineNo">336</span>  @Override<a name="line.336"></a>
-<span class="sourceLineNo">337</span>  public String getProcedureSignature() {<a name="line.337"></a>
-<span class="sourceLineNo">338</span>    return MasterFlushTableProcedureManager.FLUSH_TABLE_PROCEDURE_SIGNATURE;<a name="line.338"></a>
-<span class="sourceLineNo">339</span>  }<a name="line.339"></a>
-<span class="sourceLineNo">340</span><a name="line.340"></a>
-<span class="sourceLineNo">341</span>}<a name="line.341"></a>
+<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.regionserver.HRegion;<a name="line.49"></a>
+<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.regionserver.HRegionServer;<a name="line.50"></a>
+<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.regionserver.Region;<a name="line.51"></a>
+<span class="sourceLineNo">052</span>import org.apache.hadoop.hbase.regionserver.RegionServerServices;<a name="line.52"></a>
+<span class="sourceLineNo">053</span>import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;<a name="line.53"></a>
+<span class="sourceLineNo">054</span>import org.apache.zookeeper.KeeperException;<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> * This manager class handles flushing of the regions for table on a {@link HRegionServer}.<a name="line.57"></a>
+<span class="sourceLineNo">058</span> */<a name="line.58"></a>
+<span class="sourceLineNo">059</span>@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)<a name="line.59"></a>
+<span class="sourceLineNo">060</span>public class RegionServerFlushTableProcedureManager extends RegionServerProcedureManager {<a name="line.60"></a>
+<span class="sourceLineNo">061</span>  private static final Log LOG = LogFactory.getLog(RegionServerFlushTableProcedureManager.class);<a name="line.61"></a>
+<span class="sourceLineNo">062</span><a name="line.62"></a>
+<span class="sourceLineNo">063</span>  private static final String CONCURENT_FLUSH_TASKS_KEY =<a name="line.63"></a>
+<span class="sourceLineNo">064</span>      "hbase.flush.procedure.region.concurrentTasks";<a name="line.64"></a>
+<span class="sourceLineNo">065</span>  private static final int DEFAULT_CONCURRENT_FLUSH_TASKS = 3;<a name="line.65"></a>
+<span class="sourceLineNo">066</span><a name="line.66"></a>
+<span class="sourceLineNo">067</span>  public static final String FLUSH_REQUEST_THREADS_KEY =<a name="line.67"></a>
+<span class="sourceLineNo">068</span>      "hbase.flush.procedure.region.pool.threads";<a name="line.68"></a>
+<span class="sourceLineNo">069</span>  public static final int FLUSH_REQUEST_THREADS_DEFAULT = 10;<a name="line.69"></a>
+<span class="sourceLineNo">070</span><a name="line.70"></a>
+<span class="sourceLineNo">071</span>  public static final String FLUSH_TIMEOUT_MILLIS_KEY =<a name="line.71"></a>
+<span class="sourceLineNo">072</span>      "hbase.flush.procedure.region.timeout";<a name="line.72"></a>
+<span class="sourceLineNo">073</span>  public static final long FLUSH_TIMEOUT_MILLIS_DEFAULT = 60000;<a name="line.73"></a>
+<span class="sourceLineNo">074</span><a name="line.74"></a>
+<span class="sourceLineNo">075</span>  public static final String FLUSH_REQUEST_WAKE_MILLIS_KEY =<a name="line.75"></a>
+<span class="sourceLineNo">076</span>      "hbase.flush.procedure.region.wakefrequency";<a name="line.76"></a>
+<span class="sourceLineNo">077</span>  private static final long FLUSH_REQUEST_WAKE_MILLIS_DEFAULT = 500;<a name="line.77"></a>
+<span class="sourceLineNo">078</span><a name="line.78"></a>
+<span class="sourceLineNo">079</span>  private RegionServerServices rss;<a name="line.79"></a>
+<span class="sourceLineNo">080</span>  private ProcedureMemberRpcs memberRpcs;<a name="line.80"></a>
+<span class="sourceLineNo">081</span>  private ProcedureMember member;<a name="line.81"></a>
+<span class="sourceLineNo">082</span><a name="line.82"></a>
+<span class="sourceLineNo">083</span>  /**<a name="line.83"></a>
+<span class="sourceLineNo">084</span>   * Exposed for testing.<a name="line.84"></a>
+<span class="sourceLineNo">085</span>   * @param conf HBase configuration.<a name="line.85"></a>
+<span class="sourceLineNo">086</span>   * @param server region server.<a name="line.86"></a>
+<span class="sourceLineNo">087</span>   * @param memberRpc use specified memberRpc instance<a name="line.87"></a>
+<span class="sourceLineNo">088</span>   * @param procMember use specified ProcedureMember<a name="line.88"></a>
+<span class="sourceLineNo">089</span>   */<a name="line.89"></a>
+<span class="sourceLineNo">090</span>   RegionServerFlushTableProcedureManager(Configuration conf, HRegionServer server,<a name="line.90"></a>
+<span class="sourceLineNo">091</span>      ProcedureMemberRpcs memberRpc, ProcedureMember procMember) {<a name="line.91"></a>
+<span class="sourceLineNo">092</span>    this.rss = server;<a name="line.92"></a>
+<span class="sourceLineNo">093</span>    this.memberRpcs = memberRpc;<a name="line.93"></a>
+<span class="sourceLineNo">094</span>    this.member = procMember;<a name="line.94"></a>
+<span class="sourceLineNo">095</span>  }<a name="line.95"></a>
+<span class="sourceLineNo">096</span><a name="line.96"></a>
+<span class="sourceLineNo">097</span>  public RegionServerFlushTableProcedureManager() {}<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>   * Start accepting flush table requests.<a name="line.100"></a>
+<span class="sourceLineNo">101</span>   */<a name="line.101"></a>
+<span class="sourceLineNo">102</span>  @Override<a name="line.102"></a>
+<span class="sourceLineNo">103</span>  public void start() {<a name="line.103"></a>
+<span class="sourceLineNo">104</span>    LOG.debug("Start region server flush procedure manager " + rss.getServerName().toString());<a name="line.104"></a>
+<span class="sourceLineNo">105</span>    this.memberRpcs.start(rss.getServerName().toString(), member);<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>  /**<a name="line.108"></a>
+<span class="sourceLineNo">109</span>   * Close &lt;tt&gt;this&lt;/tt&gt; and all running tasks<a name="line.109"></a>
+<span class="sourceLineNo">110</span>   * @param force forcefully stop all running tasks<a name="line.110"></a>
+<span class="sourceLineNo">111</span>   * @throws IOException<a name="line.111"></a>
+<span class="sourceLineNo">112</span>   */<a name="line.112"></a>
+<span class="sourceLineNo">113</span>  @Override<a name="line.113"></a>
+<span class="sourceLineNo">114</span>  public void stop(boolean force) throws IOException {<a name="line.114"></a>
+<span class="sourceLineNo">115</span>    String mode = force ? "abruptly" : "gracefully";<a name="line.115"></a>
+<span class="sourceLineNo">116</span>    LOG.info("Stopping region server flush procedure manager " + mode + ".");<a name="line.116"></a>
+<span class="sourceLineNo">117</span><a name="line.117"></a>
+<span class="sourceLineNo">118</span>    try {<a name="line.118"></a>
+<span class="sourceLineNo">119</span>      this.member.close();<a name="line.119"></a>
+<span class="sourceLineNo">120</span>    } finally {<a name="line.120"></a>
+<span class="sourceLineNo">121</span>      this.memberRpcs.close();<a name="line.121"></a>
+<span class="sourceLineNo">122</span>    }<a name="line.122"></a>
+<span class="sourceLineNo">123</span>  }<a name="line.123"></a>
+<span class="sourceLineNo">124</span><a name="line.124"></a>
+<span class="sourceLineNo">125</span>  /**<a name="line.125"></a>
+<span class="sourceLineNo">126</span>   * If in a running state, creates the specified subprocedure to flush table regions.<a name="line.126"></a>
+<span class="sourceLineNo">127</span>   *<a name="line.127"></a>
+<span class="sourceLineNo">128</span>   * Because this gets the local list of regions to flush and not the set the master had,<a name="line.128"></a>
+<span class="sourceLineNo">129</span>   * there is a possibility of a race where regions may be missed.<a name="line.129"></a>
+<span class="sourceLineNo">130</span>   *<a name="line.130"></a>
+<span class="sourceLineNo">131</span>   * @param table<a name="line.131"></a>
+<span class="sourceLineNo">132</span>   * @return Subprocedure to submit to the ProcedureMemeber.<a name="line.132"></a>
+<span class="sourceLineNo">133</span>   */<a name="line.133"></a>
+<span class="sourceLineNo">134</span>  public Subprocedure buildSubprocedure(String table) {<a name="line.134"></a>
+<span class="sourceLineNo">135</span><a name="line.135"></a>
+<span class="sourceLineNo">136</span>    // don't run the subprocedure if the parent is stop(ping)<a name="line.136"></a>
+<span class="sourceLineNo">137</span>    if (rss.isStopping() || rss.isStopped()) {<a name="line.137"></a>
+<span class="sourceLineNo">138</span>      throw new IllegalStateException("Can't start flush region subprocedure on RS: "<a name="line.138"></a>
+<span class="sourceLineNo">139</span>          + rss.getServerName() + ", because stopping/stopped!");<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>    // check to see if this server is hosting any regions for the table<a name="line.142"></a>
+<span class="sourceLineNo">143</span>    List&lt;HRegion&gt; involvedRegions;<a name="line.143"></a>
+<span class="sourceLineNo">144</span>    try {<a name="line.144"></a>
+<span class="sourceLineNo">145</span>      involvedRegions = getRegionsToFlush(table);<a name="line.145"></a>
+<span class="sourceLineNo">146</span>    } catch (IOException e1) {<a name="line.146"></a>
+<span class="sourceLineNo">147</span>      throw new IllegalStateException("Failed to figure out if there is region to flush.", e1);<a name="line.147"></a>
+<span class="sourceLineNo">148</span>    }<a name="line.148"></a>
+<span class="sourceLineNo">149</span><a name="line.149"></a>
+<span class="sourceLineNo">150</span>    // We need to run the subprocedure even if we have no relevant regions.  The coordinator<a name="line.150"></a>
+<span class="sourceLineNo">151</span>    // expects participation in the procedure and without sending message the master procedure<a name="line.151"></a>
+<span class="sourceLineNo">152</span>    // will hang and fail.<a name="line.152"></a>
+<span class="sourceLineNo">153</span><a name="line.153"></a>
+<span class="sourceLineNo">154</span>    LOG.debug("Launching subprocedure to flush regions for " + table);<a name="line.154"></a>
+<span class="sourceLineNo">155</span>    ForeignExceptionDispatcher exnDispatcher = new ForeignExceptionDispatcher(table);<a name="line.155"></a>
+<span class="sourceLineNo">156</span>    Configuration conf = rss.getConfiguration();<a name="line.156"></a>
+<span class="sourceLineNo">157</span>    long timeoutMillis = conf.getLong(FLUSH_TIMEOUT_MILLIS_KEY,<a name="line.157"></a>
+<span class="sourceLineNo">158</span>        FLUSH_TIMEOUT_MILLIS_DEFAULT);<a name="line.158"></a>
+<span class="sourceLineNo">159</span>    long wakeMillis = conf.getLong(FLUSH_REQUEST_WAKE_MILLIS_KEY,<a name="line.159"></a>
+<span class="sourceLineNo">160</span>        FLUSH_REQUEST_WAKE_MILLIS_DEFAULT);<a name="line.160"></a>
+<span class="sourceLineNo">161</span><a name="line.161"></a>
+<span class="sourceLineNo">162</span>    FlushTableSubprocedurePool taskManager =<a name="line.162"></a>
+<span class="sourceLineNo">163</span>        new FlushTableSubprocedurePool(rss.getServerName().toString(), conf, rss);<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    return new FlushTableSubprocedure(member, exnDispatcher, wakeMillis,<a name="line.164"></a>
+<span class="sourceLineNo">165</span>      timeoutMillis, involvedRegions, table, taskManager);<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>  /**<a name="line.168"></a>
+<span class="sourceLineNo">169</span>   * Get the list of regions to flush for the table on this server<a name="line.169"></a>
+<span class="sourceLineNo">170</span>   *<a name="line.170"></a>
+<span class="sourceLineNo">171</span>   * It is possible that if a region moves somewhere between the calls<a name="line.171"></a>
+<span class="sourceLineNo">172</span>   * we'll miss the region.<a name="line.172"></a>
+<span class="sourceLineNo">173</span>   *<a name="line.173"></a>
+<span class="sourceLineNo">174</span>   * @param table<a name="line.174"></a>
+<span class="sourceLineNo">175</span>   * @return the list of online regions. Empty list is returned if no regions.<a name="line.175"></a>
+<span class="sourceLineNo">176</span>   * @throws IOException<a name="line.176"></a>
+<span class="sourceLineNo">177</span>   */<a name="line.177"></a>
+<span class="sourceLineNo">178</span>  private List&lt;HRegion&gt; getRegionsToFlush(String table) throws IOException {<a name="line.178"></a>
+<span class="sourceLineNo">179</span>    return (List&lt;HRegion&gt;) rss.getRegions(TableName.valueOf(table));<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>  public class FlushTableSubprocedureBuilder implements SubprocedureFactory {<a name="line.182"></a>
+<span class="sourceLineNo">183</span><a name="line.183"></a>
+<span class="sourceLineNo">184</span>    @Override<a name="line.184"></a>
+<span class="sourceLineNo">185</span>    public Subprocedure buildSubprocedure(String name, byte[] data) {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>      // The name of the procedure instance from the master is the table name.<a name="line.186"></a>
+<span class="sourceLineNo">187</span>      return RegionServerFlushTableProcedureManager.this.buildSubprocedure(name);<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><a name="line.191"></a>
+<span class="sourceLineNo">192</span>  /**<a name="line.192"></a>
+<span class="sourceLineNo">193</span>   * We use the FlushTableSubprocedurePool, a class specific thread pool instead of<a name="line.193"></a>
+<span class="sourceLineNo">194</span>   * {@link org.apache.hadoop.hbase.executor.ExecutorService}.<a name="line.194"></a>
+<span class="sourceLineNo">195</span>   *<a name="line.195"></a>
+<span class="sourceLineNo">196</span>   * It uses a {@link java.util.concurrent.ExecutorCompletionService} which provides queuing of<a name="line.196"></a>
+<span class="sourceLineNo">197</span>   * completed tasks which lets us efficiently cancel pending tasks upon the earliest operation<a name="line.197"></a>
+<span class="sourceLineNo">198</span>   * failures.<a name="line.198"></a>
+<span class="sourceLineNo">199</span>   */<a name="line.199"></a>
+<span class="sourceLineNo">200</span>  static class FlushTableSubprocedurePool {<a name="line.200"></a>
+<span class="sourceLineNo">201</span>    private final Abortable abortable;<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    private final ExecutorCompletionService&lt;Void&gt; taskPool;<a name="line.202"></a>
+<span class="sourceLineNo">203</span>    private final ThreadPoolExecutor executor;<a name="line.203"></a>
+<span class="sourceLineNo">204</span>    private volatile boolean stopped;<a name="line.204"></a>
+<span class="sourceLineNo">205</span>    private final List&lt;Future&lt;Void&gt;&gt; futures = new ArrayList&lt;&gt;();<a name="line.205"></a>
+<span class="sourceLineNo">206</span>    private final String name;<a name="line.206"></a>
+<span class="sourceLineNo">207</span><a name="line.207"></a>
+<span class="sourceLineNo">208</span>    FlushTableSubprocedurePool(String name, Configuration conf, Abortable abortable) {<a name="line.208"></a>
+<span class="sourceLineNo">209</span>      this.abortable = abortable;<a name="line.209"></a>
+<span class="sourceLineNo">210</span>      // configure the executor service<a name="line.210"></a>
+<span class="sourceLineNo">211</span>      long keepAlive = conf.getLong(<a name="line.211"></a>
+<span class="sourceLineNo">212</span>        RegionServerFlushTableProcedureManager.FLUSH_TIMEOUT_MILLIS_KEY,<a name="line.212"></a>
+<span class="sourceLineNo">213</span>        RegionServerFlushTableProcedureManager.FLUSH_TIMEOUT_MILLIS_DEFAULT);<a name="line.213"></a>
+<span class="sourceLineNo">214</span>      int threads = conf.getInt(CONCURENT_FLUSH_TASKS_KEY, DEFAULT_CONCURRENT_FLUSH_TASKS);<a name="line.214"></a>
+<span class="sourceLineNo">215</span>      this.name = name;<a name="line.215"></a>
+<span class="sourceLineNo">216</span>      executor = new ThreadPoolExecutor(threads, threads, keepAlive, TimeUnit.MILLISECONDS,<a name="line.216"></a>
+<span class="sourceLineNo">217</span>          new LinkedBlockingQueue&lt;&gt;(), new DaemonThreadFactory("rs("<a name="line.217"></a>
+<span class="sourceLineNo">218</span>              + name + ")-flush-proc-pool"));<a name="line.218"></a>
+<span class="sourceLineNo">219</span>      executor.allowCoreThreadTimeOut(true);<a name="line.219"></a>
+<span class="sourceLineNo">220</span>      taskPool = new ExecutorCompletionService&lt;&gt;(executor);<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>    boolean hasTasks() {<a name="line.223"></a>
+<span class="sourceLineNo">224</span>      return futures.size() != 0;<a name="line.224"></a>
+<span class="sourceLineNo">225</span>    }<a name="line.225"></a>
+<span class="sourceLineNo">226</span><a name="line.226"></a>
+<span class="sourceLineNo">227</span>    /**<a name="line.227"></a>
+<span class="sourceLineNo">228</span>     * Submit a task to the pool.<a name="line.228"></a>
+<span class="sourceLineNo">229</span>     *<a name="line.229"></a>
+<span class="sourceLineNo">230</span>     * NOTE: all must be submitted before you can safely {@link #waitForOutstandingTasks()}.<a name="line.230"></a>
+<span class="sourceLineNo">231</span>     */<a name="line.231"></a>
+<span class="sourceLineNo">232</span>    void submitTask(final Callable&lt;Void&gt; task) {<a name="line.232"></a>
+<span class="sourceLineNo">233</span>      Future&lt;Void&gt; f = this.taskPool.submit(task);<a name="line.233"></a>
+<span class="sourceLineNo">234</span>      futures.add(f);<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>    /**<a name="line.237"></a>
+<span class="sourceLineNo">238</span>     * Wait for all of the currently outstanding tasks submitted via {@link #submitTask(Callable)}.<a name="line.238"></a>
+<span class="sourceLineNo">239</span>     * This *must* be called after all tasks are submitted via submitTask.<a name="line.239"></a>
+<span class="sourceLineNo">240</span>     *<a name="line.240"></a>
+<span class="sourceLineNo">241</span>     * @return &lt;tt&gt;true&lt;/tt&gt; on success, &lt;tt&gt;false&lt;/tt&gt; otherwise<a name="line.241"></a>
+<span class="sourceLineNo">242</span>     * @throws InterruptedException<a name="line.242"></a>
+<span class="sourceLineNo">243</span>     */<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    boolean waitForOutstandingTasks() throws ForeignException, InterruptedException {<a name="line.244"></a>
+<span class="sourceLineNo">245</span>      LOG.debug("Waiting for local region flush to finish.");<a name="line.245"></a>
+<span class="sourceLineNo">246</span><a name="line.246"></a>
+<span class="sourceLineNo">247</span>      int sz = futures.size();<a name="line.247"></a>
+<span class="sourceLineNo">248</span>      try {<a name="line.248"></a>
+<span class="sourceLineNo">249</span>        // Using the completion service to process the futures.<a name="line.249"></a>
+<span class="sourceLineNo">250</span>        for (int i = 0; i &lt; sz; i++) {<a name="line.250"></a>
+<span class="sourceLineNo">251</span>          Future&lt;Void&gt; f = taskPool.take();<a name="line.251"></a>
+<span class="sourceLineNo">252</span>          f.get();<a name="line.252"></a>
+<span class="sourceLineNo">253</span>          if (!futures.remove(f)) {<a name="line.253"></a>
+<span class="sourceLineNo">254</span>            LOG.warn("unexpected future" + f);<a name="line.254"></a>
+<span class="sourceLineNo">255</span>          }<a name="line.255"></a>
+<span class="sourceLineNo">256</span>          LOG.debug("Completed " + (i+1) + "/" + sz +  " local region flush tasks.");<a name="line.256"></a>
+<span class="sourceLineNo">257</span>        }<a name="line.257"></a>
+<span class="sourceLineNo">258</span>        LOG.debug("Completed " + sz +  " local region flush tasks.");<a name="line.258"></a>
+<span class="sourceLineNo">259</span>        return true;<a name="line.259"></a>
+<span class="sourceLineNo">260</span>      } catch (InterruptedException e) {<a name="line.260"></a>
+<span class="sourceLineNo">261</span>        LOG.warn("Got InterruptedException in FlushSubprocedurePool", e);<a name="line.261"></a>
+<span class="sourceLineNo">262</span>        if (!stopped) {<a name="line.262"></a>
+<span class="sourceLineNo">263</span>          Thread.currentThread().interrupt();<a name="line.263"></a>
+<span class="sourceLineNo">264</span>          throw new ForeignException("FlushSubprocedurePool", e);<a name="line.264"></a>
+<span class="sourceLineNo">265</span>        }<a name="line.265"></a>
+<span class="sourceLineNo">266</span>        // we are stopped so we can just exit.<a name="line.266"></a>
+<span class="sourceLineNo">267</span>      } catch (ExecutionException e) {<a name="line.267"></a>
+<span class="sourceLineNo">268</span>        Throwable cause = e.getCause();<a name="line.268"></a>
+<span class="sourceLineNo">269</span>        if (cause instanceof ForeignException) {<a name="line.269"></a>
+<span class="sourceLineNo">270</span>          LOG.warn("Rethrowing ForeignException from FlushSubprocedurePool", e);<a name="line.270"></a>
+<span class="sourceLineNo">271</span>          throw (ForeignException)e.getCause();<a name="line.271"></a>
+<span class="sourceLineNo">272</span>        } else if (cause instanceof DroppedSnapshotException) {<a name="line.272"></a>
+<span class="sourceLineNo">273</span>          // we have to abort the region server according to contract of flush<a name="line.273"></a>
+<span class="sourceLineNo">274</span>          abortable.abort("Received DroppedSnapshotException, aborting", cause);<a name="line.274"></a>
+<span class="sourceLineNo">275</span>        }<a name="line.275"></a>
+<span class="sourceLineNo">276</span>        LOG.warn("Got Exception in FlushSubprocedurePool", e);<a name="line.276"></a>
+<span class="sourceLineNo">277</span>        throw new ForeignException(name, e.getCause());<a name="line.277"></a>
+<span class="sourceLineNo">278</span>      } finally {<a name="line.278"></a>
+<span class="sourceLineNo">279</span>        cancelTasks();<a name="line.279"></a>
+<span class="sourceLineNo">280</span>      }<a name="line.280"></a>
+<span class="sourceLineNo">281</span>      return false;<a name="line.281"></a>
+<span class="sourceLineNo">282</span>    }<a name="line.282"></a>
+<span class="sourceLineNo">283</span><a name="line.283"></a>
+<span class="sourceLineNo">284</span>    /**<a name="line.284"></a>
+<span class="sourceLineNo">285</span>     * This attempts to cancel out all pending and in progress tasks. Does not interrupt the running<a name="line.285"></a>
+<span class="sourceLineNo">286</span>     * tasks itself. An ongoing HRegion.flush() should not be interrupted (see HBASE-13877).<a name="line.286"></a>
+<span class="sourceLineNo">287</span>     * @throws InterruptedException<a name="line.287"></a>
+<span class="sourceLineNo">288</span>     */<a name="line.288"></a>
+<span class="sourceLineNo">289</span>    void cancelTasks() throws InterruptedException {<a name="line.289"></a>
+<span class="sourceLineNo">290</span>      Collection&lt;Future&lt;Void&gt;&gt; tasks = futures;<a name="line.290"></a>
+<span class="sourceLineNo">291</span>      LOG.debug("cancelling " + tasks.size() + " flush region tasks " + name);<a name="line.291"></a>
+<span class="sourceLineNo">292</span>      for (Future&lt;Void&gt; f: tasks) {<a name="line.292"></a>
+<span class="sourceLineNo">293</span>        f.cancel(false);<a name="line.293"></a>
+<span class="sourceLineNo">294</span>      }<a name="line.294"></a>
+<span class="sourceLineNo">295</span><a name="line.295"></a>
+<span class="sourceLineNo">296</span>      // evict remaining tasks and futures from taskPool.<a name="line.296"></a>
+<span class="sourceLineNo">297</span>      futures.clear();<a name="line.297"></a>
+<span class="sourceLineNo">298</span>      while (taskPool.poll() != null) {}<a name="line.298"></a>
+<span class="sourceLineNo">299</span>      stop();<a name="line.299"></a>
+<span class="sourceLineNo">300</span>    }<a name="line.300"></a>
+<span class="sourceLineNo">301</span><a name="line.301"></a>
+<span class="sourceLineNo">302</span>    /**<a name="line.302"></a>
+<span class="sourceLineNo">303</span>     * Gracefully shutdown the thread pool. An ongoing HRegion.flush() should not be<a name="line.303"></a>
+<span class="sourceLineNo">304</span>     * interrupted (see HBASE-13877)<a name="line.304"></a>
+<span class="sourceLineNo">305</span>     */<a name="line.305"></a>
+<span class="sourceLineNo">306</span>    void stop() {<a name="line.306"></a>
+<span class="sourceLineNo">307</span>      if (this.stopped) return;<a name="line.307"></a>
+<span class="sourceLineNo">308</span><a name="line.308"></a>
+<span class="sourceLineNo">309</span>      this.stopped = true;<a name="line.309"></a>
+<span class="sourceLineNo">310</span>      this.executor.shutdown();<a name="line.310"></a>
+<span class="sourceLineNo">311</span>    }<a name="line.311"></a>
+<span class="sourceLineNo">312</span>  }<a name="line.312"></a>
+<span class="sourceLineNo">313</span><a name="line.313"></a>
+<span class="sourceLineNo">314</span>  /**<a name="line.314"></a>
+<span class="sourceLineNo">315</span>   * Initialize this region server flush procedure manager<a name="line.315"></a>
+<span class="sourceLineNo">316</span>   * Uses a zookeeper based member controller.<a name="line.316"></a>
+<span class="sourceLineNo">317</span>   * @param rss region server<a name="line.317"></a>
+<span class="sourceLineNo">318</span>   * @throws KeeperException if the zookeeper cannot be reached<a name="line.318"></a>
+<span class="sourceLineNo">319</span>   */<a name="line.319"></a>
+<span class="sourceLineNo">320</span>  @Override<a name="line.320"></a>
+<span class="sourceLineNo">321</span>  public void initialize(RegionServerServices rss) throws KeeperException {<a name="line.321"></a>
+<span class="sourceLineNo">322</span>    this.rss = rss;<a name="line.322"></a>
+<span class="sourceLineNo">323</span>    ZooKeeperWatcher zkw = rss.getZooKeeper();<a name="line.323"></a>
+<span class="sourceLineNo">324</span>    this.memberRpcs = new ZKProcedureMemberRpcs(zkw,<a name="line.324"></a>
+<span class="sourceLineNo">325</span>      MasterFlushTableProcedureManager.FLUSH_TABLE_PROCEDURE_SIGNATURE);<a name="line.325"></a>
+<span class="sourceLineNo">326</span><a name="line.326"></a>
+<span class="sourceLineNo">327</span>    Configuration conf = rss.getConfiguration();<a name="line.327"></a>
+<span class="sourceLineNo">328</span>    long keepAlive = conf.getLong(FLUSH_TIMEOUT_MILLIS_KEY, FLUSH_TIMEOUT_MILLIS_DEFAULT);<a name="line.328"></a>
+<span class="sourceLineNo">329</span>    int opThreads = conf.getInt(FLUSH_REQUEST_THREADS_KEY, FLUSH_REQUEST_THREADS_DEFAULT);<a name="line.329"></a>
+<span class="sourceLineNo">330</span><a name="line.330"></a>
+<span class="sourceLineNo">331</span>    // create the actual flush table procedure member<a name="line.331"></a>
+<span class="sourceLineNo">332</span>    ThreadPoolExecutor pool = ProcedureMember.defaultPool(rss.getServerName().toString(),<a name="line.332"></a>
+<span class="sourceLineNo">333</span>      opThreads, keepAlive);<a name="line.333"></a>
+<span class="sourceLineNo">334</span>    this.member = new ProcedureMember(memberRpcs, pool, new FlushTableSubprocedureBuilder());<a name="line.334"></a>
+<span class="sourceLineNo">335</span>  }<a name="line.335"></a>
+<span class="sourceLineNo">336</span><a name="line.336"></a>
+<span class="sourceLineNo">337</span>  @Override<a name="line.337"></a>
+<span class="sourceLineNo">338</span>  public String getProcedureSignature() {<a name="line.338"></a>
+<span class="sourceLineNo">339</span>    return MasterFlushTableProcedureManager.FLUSH_TABLE_PROCEDURE_SIGNATURE;<a name="line.339"></a>
+<span class="sourceLineNo">340</span>  }<a name="line.340"></a>
+<span class="sourceLineNo">341</span><a name="line.341"></a>
+<span class="sourceLineNo">342</span>}<a name="line.342"></a>
 
 
 


Mime
View raw message