hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [23/37] hbase-site git commit: Published site at .
Date Tue, 17 Oct 2017 15:15:57 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/bd10ee7c/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/FSHLog.SyncRunner.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/FSHLog.SyncRunner.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/FSHLog.SyncRunner.html
index 2918186..c9d92f9 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/FSHLog.SyncRunner.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/FSHLog.SyncRunner.html
@@ -51,22 +51,22 @@
 <span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.util.FSUtils;<a name="line.43"></a>
 <span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.util.HasThread;<a name="line.44"></a>
 <span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.util.Threads;<a name="line.45"></a>
-<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.wal.FSHLogProvider;<a name="line.46"></a>
-<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.wal.WALEdit;<a name="line.47"></a>
-<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.wal.WALFactory;<a name="line.48"></a>
-<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.wal.WALKey;<a name="line.49"></a>
-<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.wal.WALPrettyPrinter;<a name="line.50"></a>
-<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.wal.WALProvider.Writer;<a name="line.51"></a>
-<span class="sourceLineNo">052</span>import org.apache.hadoop.hbase.wal.WALSplitter;<a name="line.52"></a>
-<span class="sourceLineNo">053</span>import org.apache.hadoop.hdfs.DFSOutputStream;<a name="line.53"></a>
-<span class="sourceLineNo">054</span>import org.apache.hadoop.hdfs.client.HdfsDataOutputStream;<a name="line.54"></a>
-<span class="sourceLineNo">055</span>import org.apache.hadoop.hdfs.protocol.DatanodeInfo;<a name="line.55"></a>
-<span class="sourceLineNo">056</span>import org.apache.htrace.NullScope;<a name="line.56"></a>
-<span class="sourceLineNo">057</span>import org.apache.htrace.Span;<a name="line.57"></a>
-<span class="sourceLineNo">058</span>import org.apache.htrace.Trace;<a name="line.58"></a>
-<span class="sourceLineNo">059</span>import org.apache.htrace.TraceScope;<a name="line.59"></a>
-<span class="sourceLineNo">060</span>import org.apache.yetus.audience.InterfaceAudience;<a name="line.60"></a>
-<span class="sourceLineNo">061</span><a name="line.61"></a>
+<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;<a name="line.46"></a>
+<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.wal.FSHLogProvider;<a name="line.47"></a>
+<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.wal.WALEdit;<a name="line.48"></a>
+<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.wal.WALFactory;<a name="line.49"></a>
+<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.wal.WALKey;<a name="line.50"></a>
+<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.wal.WALPrettyPrinter;<a name="line.51"></a>
+<span class="sourceLineNo">052</span>import org.apache.hadoop.hbase.wal.WALProvider.Writer;<a name="line.52"></a>
+<span class="sourceLineNo">053</span>import org.apache.hadoop.hbase.wal.WALSplitter;<a name="line.53"></a>
+<span class="sourceLineNo">054</span>import org.apache.hadoop.hdfs.DFSOutputStream;<a name="line.54"></a>
+<span class="sourceLineNo">055</span>import org.apache.hadoop.hdfs.client.HdfsDataOutputStream;<a name="line.55"></a>
+<span class="sourceLineNo">056</span>import org.apache.hadoop.hdfs.protocol.DatanodeInfo;<a name="line.56"></a>
+<span class="sourceLineNo">057</span>import org.apache.htrace.NullScope;<a name="line.57"></a>
+<span class="sourceLineNo">058</span>import org.apache.htrace.Span;<a name="line.58"></a>
+<span class="sourceLineNo">059</span>import org.apache.htrace.Trace;<a name="line.59"></a>
+<span class="sourceLineNo">060</span>import org.apache.htrace.TraceScope;<a name="line.60"></a>
+<span class="sourceLineNo">061</span>import org.apache.yetus.audience.InterfaceAudience;<a name="line.61"></a>
 <span class="sourceLineNo">062</span>import org.apache.hadoop.hbase.shaded.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>import com.lmax.disruptor.BlockingWaitStrategy;<a name="line.64"></a>
@@ -805,412 +805,416 @@
 <span class="sourceLineNo">797</span>    }<a name="line.797"></a>
 <span class="sourceLineNo">798</span><a name="line.798"></a>
 <span class="sourceLineNo">799</span>    final Path baseDir = FSUtils.getWALRootDir(conf);<a name="line.799"></a>
-<span class="sourceLineNo">800</span>    final Path archiveDir = new Path(baseDir, HConstants.HREGION_OLDLOGDIR_NAME);<a name="line.800"></a>
-<span class="sourceLineNo">801</span>    WALSplitter.split(baseDir, p, archiveDir, fs, conf, WALFactory.getInstance(conf));<a name="line.801"></a>
-<span class="sourceLineNo">802</span>  }<a name="line.802"></a>
-<span class="sourceLineNo">803</span><a name="line.803"></a>
-<span class="sourceLineNo">804</span>  /**<a name="line.804"></a>
-<span class="sourceLineNo">805</span>   * This class is used coordinating two threads holding one thread at a 'safe point' while the<a name="line.805"></a>
-<span class="sourceLineNo">806</span>   * orchestrating thread does some work that requires the first thread paused: e.g. holding the WAL<a name="line.806"></a>
-<span class="sourceLineNo">807</span>   * writer while its WAL is swapped out from under it by another thread.<a name="line.807"></a>
-<span class="sourceLineNo">808</span>   * &lt;p&gt;<a name="line.808"></a>
-<span class="sourceLineNo">809</span>   * Thread A signals Thread B to hold when it gets to a 'safe point'. Thread A wait until Thread B<a name="line.809"></a>
-<span class="sourceLineNo">810</span>   * gets there. When the 'safe point' has been attained, Thread B signals Thread A. Thread B then<a name="line.810"></a>
-<span class="sourceLineNo">811</span>   * holds at the 'safe point'. Thread A on notification that Thread B is paused, goes ahead and<a name="line.811"></a>
-<span class="sourceLineNo">812</span>   * does the work it needs to do while Thread B is holding. When Thread A is done, it flags B and<a name="line.812"></a>
-<span class="sourceLineNo">813</span>   * then Thread A and Thread B continue along on their merry way. Pause and signalling 'zigzags'<a name="line.813"></a>
-<span class="sourceLineNo">814</span>   * between the two participating threads. We use two latches -- one the inverse of the other --<a name="line.814"></a>
-<span class="sourceLineNo">815</span>   * pausing and signaling when states are achieved.<a name="line.815"></a>
-<span class="sourceLineNo">816</span>   * &lt;p&gt;<a name="line.816"></a>
-<span class="sourceLineNo">817</span>   * To start up the drama, Thread A creates an instance of this class each time it would do this<a name="line.817"></a>
-<span class="sourceLineNo">818</span>   * zigzag dance and passes it to Thread B (these classes use Latches so it is one shot only).<a name="line.818"></a>
-<span class="sourceLineNo">819</span>   * Thread B notices the new instance (via reading a volatile reference or how ever) and it starts<a name="line.819"></a>
-<span class="sourceLineNo">820</span>   * to work toward the 'safe point'. Thread A calls {@link #waitSafePoint(SyncFuture)} when it cannot proceed<a name="line.820"></a>
-<span class="sourceLineNo">821</span>   * until the Thread B 'safe point' is attained. Thread A will be held inside in<a name="line.821"></a>
-<span class="sourceLineNo">822</span>   * {@link #waitSafePoint(SyncFuture)} until Thread B reaches the 'safe point'. Once there, Thread B frees<a name="line.822"></a>
-<span class="sourceLineNo">823</span>   * Thread A by calling {@link #safePointAttained()}. Thread A now knows Thread B is at the 'safe<a name="line.823"></a>
-<span class="sourceLineNo">824</span>   * point' and that it is holding there (When Thread B calls {@link #safePointAttained()} it blocks<a name="line.824"></a>
-<span class="sourceLineNo">825</span>   * here until Thread A calls {@link #releaseSafePoint()}). Thread A proceeds to do what it needs<a name="line.825"></a>
-<span class="sourceLineNo">826</span>   * to do while Thread B is paused. When finished, it lets Thread B lose by calling<a name="line.826"></a>
-<span class="sourceLineNo">827</span>   * {@link #releaseSafePoint()} and away go both Threads again.<a name="line.827"></a>
-<span class="sourceLineNo">828</span>   */<a name="line.828"></a>
-<span class="sourceLineNo">829</span>  static class SafePointZigZagLatch {<a name="line.829"></a>
-<span class="sourceLineNo">830</span>    /**<a name="line.830"></a>
-<span class="sourceLineNo">831</span>     * Count down this latch when safe point attained.<a name="line.831"></a>
-<span class="sourceLineNo">832</span>     */<a name="line.832"></a>
-<span class="sourceLineNo">833</span>    private volatile CountDownLatch safePointAttainedLatch = new CountDownLatch(1);<a name="line.833"></a>
+<span class="sourceLineNo">800</span>    Path archiveDir = new Path(baseDir, HConstants.HREGION_OLDLOGDIR_NAME);<a name="line.800"></a>
+<span class="sourceLineNo">801</span>    if (conf.getBoolean(AbstractFSWALProvider.SEPARATE_OLDLOGDIR,<a name="line.801"></a>
+<span class="sourceLineNo">802</span>      AbstractFSWALProvider.DEFAULT_SEPARATE_OLDLOGDIR)) {<a name="line.802"></a>
+<span class="sourceLineNo">803</span>      archiveDir = new Path(archiveDir, p.getName());<a name="line.803"></a>
+<span class="sourceLineNo">804</span>    }<a name="line.804"></a>
+<span class="sourceLineNo">805</span>    WALSplitter.split(baseDir, p, archiveDir, fs, conf, WALFactory.getInstance(conf));<a name="line.805"></a>
+<span class="sourceLineNo">806</span>  }<a name="line.806"></a>
+<span class="sourceLineNo">807</span><a name="line.807"></a>
+<span class="sourceLineNo">808</span>  /**<a name="line.808"></a>
+<span class="sourceLineNo">809</span>   * This class is used coordinating two threads holding one thread at a 'safe point' while the<a name="line.809"></a>
+<span class="sourceLineNo">810</span>   * orchestrating thread does some work that requires the first thread paused: e.g. holding the WAL<a name="line.810"></a>
+<span class="sourceLineNo">811</span>   * writer while its WAL is swapped out from under it by another thread.<a name="line.811"></a>
+<span class="sourceLineNo">812</span>   * &lt;p&gt;<a name="line.812"></a>
+<span class="sourceLineNo">813</span>   * Thread A signals Thread B to hold when it gets to a 'safe point'. Thread A wait until Thread B<a name="line.813"></a>
+<span class="sourceLineNo">814</span>   * gets there. When the 'safe point' has been attained, Thread B signals Thread A. Thread B then<a name="line.814"></a>
+<span class="sourceLineNo">815</span>   * holds at the 'safe point'. Thread A on notification that Thread B is paused, goes ahead and<a name="line.815"></a>
+<span class="sourceLineNo">816</span>   * does the work it needs to do while Thread B is holding. When Thread A is done, it flags B and<a name="line.816"></a>
+<span class="sourceLineNo">817</span>   * then Thread A and Thread B continue along on their merry way. Pause and signalling 'zigzags'<a name="line.817"></a>
+<span class="sourceLineNo">818</span>   * between the two participating threads. We use two latches -- one the inverse of the other --<a name="line.818"></a>
+<span class="sourceLineNo">819</span>   * pausing and signaling when states are achieved.<a name="line.819"></a>
+<span class="sourceLineNo">820</span>   * &lt;p&gt;<a name="line.820"></a>
+<span class="sourceLineNo">821</span>   * To start up the drama, Thread A creates an instance of this class each time it would do this<a name="line.821"></a>
+<span class="sourceLineNo">822</span>   * zigzag dance and passes it to Thread B (these classes use Latches so it is one shot only).<a name="line.822"></a>
+<span class="sourceLineNo">823</span>   * Thread B notices the new instance (via reading a volatile reference or how ever) and it starts<a name="line.823"></a>
+<span class="sourceLineNo">824</span>   * to work toward the 'safe point'. Thread A calls {@link #waitSafePoint(SyncFuture)} when it cannot proceed<a name="line.824"></a>
+<span class="sourceLineNo">825</span>   * until the Thread B 'safe point' is attained. Thread A will be held inside in<a name="line.825"></a>
+<span class="sourceLineNo">826</span>   * {@link #waitSafePoint(SyncFuture)} until Thread B reaches the 'safe point'. Once there, Thread B frees<a name="line.826"></a>
+<span class="sourceLineNo">827</span>   * Thread A by calling {@link #safePointAttained()}. Thread A now knows Thread B is at the 'safe<a name="line.827"></a>
+<span class="sourceLineNo">828</span>   * point' and that it is holding there (When Thread B calls {@link #safePointAttained()} it blocks<a name="line.828"></a>
+<span class="sourceLineNo">829</span>   * here until Thread A calls {@link #releaseSafePoint()}). Thread A proceeds to do what it needs<a name="line.829"></a>
+<span class="sourceLineNo">830</span>   * to do while Thread B is paused. When finished, it lets Thread B lose by calling<a name="line.830"></a>
+<span class="sourceLineNo">831</span>   * {@link #releaseSafePoint()} and away go both Threads again.<a name="line.831"></a>
+<span class="sourceLineNo">832</span>   */<a name="line.832"></a>
+<span class="sourceLineNo">833</span>  static class SafePointZigZagLatch {<a name="line.833"></a>
 <span class="sourceLineNo">834</span>    /**<a name="line.834"></a>
-<span class="sourceLineNo">835</span>     * Latch to wait on. Will be released when we can proceed.<a name="line.835"></a>
+<span class="sourceLineNo">835</span>     * Count down this latch when safe point attained.<a name="line.835"></a>
 <span class="sourceLineNo">836</span>     */<a name="line.836"></a>
-<span class="sourceLineNo">837</span>    private volatile CountDownLatch safePointReleasedLatch = new CountDownLatch(1);<a name="line.837"></a>
-<span class="sourceLineNo">838</span><a name="line.838"></a>
-<span class="sourceLineNo">839</span>    private void checkIfSyncFailed(SyncFuture syncFuture) throws FailedSyncBeforeLogCloseException {<a name="line.839"></a>
-<span class="sourceLineNo">840</span>      if (syncFuture.isThrowable()) {<a name="line.840"></a>
-<span class="sourceLineNo">841</span>        throw new FailedSyncBeforeLogCloseException(syncFuture.getThrowable());<a name="line.841"></a>
-<span class="sourceLineNo">842</span>      }<a name="line.842"></a>
-<span class="sourceLineNo">843</span>    }<a name="line.843"></a>
-<span class="sourceLineNo">844</span><a name="line.844"></a>
-<span class="sourceLineNo">845</span>    /**<a name="line.845"></a>
-<span class="sourceLineNo">846</span>     * For Thread A to call when it is ready to wait on the 'safe point' to be attained. Thread A<a name="line.846"></a>
-<span class="sourceLineNo">847</span>     * will be held in here until Thread B calls {@link #safePointAttained()}<a name="line.847"></a>
-<span class="sourceLineNo">848</span>     * @param syncFuture We need this as barometer on outstanding syncs. If it comes home with an<a name="line.848"></a>
-<span class="sourceLineNo">849</span>     *          exception, then something is up w/ our syncing.<a name="line.849"></a>
-<span class="sourceLineNo">850</span>     * @return The passed &lt;code&gt;syncFuture&lt;/code&gt;<a name="line.850"></a>
-<span class="sourceLineNo">851</span>     */<a name="line.851"></a>
-<span class="sourceLineNo">852</span>    SyncFuture waitSafePoint(SyncFuture syncFuture) throws InterruptedException,<a name="line.852"></a>
-<span class="sourceLineNo">853</span>        FailedSyncBeforeLogCloseException {<a name="line.853"></a>
-<span class="sourceLineNo">854</span>      while (!this.safePointAttainedLatch.await(1, TimeUnit.MILLISECONDS)) {<a name="line.854"></a>
-<span class="sourceLineNo">855</span>        checkIfSyncFailed(syncFuture);<a name="line.855"></a>
-<span class="sourceLineNo">856</span>      }<a name="line.856"></a>
-<span class="sourceLineNo">857</span>      checkIfSyncFailed(syncFuture);<a name="line.857"></a>
-<span class="sourceLineNo">858</span>      return syncFuture;<a name="line.858"></a>
-<span class="sourceLineNo">859</span>    }<a name="line.859"></a>
-<span class="sourceLineNo">860</span><a name="line.860"></a>
-<span class="sourceLineNo">861</span>    /**<a name="line.861"></a>
-<span class="sourceLineNo">862</span>     * Called by Thread B when it attains the 'safe point'. In this method, Thread B signals Thread<a name="line.862"></a>
-<span class="sourceLineNo">863</span>     * A it can proceed. Thread B will be held in here until {@link #releaseSafePoint()} is called<a name="line.863"></a>
-<span class="sourceLineNo">864</span>     * by Thread A.<a name="line.864"></a>
-<span class="sourceLineNo">865</span>     */<a name="line.865"></a>
-<span class="sourceLineNo">866</span>    void safePointAttained() throws InterruptedException {<a name="line.866"></a>
-<span class="sourceLineNo">867</span>      this.safePointAttainedLatch.countDown();<a name="line.867"></a>
-<span class="sourceLineNo">868</span>      this.safePointReleasedLatch.await();<a name="line.868"></a>
-<span class="sourceLineNo">869</span>    }<a name="line.869"></a>
-<span class="sourceLineNo">870</span><a name="line.870"></a>
-<span class="sourceLineNo">871</span>    /**<a name="line.871"></a>
-<span class="sourceLineNo">872</span>     * Called by Thread A when it is done with the work it needs to do while Thread B is halted.<a name="line.872"></a>
-<span class="sourceLineNo">873</span>     * This will release the Thread B held in a call to {@link #safePointAttained()}<a name="line.873"></a>
-<span class="sourceLineNo">874</span>     */<a name="line.874"></a>
-<span class="sourceLineNo">875</span>    void releaseSafePoint() {<a name="line.875"></a>
-<span class="sourceLineNo">876</span>      this.safePointReleasedLatch.countDown();<a name="line.876"></a>
-<span class="sourceLineNo">877</span>    }<a name="line.877"></a>
-<span class="sourceLineNo">878</span><a name="line.878"></a>
-<span class="sourceLineNo">879</span>    /**<a name="line.879"></a>
-<span class="sourceLineNo">880</span>     * @return True is this is a 'cocked', fresh instance, and not one that has already fired.<a name="line.880"></a>
-<span class="sourceLineNo">881</span>     */<a name="line.881"></a>
-<span class="sourceLineNo">882</span>    boolean isCocked() {<a name="line.882"></a>
-<span class="sourceLineNo">883</span>      return this.safePointAttainedLatch.getCount() &gt; 0<a name="line.883"></a>
-<span class="sourceLineNo">884</span>          &amp;&amp; this.safePointReleasedLatch.getCount() &gt; 0;<a name="line.884"></a>
-<span class="sourceLineNo">885</span>    }<a name="line.885"></a>
-<span class="sourceLineNo">886</span>  }<a name="line.886"></a>
-<span class="sourceLineNo">887</span><a name="line.887"></a>
-<span class="sourceLineNo">888</span>  /**<a name="line.888"></a>
-<span class="sourceLineNo">889</span>   * Handler that is run by the disruptor ringbuffer consumer. Consumer is a SINGLE<a name="line.889"></a>
-<span class="sourceLineNo">890</span>   * 'writer/appender' thread. Appends edits and starts up sync runs. Tries its best to batch up<a name="line.890"></a>
-<span class="sourceLineNo">891</span>   * syncs. There is no discernible benefit batching appends so we just append as they come in<a name="line.891"></a>
-<span class="sourceLineNo">892</span>   * because it simplifies the below implementation. See metrics for batching effectiveness (In<a name="line.892"></a>
-<span class="sourceLineNo">893</span>   * measurement, at 100 concurrent handlers writing 1k, we are batching &gt; 10 appends and 10 handler<a name="line.893"></a>
-<span class="sourceLineNo">894</span>   * sync invocations for every actual dfsclient sync call; at 10 concurrent handlers, YMMV).<a name="line.894"></a>
-<span class="sourceLineNo">895</span>   * &lt;p&gt;<a name="line.895"></a>
-<span class="sourceLineNo">896</span>   * Herein, we have an array into which we store the sync futures as they come in. When we have a<a name="line.896"></a>
-<span class="sourceLineNo">897</span>   * 'batch', we'll then pass what we have collected to a SyncRunner thread to do the filesystem<a name="line.897"></a>
-<span class="sourceLineNo">898</span>   * sync. When it completes, it will then call {@link SyncFuture#done(long, Throwable)} on each of<a name="line.898"></a>
-<span class="sourceLineNo">899</span>   * SyncFutures in the batch to release blocked Handler threads.<a name="line.899"></a>
-<span class="sourceLineNo">900</span>   * &lt;p&gt;<a name="line.900"></a>
-<span class="sourceLineNo">901</span>   * I've tried various effects to try and make latencies low while keeping throughput high. I've<a name="line.901"></a>
-<span class="sourceLineNo">902</span>   * tried keeping a single Queue of SyncFutures in this class appending to its tail as the syncs<a name="line.902"></a>
-<span class="sourceLineNo">903</span>   * coming and having sync runner threads poll off the head to 'finish' completed SyncFutures. I've<a name="line.903"></a>
-<span class="sourceLineNo">904</span>   * tried linkedlist, and various from concurrent utils whether LinkedBlockingQueue or<a name="line.904"></a>
-<span class="sourceLineNo">905</span>   * ArrayBlockingQueue, etc. The more points of synchronization, the more 'work' (according to<a name="line.905"></a>
-<span class="sourceLineNo">906</span>   * 'perf stats') that has to be done; small increases in stall percentages seem to have a big<a name="line.906"></a>
-<span class="sourceLineNo">907</span>   * impact on throughput/latencies. The below model where we have an array into which we stash the<a name="line.907"></a>
-<span class="sourceLineNo">908</span>   * syncs and then hand them off to the sync thread seemed like a decent compromise. See HBASE-8755<a name="line.908"></a>
-<span class="sourceLineNo">909</span>   * for more detail.<a name="line.909"></a>
-<span class="sourceLineNo">910</span>   */<a name="line.910"></a>
-<span class="sourceLineNo">911</span>  class RingBufferEventHandler implements EventHandler&lt;RingBufferTruck&gt;, LifecycleAware {<a name="line.911"></a>
-<span class="sourceLineNo">912</span>    private final SyncRunner[] syncRunners;<a name="line.912"></a>
-<span class="sourceLineNo">913</span>    private final SyncFuture[] syncFutures;<a name="line.913"></a>
-<span class="sourceLineNo">914</span>    // Had 'interesting' issues when this was non-volatile. On occasion, we'd not pass all<a name="line.914"></a>
-<span class="sourceLineNo">915</span>    // syncFutures to the next sync'ing thread.<a name="line.915"></a>
-<span class="sourceLineNo">916</span>    private volatile int syncFuturesCount = 0;<a name="line.916"></a>
-<span class="sourceLineNo">917</span>    private volatile SafePointZigZagLatch zigzagLatch;<a name="line.917"></a>
-<span class="sourceLineNo">918</span>    /**<a name="line.918"></a>
-<span class="sourceLineNo">919</span>     * Set if we get an exception appending or syncing so that all subsequence appends and syncs on<a name="line.919"></a>
-<span class="sourceLineNo">920</span>     * this WAL fail until WAL is replaced.<a name="line.920"></a>
-<span class="sourceLineNo">921</span>     */<a name="line.921"></a>
-<span class="sourceLineNo">922</span>    private Exception exception = null;<a name="line.922"></a>
-<span class="sourceLineNo">923</span>    /**<a name="line.923"></a>
-<span class="sourceLineNo">924</span>     * Object to block on while waiting on safe point.<a name="line.924"></a>
+<span class="sourceLineNo">837</span>    private volatile CountDownLatch safePointAttainedLatch = new CountDownLatch(1);<a name="line.837"></a>
+<span class="sourceLineNo">838</span>    /**<a name="line.838"></a>
+<span class="sourceLineNo">839</span>     * Latch to wait on. Will be released when we can proceed.<a name="line.839"></a>
+<span class="sourceLineNo">840</span>     */<a name="line.840"></a>
+<span class="sourceLineNo">841</span>    private volatile CountDownLatch safePointReleasedLatch = new CountDownLatch(1);<a name="line.841"></a>
+<span class="sourceLineNo">842</span><a name="line.842"></a>
+<span class="sourceLineNo">843</span>    private void checkIfSyncFailed(SyncFuture syncFuture) throws FailedSyncBeforeLogCloseException {<a name="line.843"></a>
+<span class="sourceLineNo">844</span>      if (syncFuture.isThrowable()) {<a name="line.844"></a>
+<span class="sourceLineNo">845</span>        throw new FailedSyncBeforeLogCloseException(syncFuture.getThrowable());<a name="line.845"></a>
+<span class="sourceLineNo">846</span>      }<a name="line.846"></a>
+<span class="sourceLineNo">847</span>    }<a name="line.847"></a>
+<span class="sourceLineNo">848</span><a name="line.848"></a>
+<span class="sourceLineNo">849</span>    /**<a name="line.849"></a>
+<span class="sourceLineNo">850</span>     * For Thread A to call when it is ready to wait on the 'safe point' to be attained. Thread A<a name="line.850"></a>
+<span class="sourceLineNo">851</span>     * will be held in here until Thread B calls {@link #safePointAttained()}<a name="line.851"></a>
+<span class="sourceLineNo">852</span>     * @param syncFuture We need this as barometer on outstanding syncs. If it comes home with an<a name="line.852"></a>
+<span class="sourceLineNo">853</span>     *          exception, then something is up w/ our syncing.<a name="line.853"></a>
+<span class="sourceLineNo">854</span>     * @return The passed &lt;code&gt;syncFuture&lt;/code&gt;<a name="line.854"></a>
+<span class="sourceLineNo">855</span>     */<a name="line.855"></a>
+<span class="sourceLineNo">856</span>    SyncFuture waitSafePoint(SyncFuture syncFuture) throws InterruptedException,<a name="line.856"></a>
+<span class="sourceLineNo">857</span>        FailedSyncBeforeLogCloseException {<a name="line.857"></a>
+<span class="sourceLineNo">858</span>      while (!this.safePointAttainedLatch.await(1, TimeUnit.MILLISECONDS)) {<a name="line.858"></a>
+<span class="sourceLineNo">859</span>        checkIfSyncFailed(syncFuture);<a name="line.859"></a>
+<span class="sourceLineNo">860</span>      }<a name="line.860"></a>
+<span class="sourceLineNo">861</span>      checkIfSyncFailed(syncFuture);<a name="line.861"></a>
+<span class="sourceLineNo">862</span>      return syncFuture;<a name="line.862"></a>
+<span class="sourceLineNo">863</span>    }<a name="line.863"></a>
+<span class="sourceLineNo">864</span><a name="line.864"></a>
+<span class="sourceLineNo">865</span>    /**<a name="line.865"></a>
+<span class="sourceLineNo">866</span>     * Called by Thread B when it attains the 'safe point'. In this method, Thread B signals Thread<a name="line.866"></a>
+<span class="sourceLineNo">867</span>     * A it can proceed. Thread B will be held in here until {@link #releaseSafePoint()} is called<a name="line.867"></a>
+<span class="sourceLineNo">868</span>     * by Thread A.<a name="line.868"></a>
+<span class="sourceLineNo">869</span>     */<a name="line.869"></a>
+<span class="sourceLineNo">870</span>    void safePointAttained() throws InterruptedException {<a name="line.870"></a>
+<span class="sourceLineNo">871</span>      this.safePointAttainedLatch.countDown();<a name="line.871"></a>
+<span class="sourceLineNo">872</span>      this.safePointReleasedLatch.await();<a name="line.872"></a>
+<span class="sourceLineNo">873</span>    }<a name="line.873"></a>
+<span class="sourceLineNo">874</span><a name="line.874"></a>
+<span class="sourceLineNo">875</span>    /**<a name="line.875"></a>
+<span class="sourceLineNo">876</span>     * Called by Thread A when it is done with the work it needs to do while Thread B is halted.<a name="line.876"></a>
+<span class="sourceLineNo">877</span>     * This will release the Thread B held in a call to {@link #safePointAttained()}<a name="line.877"></a>
+<span class="sourceLineNo">878</span>     */<a name="line.878"></a>
+<span class="sourceLineNo">879</span>    void releaseSafePoint() {<a name="line.879"></a>
+<span class="sourceLineNo">880</span>      this.safePointReleasedLatch.countDown();<a name="line.880"></a>
+<span class="sourceLineNo">881</span>    }<a name="line.881"></a>
+<span class="sourceLineNo">882</span><a name="line.882"></a>
+<span class="sourceLineNo">883</span>    /**<a name="line.883"></a>
+<span class="sourceLineNo">884</span>     * @return True is this is a 'cocked', fresh instance, and not one that has already fired.<a name="line.884"></a>
+<span class="sourceLineNo">885</span>     */<a name="line.885"></a>
+<span class="sourceLineNo">886</span>    boolean isCocked() {<a name="line.886"></a>
+<span class="sourceLineNo">887</span>      return this.safePointAttainedLatch.getCount() &gt; 0<a name="line.887"></a>
+<span class="sourceLineNo">888</span>          &amp;&amp; this.safePointReleasedLatch.getCount() &gt; 0;<a name="line.888"></a>
+<span class="sourceLineNo">889</span>    }<a name="line.889"></a>
+<span class="sourceLineNo">890</span>  }<a name="line.890"></a>
+<span class="sourceLineNo">891</span><a name="line.891"></a>
+<span class="sourceLineNo">892</span>  /**<a name="line.892"></a>
+<span class="sourceLineNo">893</span>   * Handler that is run by the disruptor ringbuffer consumer. Consumer is a SINGLE<a name="line.893"></a>
+<span class="sourceLineNo">894</span>   * 'writer/appender' thread. Appends edits and starts up sync runs. Tries its best to batch up<a name="line.894"></a>
+<span class="sourceLineNo">895</span>   * syncs. There is no discernible benefit batching appends so we just append as they come in<a name="line.895"></a>
+<span class="sourceLineNo">896</span>   * because it simplifies the below implementation. See metrics for batching effectiveness (In<a name="line.896"></a>
+<span class="sourceLineNo">897</span>   * measurement, at 100 concurrent handlers writing 1k, we are batching &gt; 10 appends and 10 handler<a name="line.897"></a>
+<span class="sourceLineNo">898</span>   * sync invocations for every actual dfsclient sync call; at 10 concurrent handlers, YMMV).<a name="line.898"></a>
+<span class="sourceLineNo">899</span>   * &lt;p&gt;<a name="line.899"></a>
+<span class="sourceLineNo">900</span>   * Herein, we have an array into which we store the sync futures as they come in. When we have a<a name="line.900"></a>
+<span class="sourceLineNo">901</span>   * 'batch', we'll then pass what we have collected to a SyncRunner thread to do the filesystem<a name="line.901"></a>
+<span class="sourceLineNo">902</span>   * sync. When it completes, it will then call {@link SyncFuture#done(long, Throwable)} on each of<a name="line.902"></a>
+<span class="sourceLineNo">903</span>   * SyncFutures in the batch to release blocked Handler threads.<a name="line.903"></a>
+<span class="sourceLineNo">904</span>   * &lt;p&gt;<a name="line.904"></a>
+<span class="sourceLineNo">905</span>   * I've tried various effects to try and make latencies low while keeping throughput high. I've<a name="line.905"></a>
+<span class="sourceLineNo">906</span>   * tried keeping a single Queue of SyncFutures in this class appending to its tail as the syncs<a name="line.906"></a>
+<span class="sourceLineNo">907</span>   * coming and having sync runner threads poll off the head to 'finish' completed SyncFutures. I've<a name="line.907"></a>
+<span class="sourceLineNo">908</span>   * tried linkedlist, and various from concurrent utils whether LinkedBlockingQueue or<a name="line.908"></a>
+<span class="sourceLineNo">909</span>   * ArrayBlockingQueue, etc. The more points of synchronization, the more 'work' (according to<a name="line.909"></a>
+<span class="sourceLineNo">910</span>   * 'perf stats') that has to be done; small increases in stall percentages seem to have a big<a name="line.910"></a>
+<span class="sourceLineNo">911</span>   * impact on throughput/latencies. The below model where we have an array into which we stash the<a name="line.911"></a>
+<span class="sourceLineNo">912</span>   * syncs and then hand them off to the sync thread seemed like a decent compromise. See HBASE-8755<a name="line.912"></a>
+<span class="sourceLineNo">913</span>   * for more detail.<a name="line.913"></a>
+<span class="sourceLineNo">914</span>   */<a name="line.914"></a>
+<span class="sourceLineNo">915</span>  class RingBufferEventHandler implements EventHandler&lt;RingBufferTruck&gt;, LifecycleAware {<a name="line.915"></a>
+<span class="sourceLineNo">916</span>    private final SyncRunner[] syncRunners;<a name="line.916"></a>
+<span class="sourceLineNo">917</span>    private final SyncFuture[] syncFutures;<a name="line.917"></a>
+<span class="sourceLineNo">918</span>    // Had 'interesting' issues when this was non-volatile. On occasion, we'd not pass all<a name="line.918"></a>
+<span class="sourceLineNo">919</span>    // syncFutures to the next sync'ing thread.<a name="line.919"></a>
+<span class="sourceLineNo">920</span>    private volatile int syncFuturesCount = 0;<a name="line.920"></a>
+<span class="sourceLineNo">921</span>    private volatile SafePointZigZagLatch zigzagLatch;<a name="line.921"></a>
+<span class="sourceLineNo">922</span>    /**<a name="line.922"></a>
+<span class="sourceLineNo">923</span>     * Set if we get an exception appending or syncing so that all subsequence appends and syncs on<a name="line.923"></a>
+<span class="sourceLineNo">924</span>     * this WAL fail until WAL is replaced.<a name="line.924"></a>
 <span class="sourceLineNo">925</span>     */<a name="line.925"></a>
-<span class="sourceLineNo">926</span>    private final Object safePointWaiter = new Object();<a name="line.926"></a>
-<span class="sourceLineNo">927</span>    private volatile boolean shutdown = false;<a name="line.927"></a>
-<span class="sourceLineNo">928</span><a name="line.928"></a>
-<span class="sourceLineNo">929</span>    /**<a name="line.929"></a>
-<span class="sourceLineNo">930</span>     * Which syncrunner to use next.<a name="line.930"></a>
-<span class="sourceLineNo">931</span>     */<a name="line.931"></a>
-<span class="sourceLineNo">932</span>    private int syncRunnerIndex;<a name="line.932"></a>
-<span class="sourceLineNo">933</span><a name="line.933"></a>
-<span class="sourceLineNo">934</span>    RingBufferEventHandler(final int syncRunnerCount, final int maxHandlersCount) {<a name="line.934"></a>
-<span class="sourceLineNo">935</span>      this.syncFutures = new SyncFuture[maxHandlersCount];<a name="line.935"></a>
-<span class="sourceLineNo">936</span>      this.syncRunners = new SyncRunner[syncRunnerCount];<a name="line.936"></a>
-<span class="sourceLineNo">937</span>      for (int i = 0; i &lt; syncRunnerCount; i++) {<a name="line.937"></a>
-<span class="sourceLineNo">938</span>        this.syncRunners[i] = new SyncRunner("sync." + i, maxHandlersCount);<a name="line.938"></a>
-<span class="sourceLineNo">939</span>      }<a name="line.939"></a>
-<span class="sourceLineNo">940</span>    }<a name="line.940"></a>
-<span class="sourceLineNo">941</span><a name="line.941"></a>
-<span class="sourceLineNo">942</span>    private void cleanupOutstandingSyncsOnException(final long sequence, final Exception e) {<a name="line.942"></a>
-<span class="sourceLineNo">943</span>      // There could be handler-count syncFutures outstanding.<a name="line.943"></a>
-<span class="sourceLineNo">944</span>      for (int i = 0; i &lt; this.syncFuturesCount; i++) {<a name="line.944"></a>
-<span class="sourceLineNo">945</span>        this.syncFutures[i].done(sequence, e);<a name="line.945"></a>
-<span class="sourceLineNo">946</span>      }<a name="line.946"></a>
-<span class="sourceLineNo">947</span>      this.syncFuturesCount = 0;<a name="line.947"></a>
-<span class="sourceLineNo">948</span>    }<a name="line.948"></a>
-<span class="sourceLineNo">949</span><a name="line.949"></a>
-<span class="sourceLineNo">950</span>    /**<a name="line.950"></a>
-<span class="sourceLineNo">951</span>     * @return True if outstanding sync futures still<a name="line.951"></a>
-<span class="sourceLineNo">952</span>     */<a name="line.952"></a>
-<span class="sourceLineNo">953</span>    private boolean isOutstandingSyncs() {<a name="line.953"></a>
-<span class="sourceLineNo">954</span>      // Look at SyncFutures in the EventHandler<a name="line.954"></a>
-<span class="sourceLineNo">955</span>      for (int i = 0; i &lt; this.syncFuturesCount; i++) {<a name="line.955"></a>
-<span class="sourceLineNo">956</span>        if (!this.syncFutures[i].isDone()) {<a name="line.956"></a>
-<span class="sourceLineNo">957</span>          return true;<a name="line.957"></a>
-<span class="sourceLineNo">958</span>        }<a name="line.958"></a>
-<span class="sourceLineNo">959</span>      }<a name="line.959"></a>
-<span class="sourceLineNo">960</span><a name="line.960"></a>
-<span class="sourceLineNo">961</span>      return false;<a name="line.961"></a>
-<span class="sourceLineNo">962</span>    }<a name="line.962"></a>
-<span class="sourceLineNo">963</span><a name="line.963"></a>
-<span class="sourceLineNo">964</span>    private boolean isOutstandingSyncsFromRunners() {<a name="line.964"></a>
-<span class="sourceLineNo">965</span>      // Look at SyncFutures in the SyncRunners<a name="line.965"></a>
-<span class="sourceLineNo">966</span>      for (SyncRunner syncRunner: syncRunners) {<a name="line.966"></a>
-<span class="sourceLineNo">967</span>        if(syncRunner.isAlive() &amp;&amp; !syncRunner.areSyncFuturesReleased()) {<a name="line.967"></a>
-<span class="sourceLineNo">968</span>          return true;<a name="line.968"></a>
-<span class="sourceLineNo">969</span>        }<a name="line.969"></a>
-<span class="sourceLineNo">970</span>      }<a name="line.970"></a>
-<span class="sourceLineNo">971</span>      return false;<a name="line.971"></a>
-<span class="sourceLineNo">972</span>    }<a name="line.972"></a>
-<span class="sourceLineNo">973</span><a name="line.973"></a>
-<span class="sourceLineNo">974</span>    @Override<a name="line.974"></a>
-<span class="sourceLineNo">975</span>    // We can set endOfBatch in the below method if at end of our this.syncFutures array<a name="line.975"></a>
-<span class="sourceLineNo">976</span>    public void onEvent(final RingBufferTruck truck, final long sequence, boolean endOfBatch)<a name="line.976"></a>
-<span class="sourceLineNo">977</span>        throws Exception {<a name="line.977"></a>
-<span class="sourceLineNo">978</span>      // Appends and syncs are coming in order off the ringbuffer. We depend on this fact. We'll<a name="line.978"></a>
-<span class="sourceLineNo">979</span>      // add appends to dfsclient as they come in. Batching appends doesn't give any significant<a name="line.979"></a>
-<span class="sourceLineNo">980</span>      // benefit on measurement. Handler sync calls we will batch up. If we get an exception<a name="line.980"></a>
-<span class="sourceLineNo">981</span>      // appending an edit, we fail all subsequent appends and syncs with the same exception until<a name="line.981"></a>
-<span class="sourceLineNo">982</span>      // the WAL is reset. It is important that we not short-circuit and exit early this method.<a name="line.982"></a>
-<span class="sourceLineNo">983</span>      // It is important that we always go through the attainSafePoint on the end. Another thread,<a name="line.983"></a>
-<span class="sourceLineNo">984</span>      // the log roller may be waiting on a signal from us here and will just hang without it.<a name="line.984"></a>
-<span class="sourceLineNo">985</span><a name="line.985"></a>
-<span class="sourceLineNo">986</span>      try {<a name="line.986"></a>
-<span class="sourceLineNo">987</span>        if (truck.type() == RingBufferTruck.Type.SYNC) {<a name="line.987"></a>
-<span class="sourceLineNo">988</span>          this.syncFutures[this.syncFuturesCount++] = truck.unloadSync();<a name="line.988"></a>
-<span class="sourceLineNo">989</span>          // Force flush of syncs if we are carrying a full complement of syncFutures.<a name="line.989"></a>
-<span class="sourceLineNo">990</span>          if (this.syncFuturesCount == this.syncFutures.length) {<a name="line.990"></a>
-<span class="sourceLineNo">991</span>            endOfBatch = true;<a name="line.991"></a>
-<span class="sourceLineNo">992</span>          }<a name="line.992"></a>
-<span class="sourceLineNo">993</span>        } else if (truck.type() == RingBufferTruck.Type.APPEND) {<a name="line.993"></a>
-<span class="sourceLineNo">994</span>          FSWALEntry entry = truck.unloadAppend();<a name="line.994"></a>
-<span class="sourceLineNo">995</span>          TraceScope scope = Trace.continueSpan(entry.detachSpan());<a name="line.995"></a>
-<span class="sourceLineNo">996</span>          try {<a name="line.996"></a>
-<span class="sourceLineNo">997</span><a name="line.997"></a>
-<span class="sourceLineNo">998</span>            if (this.exception != null) {<a name="line.998"></a>
-<span class="sourceLineNo">999</span>              // Return to keep processing events coming off the ringbuffer<a name="line.999"></a>
-<span class="sourceLineNo">1000</span>              return;<a name="line.1000"></a>
-<span class="sourceLineNo">1001</span>            }<a name="line.1001"></a>
-<span class="sourceLineNo">1002</span>            append(entry);<a name="line.1002"></a>
-<span class="sourceLineNo">1003</span>          } catch (Exception e) {<a name="line.1003"></a>
-<span class="sourceLineNo">1004</span>            // Failed append. Record the exception.<a name="line.1004"></a>
-<span class="sourceLineNo">1005</span>            this.exception = e;<a name="line.1005"></a>
-<span class="sourceLineNo">1006</span>            // invoking cleanupOutstandingSyncsOnException when append failed with exception,<a name="line.1006"></a>
-<span class="sourceLineNo">1007</span>            // it will cleanup existing sync requests recorded in syncFutures but not offered to SyncRunner yet,<a name="line.1007"></a>
-<span class="sourceLineNo">1008</span>            // so there won't be any sync future left over if no further truck published to disruptor.<a name="line.1008"></a>
-<span class="sourceLineNo">1009</span>            cleanupOutstandingSyncsOnException(sequence,<a name="line.1009"></a>
-<span class="sourceLineNo">1010</span>                this.exception instanceof DamagedWALException ? this.exception<a name="line.1010"></a>
-<span class="sourceLineNo">1011</span>                    : new DamagedWALException("On sync", this.exception));<a name="line.1011"></a>
-<span class="sourceLineNo">1012</span>            // Return to keep processing events coming off the ringbuffer<a name="line.1012"></a>
-<span class="sourceLineNo">1013</span>            return;<a name="line.1013"></a>
-<span class="sourceLineNo">1014</span>          } finally {<a name="line.1014"></a>
-<span class="sourceLineNo">1015</span>            assert scope == NullScope.INSTANCE || !scope.isDetached();<a name="line.1015"></a>
-<span class="sourceLineNo">1016</span>            scope.close(); // append scope is complete<a name="line.1016"></a>
-<span class="sourceLineNo">1017</span>          }<a name="line.1017"></a>
-<span class="sourceLineNo">1018</span>        } else {<a name="line.1018"></a>
-<span class="sourceLineNo">1019</span>          // What is this if not an append or sync. Fail all up to this!!!<a name="line.1019"></a>
-<span class="sourceLineNo">1020</span>          cleanupOutstandingSyncsOnException(sequence,<a name="line.1020"></a>
-<span class="sourceLineNo">1021</span>            new IllegalStateException("Neither append nor sync"));<a name="line.1021"></a>
-<span class="sourceLineNo">1022</span>          // Return to keep processing.<a name="line.1022"></a>
-<span class="sourceLineNo">1023</span>          return;<a name="line.1023"></a>
-<span class="sourceLineNo">1024</span>        }<a name="line.1024"></a>
-<span class="sourceLineNo">1025</span><a name="line.1025"></a>
-<span class="sourceLineNo">1026</span>        // TODO: Check size and if big go ahead and call a sync if we have enough data.<a name="line.1026"></a>
-<span class="sourceLineNo">1027</span>        // This is a sync. If existing exception, fall through. Else look to see if batch.<a name="line.1027"></a>
-<span class="sourceLineNo">1028</span>        if (this.exception == null) {<a name="line.1028"></a>
-<span class="sourceLineNo">1029</span>          // If not a batch, return to consume more events from the ring buffer before proceeding;<a name="line.1029"></a>
-<span class="sourceLineNo">1030</span>          // we want to get up a batch of syncs and appends before we go do a filesystem sync.<a name="line.1030"></a>
-<span class="sourceLineNo">1031</span>          if (!endOfBatch || this.syncFuturesCount &lt;= 0) {<a name="line.1031"></a>
-<span class="sourceLineNo">1032</span>            return;<a name="line.1032"></a>
-<span class="sourceLineNo">1033</span>          }<a name="line.1033"></a>
-<span class="sourceLineNo">1034</span>          // syncRunnerIndex is bound to the range [0, Integer.MAX_INT - 1] as follows:<a name="line.1034"></a>
-<span class="sourceLineNo">1035</span>          //   * The maximum value possible for syncRunners.length is Integer.MAX_INT<a name="line.1035"></a>
-<span class="sourceLineNo">1036</span>          //   * syncRunnerIndex starts at 0 and is incremented only here<a name="line.1036"></a>
-<span class="sourceLineNo">1037</span>          //   * after the increment, the value is bounded by the '%' operator to<a name="line.1037"></a>
-<span class="sourceLineNo">1038</span>          //     [0, syncRunners.length), presuming the value was positive prior to<a name="line.1038"></a>
-<span class="sourceLineNo">1039</span>          //     the '%' operator.<a name="line.1039"></a>
-<span class="sourceLineNo">1040</span>          //   * after being bound to [0, Integer.MAX_INT - 1], the new value is stored in<a name="line.1040"></a>
-<span class="sourceLineNo">1041</span>          //     syncRunnerIndex ensuring that it can't grow without bound and overflow.<a name="line.1041"></a>
-<span class="sourceLineNo">1042</span>          //   * note that the value after the increment must be positive, because the most it<a name="line.1042"></a>
-<span class="sourceLineNo">1043</span>          //     could have been prior was Integer.MAX_INT - 1 and we only increment by 1.<a name="line.1043"></a>
-<span class="sourceLineNo">1044</span>          this.syncRunnerIndex = (this.syncRunnerIndex + 1) % this.syncRunners.length;<a name="line.1044"></a>
-<span class="sourceLineNo">1045</span>          try {<a name="line.1045"></a>
-<span class="sourceLineNo">1046</span>            // Below expects that the offer 'transfers' responsibility for the outstanding syncs to<a name="line.1046"></a>
-<span class="sourceLineNo">1047</span>            // the syncRunner. We should never get an exception in here.<a name="line.1047"></a>
-<span class="sourceLineNo">1048</span>            this.syncRunners[this.syncRunnerIndex].offer(sequence, this.syncFutures,<a name="line.1048"></a>
-<span class="sourceLineNo">1049</span>              this.syncFuturesCount);<a name="line.1049"></a>
-<span class="sourceLineNo">1050</span>          } catch (Exception e) {<a name="line.1050"></a>
-<span class="sourceLineNo">1051</span>            // Should NEVER get here.<a name="line.1051"></a>
-<span class="sourceLineNo">1052</span>            requestLogRoll();<a name="line.1052"></a>
-<span class="sourceLineNo">1053</span>            this.exception = new DamagedWALException("Failed offering sync", e);<a name="line.1053"></a>
-<span class="sourceLineNo">1054</span>          }<a name="line.1054"></a>
-<span class="sourceLineNo">1055</span>        }<a name="line.1055"></a>
-<span class="sourceLineNo">1056</span>        // We may have picked up an exception above trying to offer sync<a name="line.1056"></a>
-<span class="sourceLineNo">1057</span>        if (this.exception != null) {<a name="line.1057"></a>
-<span class="sourceLineNo">1058</span>          cleanupOutstandingSyncsOnException(sequence, this.exception instanceof DamagedWALException<a name="line.1058"></a>
-<span class="sourceLineNo">1059</span>              ? this.exception : new DamagedWALException("On sync", this.exception));<a name="line.1059"></a>
-<span class="sourceLineNo">1060</span>        }<a name="line.1060"></a>
-<span class="sourceLineNo">1061</span>        attainSafePoint(sequence);<a name="line.1061"></a>
-<span class="sourceLineNo">1062</span>        this.syncFuturesCount = 0;<a name="line.1062"></a>
-<span class="sourceLineNo">1063</span>      } catch (Throwable t) {<a name="line.1063"></a>
-<span class="sourceLineNo">1064</span>        LOG.error("UNEXPECTED!!! syncFutures.length=" + this.syncFutures.length, t);<a name="line.1064"></a>
-<span class="sourceLineNo">1065</span>      }<a name="line.1065"></a>
-<span class="sourceLineNo">1066</span>    }<a name="line.1066"></a>
-<span class="sourceLineNo">1067</span><a name="line.1067"></a>
-<span class="sourceLineNo">1068</span>    SafePointZigZagLatch attainSafePoint() {<a name="line.1068"></a>
-<span class="sourceLineNo">1069</span>      this.zigzagLatch = new SafePointZigZagLatch();<a name="line.1069"></a>
-<span class="sourceLineNo">1070</span>      return this.zigzagLatch;<a name="line.1070"></a>
-<span class="sourceLineNo">1071</span>    }<a name="line.1071"></a>
-<span class="sourceLineNo">1072</span><a name="line.1072"></a>
-<span class="sourceLineNo">1073</span>    /**<a name="line.1073"></a>
-<span class="sourceLineNo">1074</span>     * Check if we should attain safe point. If so, go there and then wait till signalled before we<a name="line.1074"></a>
-<span class="sourceLineNo">1075</span>     * proceeding.<a name="line.1075"></a>
-<span class="sourceLineNo">1076</span>     */<a name="line.1076"></a>
-<span class="sourceLineNo">1077</span>    private void attainSafePoint(final long currentSequence) {<a name="line.1077"></a>
-<span class="sourceLineNo">1078</span>      if (this.zigzagLatch == null || !this.zigzagLatch.isCocked()) {<a name="line.1078"></a>
-<span class="sourceLineNo">1079</span>        return;<a name="line.1079"></a>
-<span class="sourceLineNo">1080</span>      }<a name="line.1080"></a>
-<span class="sourceLineNo">1081</span>      // If here, another thread is waiting on us to get to safe point. Don't leave it hanging.<a name="line.1081"></a>
-<span class="sourceLineNo">1082</span>      beforeWaitOnSafePoint();<a name="line.1082"></a>
-<span class="sourceLineNo">1083</span>      try {<a name="line.1083"></a>
-<span class="sourceLineNo">1084</span>        // Wait on outstanding syncers; wait for them to finish syncing (unless we've been<a name="line.1084"></a>
-<span class="sourceLineNo">1085</span>        // shutdown or unless our latch has been thrown because we have been aborted or unless<a name="line.1085"></a>
-<span class="sourceLineNo">1086</span>        // this WAL is broken and we can't get a sync/append to complete).<a name="line.1086"></a>
-<span class="sourceLineNo">1087</span>        while ((!this.shutdown &amp;&amp; this.zigzagLatch.isCocked()<a name="line.1087"></a>
-<span class="sourceLineNo">1088</span>            &amp;&amp; highestSyncedTxid.get() &lt; currentSequence &amp;&amp;<a name="line.1088"></a>
-<span class="sourceLineNo">1089</span>            // We could be in here and all syncs are failing or failed. Check for this. Otherwise<a name="line.1089"></a>
-<span class="sourceLineNo">1090</span>            // we'll just be stuck here for ever. In other words, ensure there syncs running.<a name="line.1090"></a>
-<span class="sourceLineNo">1091</span>            isOutstandingSyncs())<a name="line.1091"></a>
-<span class="sourceLineNo">1092</span>            // Wait for all SyncRunners to finish their work so that we can replace the writer<a name="line.1092"></a>
-<span class="sourceLineNo">1093</span>            || isOutstandingSyncsFromRunners()) {<a name="line.1093"></a>
-<span class="sourceLineNo">1094</span>          synchronized (this.safePointWaiter) {<a name="line.1094"></a>
-<span class="sourceLineNo">1095</span>            this.safePointWaiter.wait(0, 1);<a name="line.1095"></a>
-<span class="sourceLineNo">1096</span>          }<a name="line.1096"></a>
-<span class="sourceLineNo">1097</span>        }<a name="line.1097"></a>
-<span class="sourceLineNo">1098</span>        // Tell waiting thread we've attained safe point. Can clear this.throwable if set here<a name="line.1098"></a>
-<span class="sourceLineNo">1099</span>        // because we know that next event through the ringbuffer will be going to a new WAL<a name="line.1099"></a>
-<span class="sourceLineNo">1100</span>        // after we do the zigzaglatch dance.<a name="line.1100"></a>
-<span class="sourceLineNo">1101</span>        this.exception = null;<a name="line.1101"></a>
-<span class="sourceLineNo">1102</span>        this.zigzagLatch.safePointAttained();<a name="line.1102"></a>
-<span class="sourceLineNo">1103</span>      } catch (InterruptedException e) {<a name="line.1103"></a>
-<span class="sourceLineNo">1104</span>        LOG.warn("Interrupted ", e);<a name="line.1104"></a>
-<span class="sourceLineNo">1105</span>        Thread.currentThread().interrupt();<a name="line.1105"></a>
-<span class="sourceLineNo">1106</span>      }<a name="line.1106"></a>
-<span class="sourceLineNo">1107</span>    }<a name="line.1107"></a>
-<span class="sourceLineNo">1108</span><a name="line.1108"></a>
-<span class="sourceLineNo">1109</span>    /**<a name="line.1109"></a>
-<span class="sourceLineNo">1110</span>     * Append to the WAL. Does all CP and WAL listener calls.<a name="line.1110"></a>
-<span class="sourceLineNo">1111</span>     */<a name="line.1111"></a>
-<span class="sourceLineNo">1112</span>    void append(final FSWALEntry entry) throws Exception {<a name="line.1112"></a>
-<span class="sourceLineNo">1113</span>      try {<a name="line.1113"></a>
-<span class="sourceLineNo">1114</span>        FSHLog.this.append(writer, entry);<a name="line.1114"></a>
-<span class="sourceLineNo">1115</span>      } catch (Exception e) {<a name="line.1115"></a>
-<span class="sourceLineNo">1116</span>        String msg = "Append sequenceId=" + entry.getKey().getSequenceId()<a name="line.1116"></a>
-<span class="sourceLineNo">1117</span>            + ", requesting roll of WAL";<a name="line.1117"></a>
-<span class="sourceLineNo">1118</span>        LOG.warn(msg, e);<a name="line.1118"></a>
-<span class="sourceLineNo">1119</span>        requestLogRoll();<a name="line.1119"></a>
-<span class="sourceLineNo">1120</span>        throw new DamagedWALException(msg, e);<a name="line.1120"></a>
-<span class="sourceLineNo">1121</span>      }<a name="line.1121"></a>
-<span class="sourceLineNo">1122</span>    }<a name="line.1122"></a>
-<span class="sourceLineNo">1123</span><a name="line.1123"></a>
-<span class="sourceLineNo">1124</span>    @Override<a name="line.1124"></a>
-<span class="sourceLineNo">1125</span>    public void onStart() {<a name="line.1125"></a>
-<span class="sourceLineNo">1126</span>      for (SyncRunner syncRunner : this.syncRunners) {<a name="line.1126"></a>
-<span class="sourceLineNo">1127</span>        syncRunner.start();<a name="line.1127"></a>
-<span class="sourceLineNo">1128</span>      }<a name="line.1128"></a>
-<span class="sourceLineNo">1129</span>    }<a name="line.1129"></a>
-<span class="sourceLineNo">1130</span><a name="line.1130"></a>
-<span class="sourceLineNo">1131</span>    @Override<a name="line.1131"></a>
-<span class="sourceLineNo">1132</span>    public void onShutdown() {<a name="line.1132"></a>
-<span class="sourceLineNo">1133</span>      for (SyncRunner syncRunner : this.syncRunners) {<a name="line.1133"></a>
-<span class="sourceLineNo">1134</span>        syncRunner.interrupt();<a name="line.1134"></a>
-<span class="sourceLineNo">1135</span>      }<a name="line.1135"></a>
-<span class="sourceLineNo">1136</span>    }<a name="line.1136"></a>
-<span class="sourceLineNo">1137</span>  }<a name="line.1137"></a>
-<span class="sourceLineNo">1138</span><a name="line.1138"></a>
-<span class="sourceLineNo">1139</span>  private static void usage() {<a name="line.1139"></a>
-<span class="sourceLineNo">1140</span>    System.err.println("Usage: FSHLog &lt;ARGS&gt;");<a name="line.1140"></a>
-<span class="sourceLineNo">1141</span>    System.err.println("Arguments:");<a name="line.1141"></a>
-<span class="sourceLineNo">1142</span>    System.err.println(" --dump  Dump textual representation of passed one or more files");<a name="line.1142"></a>
-<span class="sourceLineNo">1143</span>    System.err.println("         For example: "<a name="line.1143"></a>
-<span class="sourceLineNo">1144</span>        + "FSHLog --dump hdfs://example.com:9000/hbase/.logs/MACHINE/LOGFILE");<a name="line.1144"></a>
-<span class="sourceLineNo">1145</span>    System.err.println(" --split Split the passed directory of WAL logs");<a name="line.1145"></a>
-<span class="sourceLineNo">1146</span>    System.err.println(<a name="line.1146"></a>
-<span class="sourceLineNo">1147</span>      "         For example: " + "FSHLog --split hdfs://example.com:9000/hbase/.logs/DIR");<a name="line.1147"></a>
-<span class="sourceLineNo">1148</span>  }<a name="line.1148"></a>
-<span class="sourceLineNo">1149</span><a name="line.1149"></a>
-<span class="sourceLineNo">1150</span>  /**<a name="line.1150"></a>
-<span class="sourceLineNo">1151</span>   * Pass one or more log file names and it will either dump out a text version on<a name="line.1151"></a>
-<span class="sourceLineNo">1152</span>   * &lt;code&gt;stdout&lt;/code&gt; or split the specified log files.<a name="line.1152"></a>
-<span class="sourceLineNo">1153</span>   */<a name="line.1153"></a>
-<span class="sourceLineNo">1154</span>  public static void main(String[] args) throws IOException {<a name="line.1154"></a>
-<span class="sourceLineNo">1155</span>    if (args.length &lt; 2) {<a name="line.1155"></a>
-<span class="sourceLineNo">1156</span>      usage();<a name="line.1156"></a>
-<span class="sourceLineNo">1157</span>      System.exit(-1);<a name="line.1157"></a>
-<span class="sourceLineNo">1158</span>    }<a name="line.1158"></a>
-<span class="sourceLineNo">1159</span>    // either dump using the WALPrettyPrinter or split, depending on args<a name="line.1159"></a>
-<span class="sourceLineNo">1160</span>    if (args[0].compareTo("--dump") == 0) {<a name="line.1160"></a>
-<span class="sourceLineNo">1161</span>      WALPrettyPrinter.run(Arrays.copyOfRange(args, 1, args.length));<a name="line.1161"></a>
-<span class="sourceLineNo">1162</span>    } else if (args[0].compareTo("--perf") == 0) {<a name="line.1162"></a>
-<span class="sourceLineNo">1163</span>      LOG.fatal("Please use the WALPerformanceEvaluation tool instead. i.e.:");<a name="line.1163"></a>
-<span class="sourceLineNo">1164</span>      LOG.fatal(<a name="line.1164"></a>
-<span class="sourceLineNo">1165</span>        "\thbase org.apache.hadoop.hbase.wal.WALPerformanceEvaluation --iterations " + args[1]);<a name="line.1165"></a>
-<span class="sourceLineNo">1166</span>      System.exit(-1);<a name="line.1166"></a>
-<span class="sourceLineNo">1167</span>    } else if (args[0].compareTo("--split") == 0) {<a name="line.1167"></a>
-<span class="sourceLineNo">1168</span>      Configuration conf = HBaseConfiguration.create();<a name="line.1168"></a>
-<span class="sourceLineNo">1169</span>      for (int i = 1; i &lt; args.length; i++) {<a name="line.1169"></a>
-<span class="sourceLineNo">1170</span>        try {<a name="line.1170"></a>
-<span class="sourceLineNo">1171</span>          Path logPath = new Path(args[i]);<a name="line.1171"></a>
-<span class="sourceLineNo">1172</span>          FSUtils.setFsDefault(conf, logPath);<a name="line.1172"></a>
-<span class="sourceLineNo">1173</span>          split(conf, logPath);<a name="line.1173"></a>
-<span class="sourceLineNo">1174</span>        } catch (IOException t) {<a name="line.1174"></a>
-<span class="sourceLineNo">1175</span>          t.printStackTrace(System.err);<a name="line.1175"></a>
-<span class="sourceLineNo">1176</span>          System.exit(-1);<a name="line.1176"></a>
-<span class="sourceLineNo">1177</span>        }<a name="line.1177"></a>
-<span class="sourceLineNo">1178</span>      }<a name="line.1178"></a>
-<span class="sourceLineNo">1179</span>    } else {<a name="line.1179"></a>
-<span class="sourceLineNo">1180</span>      usage();<a name="line.1180"></a>
-<span class="sourceLineNo">1181</span>      System.exit(-1);<a name="line.1181"></a>
-<span class="sourceLineNo">1182</span>    }<a name="line.1182"></a>
-<span class="sourceLineNo">1183</span>  }<a name="line.1183"></a>
-<span class="sourceLineNo">1184</span><a name="line.1184"></a>
-<span class="sourceLineNo">1185</span>  /**<a name="line.1185"></a>
-<span class="sourceLineNo">1186</span>   * This method gets the pipeline for the current WAL.<a name="line.1186"></a>
-<span class="sourceLineNo">1187</span>   */<a name="line.1187"></a>
-<span class="sourceLineNo">1188</span>  @Override<a name="line.1188"></a>
-<span class="sourceLineNo">1189</span>  DatanodeInfo[] getPipeline() {<a name="line.1189"></a>
-<span class="sourceLineNo">1190</span>    if (this.hdfs_out != null) {<a name="line.1190"></a>
-<span class="sourceLineNo">1191</span>      if (this.hdfs_out.getWrappedStream() instanceof DFSOutputStream) {<a name="line.1191"></a>
-<span class="sourceLineNo">1192</span>        return ((DFSOutputStream) this.hdfs_out.getWrappedStream()).getPipeline();<a name="line.1192"></a>
-<span class="sourceLineNo">1193</span>      }<a name="line.1193"></a>
-<span class="sourceLineNo">1194</span>    }<a name="line.1194"></a>
-<span class="sourceLineNo">1195</span>    return new DatanodeInfo[0];<a name="line.1195"></a>
-<span class="sourceLineNo">1196</span>  }<a name="line.1196"></a>
-<span class="sourceLineNo">1197</span><a name="line.1197"></a>
-<span class="sourceLineNo">1198</span>  /**<a name="line.1198"></a>
-<span class="sourceLineNo">1199</span>   *<a name="line.1199"></a>
-<span class="sourceLineNo">1200</span>   * @return last time on checking low replication<a name="line.1200"></a>
-<span class="sourceLineNo">1201</span>   */<a name="line.1201"></a>
-<span class="sourceLineNo">1202</span>  public long getLastTimeCheckLowReplication() {<a name="line.1202"></a>
-<span class="sourceLineNo">1203</span>    return this.lastTimeCheckLowReplication;<a name="line.1203"></a>
-<span class="sourceLineNo">1204</span>  }<a name="line.1204"></a>
-<span class="sourceLineNo">1205</span>}<a name="line.1205"></a>
+<span class="sourceLineNo">926</span>    private Exception exception = null;<a name="line.926"></a>
+<span class="sourceLineNo">927</span>    /**<a name="line.927"></a>
+<span class="sourceLineNo">928</span>     * Object to block on while waiting on safe point.<a name="line.928"></a>
+<span class="sourceLineNo">929</span>     */<a name="line.929"></a>
+<span class="sourceLineNo">930</span>    private final Object safePointWaiter = new Object();<a name="line.930"></a>
+<span class="sourceLineNo">931</span>    private volatile boolean shutdown = false;<a name="line.931"></a>
+<span class="sourceLineNo">932</span><a name="line.932"></a>
+<span class="sourceLineNo">933</span>    /**<a name="line.933"></a>
+<span class="sourceLineNo">934</span>     * Which syncrunner to use next.<a name="line.934"></a>
+<span class="sourceLineNo">935</span>     */<a name="line.935"></a>
+<span class="sourceLineNo">936</span>    private int syncRunnerIndex;<a name="line.936"></a>
+<span class="sourceLineNo">937</span><a name="line.937"></a>
+<span class="sourceLineNo">938</span>    RingBufferEventHandler(final int syncRunnerCount, final int maxHandlersCount) {<a name="line.938"></a>
+<span class="sourceLineNo">939</span>      this.syncFutures = new SyncFuture[maxHandlersCount];<a name="line.939"></a>
+<span class="sourceLineNo">940</span>      this.syncRunners = new SyncRunner[syncRunnerCount];<a name="line.940"></a>
+<span class="sourceLineNo">941</span>      for (int i = 0; i &lt; syncRunnerCount; i++) {<a name="line.941"></a>
+<span class="sourceLineNo">942</span>        this.syncRunners[i] = new SyncRunner("sync." + i, maxHandlersCount);<a name="line.942"></a>
+<span class="sourceLineNo">943</span>      }<a name="line.943"></a>
+<span class="sourceLineNo">944</span>    }<a name="line.944"></a>
+<span class="sourceLineNo">945</span><a name="line.945"></a>
+<span class="sourceLineNo">946</span>    private void cleanupOutstandingSyncsOnException(final long sequence, final Exception e) {<a name="line.946"></a>
+<span class="sourceLineNo">947</span>      // There could be handler-count syncFutures outstanding.<a name="line.947"></a>
+<span class="sourceLineNo">948</span>      for (int i = 0; i &lt; this.syncFuturesCount; i++) {<a name="line.948"></a>
+<span class="sourceLineNo">949</span>        this.syncFutures[i].done(sequence, e);<a name="line.949"></a>
+<span class="sourceLineNo">950</span>      }<a name="line.950"></a>
+<span class="sourceLineNo">951</span>      this.syncFuturesCount = 0;<a name="line.951"></a>
+<span class="sourceLineNo">952</span>    }<a name="line.952"></a>
+<span class="sourceLineNo">953</span><a name="line.953"></a>
+<span class="sourceLineNo">954</span>    /**<a name="line.954"></a>
+<span class="sourceLineNo">955</span>     * @return True if outstanding sync futures still<a name="line.955"></a>
+<span class="sourceLineNo">956</span>     */<a name="line.956"></a>
+<span class="sourceLineNo">957</span>    private boolean isOutstandingSyncs() {<a name="line.957"></a>
+<span class="sourceLineNo">958</span>      // Look at SyncFutures in the EventHandler<a name="line.958"></a>
+<span class="sourceLineNo">959</span>      for (int i = 0; i &lt; this.syncFuturesCount; i++) {<a name="line.959"></a>
+<span class="sourceLineNo">960</span>        if (!this.syncFutures[i].isDone()) {<a name="line.960"></a>
+<span class="sourceLineNo">961</span>          return true;<a name="line.961"></a>
+<span class="sourceLineNo">962</span>        }<a name="line.962"></a>
+<span class="sourceLineNo">963</span>      }<a name="line.963"></a>
+<span class="sourceLineNo">964</span><a name="line.964"></a>
+<span class="sourceLineNo">965</span>      return false;<a name="line.965"></a>
+<span class="sourceLineNo">966</span>    }<a name="line.966"></a>
+<span class="sourceLineNo">967</span><a name="line.967"></a>
+<span class="sourceLineNo">968</span>    private boolean isOutstandingSyncsFromRunners() {<a name="line.968"></a>
+<span class="sourceLineNo">969</span>      // Look at SyncFutures in the SyncRunners<a name="line.969"></a>
+<span class="sourceLineNo">970</span>      for (SyncRunner syncRunner: syncRunners) {<a name="line.970"></a>
+<span class="sourceLineNo">971</span>        if(syncRunner.isAlive() &amp;&amp; !syncRunner.areSyncFuturesReleased()) {<a name="line.971"></a>
+<span class="sourceLineNo">972</span>          return true;<a name="line.972"></a>
+<span class="sourceLineNo">973</span>        }<a name="line.973"></a>
+<span class="sourceLineNo">974</span>      }<a name="line.974"></a>
+<span class="sourceLineNo">975</span>      return false;<a name="line.975"></a>
+<span class="sourceLineNo">976</span>    }<a name="line.976"></a>
+<span class="sourceLineNo">977</span><a name="line.977"></a>
+<span class="sourceLineNo">978</span>    @Override<a name="line.978"></a>
+<span class="sourceLineNo">979</span>    // We can set endOfBatch in the below method if at end of our this.syncFutures array<a name="line.979"></a>
+<span class="sourceLineNo">980</span>    public void onEvent(final RingBufferTruck truck, final long sequence, boolean endOfBatch)<a name="line.980"></a>
+<span class="sourceLineNo">981</span>        throws Exception {<a name="line.981"></a>
+<span class="sourceLineNo">982</span>      // Appends and syncs are coming in order off the ringbuffer. We depend on this fact. We'll<a name="line.982"></a>
+<span class="sourceLineNo">983</span>      // add appends to dfsclient as they come in. Batching appends doesn't give any significant<a name="line.983"></a>
+<span class="sourceLineNo">984</span>      // benefit on measurement. Handler sync calls we will batch up. If we get an exception<a name="line.984"></a>
+<span class="sourceLineNo">985</span>      // appending an edit, we fail all subsequent appends and syncs with the same exception until<a name="line.985"></a>
+<span class="sourceLineNo">986</span>      // the WAL is reset. It is important that we not short-circuit and exit early this method.<a name="line.986"></a>
+<span class="sourceLineNo">987</span>      // It is important that we always go through the attainSafePoint on the end. Another thread,<a name="line.987"></a>
+<span class="sourceLineNo">988</span>      // the log roller may be waiting on a signal from us here and will just hang without it.<a name="line.988"></a>
+<span class="sourceLineNo">989</span><a name="line.989"></a>
+<span class="sourceLineNo">990</span>      try {<a name="line.990"></a>
+<span class="sourceLineNo">991</span>        if (truck.type() == RingBufferTruck.Type.SYNC) {<a name="line.991"></a>
+<span class="sourceLineNo">992</span>          this.syncFutures[this.syncFuturesCount++] = truck.unloadSync();<a name="line.992"></a>
+<span class="sourceLineNo">993</span>          // Force flush of syncs if we are carrying a full complement of syncFutures.<a name="line.993"></a>
+<span class="sourceLineNo">994</span>          if (this.syncFuturesCount == this.syncFutures.length) {<a name="line.994"></a>
+<span class="sourceLineNo">995</span>            endOfBatch = true;<a name="line.995"></a>
+<span class="sourceLineNo">996</span>          }<a name="line.996"></a>
+<span class="sourceLineNo">997</span>        } else if (truck.type() == RingBufferTruck.Type.APPEND) {<a name="line.997"></a>
+<span class="sourceLineNo">998</span>          FSWALEntry entry = truck.unloadAppend();<a name="line.998"></a>
+<span class="sourceLineNo">999</span>          TraceScope scope = Trace.continueSpan(entry.detachSpan());<a name="line.999"></a>
+<span class="sourceLineNo">1000</span>          try {<a name="line.1000"></a>
+<span class="sourceLineNo">1001</span><a name="line.1001"></a>
+<span class="sourceLineNo">1002</span>            if (this.exception != null) {<a name="line.1002"></a>
+<span class="sourceLineNo">1003</span>              // Return to keep processing events coming off the ringbuffer<a name="line.1003"></a>
+<span class="sourceLineNo">1004</span>              return;<a name="line.1004"></a>
+<span class="sourceLineNo">1005</span>            }<a name="line.1005"></a>
+<span class="sourceLineNo">1006</span>            append(entry);<a name="line.1006"></a>
+<span class="sourceLineNo">1007</span>          } catch (Exception e) {<a name="line.1007"></a>
+<span class="sourceLineNo">1008</span>            // Failed append. Record the exception.<a name="line.1008"></a>
+<span class="sourceLineNo">1009</span>            this.exception = e;<a name="line.1009"></a>
+<span class="sourceLineNo">1010</span>            // invoking cleanupOutstandingSyncsOnException when append failed with exception,<a name="line.1010"></a>
+<span class="sourceLineNo">1011</span>            // it will cleanup existing sync requests recorded in syncFutures but not offered to SyncRunner yet,<a name="line.1011"></a>
+<span class="sourceLineNo">1012</span>            // so there won't be any sync future left over if no further truck published to disruptor.<a name="line.1012"></a>
+<span class="sourceLineNo">1013</span>            cleanupOutstandingSyncsOnException(sequence,<a name="line.1013"></a>
+<span class="sourceLineNo">1014</span>                this.exception instanceof DamagedWALException ? this.exception<a name="line.1014"></a>
+<span class="sourceLineNo">1015</span>                    : new DamagedWALException("On sync", this.exception));<a name="line.1015"></a>
+<span class="sourceLineNo">1016</span>            // Return to keep processing events coming off the ringbuffer<a name="line.1016"></a>
+<span class="sourceLineNo">1017</span>            return;<a name="line.1017"></a>
+<span class="sourceLineNo">1018</span>          } finally {<a name="line.1018"></a>
+<span class="sourceLineNo">1019</span>            assert scope == NullScope.INSTANCE || !scope.isDetached();<a name="line.1019"></a>
+<span class="sourceLineNo">1020</span>            scope.close(); // append scope is complete<a name="line.1020"></a>
+<span class="sourceLineNo">1021</span>          }<a name="line.1021"></a>
+<span class="sourceLineNo">1022</span>        } else {<a name="line.1022"></a>
+<span class="sourceLineNo">1023</span>          // What is this if not an append or sync. Fail all up to this!!!<a name="line.1023"></a>
+<span class="sourceLineNo">1024</span>          cleanupOutstandingSyncsOnException(sequence,<a name="line.1024"></a>
+<span class="sourceLineNo">1025</span>            new IllegalStateException("Neither append nor sync"));<a name="line.1025"></a>
+<span class="sourceLineNo">1026</span>          // Return to keep processing.<a name="line.1026"></a>
+<span class="sourceLineNo">1027</span>          return;<a name="line.1027"></a>
+<span class="sourceLineNo">1028</span>        }<a name="line.1028"></a>
+<span class="sourceLineNo">1029</span><a name="line.1029"></a>
+<span class="sourceLineNo">1030</span>        // TODO: Check size and if big go ahead and call a sync if we have enough data.<a name="line.1030"></a>
+<span class="sourceLineNo">1031</span>        // This is a sync. If existing exception, fall through. Else look to see if batch.<a name="line.1031"></a>
+<span class="sourceLineNo">1032</span>        if (this.exception == null) {<a name="line.1032"></a>
+<span class="sourceLineNo">1033</span>          // If not a batch, return to consume more events from the ring buffer before proceeding;<a name="line.1033"></a>
+<span class="sourceLineNo">1034</span>          // we want to get up a batch of syncs and appends before we go do a filesystem sync.<a name="line.1034"></a>
+<span class="sourceLineNo">1035</span>          if (!endOfBatch || this.syncFuturesCount &lt;= 0) {<a name="line.1035"></a>
+<span class="sourceLineNo">1036</span>            return;<a name="line.1036"></a>
+<span class="sourceLineNo">1037</span>          }<a name="line.1037"></a>
+<span class="sourceLineNo">1038</span>          // syncRunnerIndex is bound to the range [0, Integer.MAX_INT - 1] as follows:<a name="line.1038"></a>
+<span class="sourceLineNo">1039</span>          //   * The maximum value possible for syncRunners.length is Integer.MAX_INT<a name="line.1039"></a>
+<span class="sourceLineNo">1040</span>          //   * syncRunnerIndex starts at 0 and is incremented only here<a name="line.1040"></a>
+<span class="sourceLineNo">1041</span>          //   * after the increment, the value is bounded by the '%' operator to<a name="line.1041"></a>
+<span class="sourceLineNo">1042</span>          //     [0, syncRunners.length), presuming the value was positive prior to<a name="line.1042"></a>
+<span class="sourceLineNo">1043</span>          //     the '%' operator.<a name="line.1043"></a>
+<span class="sourceLineNo">1044</span>          //   * after being bound to [0, Integer.MAX_INT - 1], the new value is stored in<a name="line.1044"></a>
+<span class="sourceLineNo">1045</span>          //     syncRunnerIndex ensuring that it can't grow without bound and overflow.<a name="line.1045"></a>
+<span class="sourceLineNo">1046</span>          //   * note that the value after the increment must be positive, because the most it<a name="line.1046"></a>
+<span class="sourceLineNo">1047</span>          //     could have been prior was Integer.MAX_INT - 1 and we only increment by 1.<a name="line.1047"></a>
+<span class="sourceLineNo">1048</span>          this.syncRunnerIndex = (this.syncRunnerIndex + 1) % this.syncRunners.length;<a name="line.1048"></a>
+<span class="sourceLineNo">1049</span>          try {<a name="line.1049"></a>
+<span class="sourceLineNo">1050</span>            // Below expects that the offer 'transfers' responsibility for the outstanding syncs to<a name="line.1050"></a>
+<span class="sourceLineNo">1051</span>            // the syncRunner. We should never get an exception in here.<a name="line.1051"></a>
+<span class="sourceLineNo">1052</span>            this.syncRunners[this.syncRunnerIndex].offer(sequence, this.syncFutures,<a name="line.1052"></a>
+<span class="sourceLineNo">1053</span>              this.syncFuturesCount);<a name="line.1053"></a>
+<span class="sourceLineNo">1054</span>          } catch (Exception e) {<a name="line.1054"></a>
+<span class="sourceLineNo">1055</span>            // Should NEVER get here.<a name="line.1055"></a>
+<span class="sourceLineNo">1056</span>            requestLogRoll();<a name="line.1056"></a>
+<span class="sourceLineNo">1057</span>            this.exception = new DamagedWALException("Failed offering sync", e);<a name="line.1057"></a>
+<span class="sourceLineNo">1058</span>          }<a name="line.1058"></a>
+<span class="sourceLineNo">1059</span>        }<a name="line.1059"></a>
+<span class="sourceLineNo">1060</span>        // We may have picked up an exception above trying to offer sync<a name="line.1060"></a>
+<span class="sourceLineNo">1061</span>        if (this.exception != null) {<a name="line.1061"></a>
+<span class="sourceLineNo">1062</span>          cleanupOutstandingSyncsOnException(sequence, this.exception instanceof DamagedWALException<a name="line.1062"></a>
+<span class="sourceLineNo">1063</span>              ? this.exception : new DamagedWALException("On sync", this.exception));<a name="line.1063"></a>
+<span class="sourceLineNo">1064</span>        }<a name="line.1064"></a>
+<span class="sourceLineNo">1065</span>        attainSafePoint(sequence);<a name="line.1065"></a>
+<span class="sourceLineNo">1066</span>        this.syncFuturesCount = 0;<a name="line.1066"></a>
+<span class="sourceLineNo">1067</span>      } catch (Throwable t) {<a name="line.1067"></a>
+<span class="sourceLineNo">1068</span>        LOG.error("UNEXPECTED!!! syncFutures.length=" + this.syncFutures.length, t);<a name="line.1068"></a>
+<span class="sourceLineNo">1069</span>      }<a name="line.1069"></a>
+<span class="sourceLineNo">1070</span>    }<a name="line.1070"></a>
+<span class="sourceLineNo">1071</span><a name="line.1071"></a>
+<span class="sourceLineNo">1072</span>    SafePointZigZagLatch attainSafePoint() {<a name="line.1072"></a>
+<span class="sourceLineNo">1073</span>      this.zigzagLatch = new SafePointZigZagLatch();<a name="line.1073"></a>
+<span class="sourceLineNo">1074</span>      return this.zigzagLatch;<a name="line.1074"></a>
+<span class="sourceLineNo">1075</span>    }<a name="line.1075"></a>
+<span class="sourceLineNo">1076</span><a name="line.1076"></a>
+<span class="sourceLineNo">1077</span>    /**<a name="line.1077"></a>
+<span class="sourceLineNo">1078</span>     * Check if we should attain safe point. If so, go there and then wait till signalled before we<a name="line.1078"></a>
+<span class="sourceLineNo">1079</span>     * proceeding.<a name="line.1079"></a>
+<span class="sourceLineNo">1080</span>     */<a name="line.1080"></a>
+<span class="sourceLineNo">1081</span>    private void attainSafePoint(final long currentSequence) {<a name="line.1081"></a>
+<span class="sourceLineNo">1082</span>      if (this.zigzagLatch == null || !this.zigzagLatch.isCocked()) {<a name="line.1082"></a>
+<span class="sourceLineNo">1083</span>        return;<a name="line.1083"></a>
+<span class="sourceLineNo">1084</span>      }<a name="line.1084"></a>
+<span class="sourceLineNo">1085</span>      // If here, another thread is waiting on us to get to safe point. Don't leave it hanging.<a name="line.1085"></a>
+<span class="sourceLineNo">1086</span>      beforeWaitOnSafePoint();<a name="line.1086"></a>
+<span class="sourceLineNo">1087</span>      try {<a name="line.1087"></a>
+<span class="sourceLineNo">1088</span>        // Wait on outstanding syncers; wait for them to finish syncing (unless we've been<a name="line.1088"></a>
+<span class="sourceLineNo">1089</span>        // shutdown or unless our latch has been thrown because we have been aborted or unless<a name="line.1089"></a>
+<span class="sourceLineNo">1090</span>        // this WAL is broken and we can't get a sync/append to complete).<a name="line.1090"></a>
+<span class="sourceLineNo">1091</span>        while ((!this.shutdown &amp;&amp; this.zigzagLatch.isCocked()<a name="line.1091"></a>
+<span class="sourceLineNo">1092</span>            &amp;&amp; highestSyncedTxid.get() &lt; currentSequence &amp;&amp;<a name="line.1092"></a>
+<span class="sourceLineNo">1093</span>            // We could be in here and all syncs are failing or failed. Check for this. Otherwise<a name="line.1093"></a>
+<span class="sourceLineNo">1094</span>            // we'll just be stuck here for ever. In other words, ensure there syncs running.<a name="line.1094"></a>
+<span class="sourceLineNo">1095</span>            isOutstandingSyncs())<a name="line.1095"></a>
+<span class="sourceLineNo">1096</span>            // Wait for all SyncRunners to finish their work so that we can replace the writer<a name="line.1096"></a>
+<span class="sourceLineNo">1097</span>            || isOutstandingSyncsFromRunners()) {<a name="line.1097"></a>
+<span class="sourceLineNo">1098</span>          synchronized (this.safePointWaiter) {<a name="line.1098"></a>
+<span class="sourceLineNo">1099</span>            this.safePointWaiter.wait(0, 1);<a name="line.1099"></a>
+<span class="sourceLineNo">1100</span>          }<a name="line.1100"></a>
+<span class="sourceLineNo">1101</span>        }<a name="line.1101"></a>
+<span class="sourceLineNo">1102</span>        // Tell waiting thread we've attained safe point. Can clear this.throwable if set here<a name="line.1102"></a>
+<span class="sourceLineNo">1103</span>        // because we know that next event through the ringbuffer will be going to a new WAL<a name="line.1103"></a>
+<span class="sourceLineNo">1104</span>        // after we do the zigzaglatch dance.<a name="line.1104"></a>
+<span class="sourceLineNo">1105</span>        this.exception = null;<a name="line.1105"></a>
+<span class="sourceLineNo">1106</span>        this.zigzagLatch.safePointAttained();<a name="line.1106"></a>
+<span class="sourceLineNo">1107</span>      } catch (InterruptedException e) {<a name="line.1107"></a>
+<span class="sourceLineNo">1108</span>        LOG.warn("Interrupted ", e);<a name="line.1108"></a>
+<span class="sourceLineNo">1109</span>        Thread.currentThread().interrupt();<a name="line.1109"></a>
+<span class="sourceLineNo">1110</span>      }<a name="line.1110"></a>
+<span class="sourceLineNo">1111</span>    }<a name="line.1111"></a>
+<span class="sourceLineNo">1112</span><a name="line.1112"></a>
+<span class="sourceLineNo">1113</span>    /**<a name="line.1113"></a>
+<span class="sourceLineNo">1114</span>     * Append to the WAL. Does all CP and WAL listener calls.<a name="line.1114"></a>
+<span class="sourceLineNo">1115</span>     */<a name="line.1115"></a>
+<span class="sourceLineNo">1116</span>    void append(final FSWALEntry entry) throws Exception {<a name="line.1116"></a>
+<span class="sourceLineNo">1117</span>      try {<a name="line.1117"></a>
+<span class="sourceLineNo">1118</span>        FSHLog.this.append(writer, entry);<a name="line.1118"></a>
+<span class="sourceLineNo">1119</span>      } catch (Exception e) {<a name="line.1119"></a>
+<span class="sourceLineNo">1120</span>        String msg = "Append sequenceId=" + entry.getKey().getSequenceId()<a name="line.1120"></a>
+<span class="sourceLineNo">1121</span>            + ", requesting roll of WAL";<a name="line.1121"></a>
+<span class="sourceLineNo">1122</span>        LOG.warn(msg, e);<a name="line.1122"></a>
+<span class="sourceLineNo">1123</span>        requestLogRoll();<a name="line.1123"></a>
+<span class="sourceLineNo">1124</span>        throw new DamagedWALException(msg, e);<a name="line.1124"></a>
+<span class="sourceLineNo">1125</span>      }<a name="line.1125"></a>
+<span class="sourceLineNo">1126</span>    }<a name="line.1126"></a>
+<span class="sourceLineNo">1127</span><a name="line.1127"></a>
+<span class="sourceLineNo">1128</span>    @Override<a name="line.1128"></a>
+<span class="sourceLineNo">1129</span>    public void onStart() {<a name="line.1129"></a>
+<span class="sourceLineNo">1130</span>      for (SyncRunner syncRunner : this.syncRunners) {<a name="line.1130"></a>
+<span class="sourceLineNo">1131</span>        syncRunner.start();<a name="line.1131"></a>
+<span class="sourceLineNo">1132</span>      }<a name="line.1132"></a>
+<span class="sourceLineNo">1133</span>    }<a name="line.1133"></a>
+<span class="sourceLineNo">1134</span><a name="line.1134"></a>
+<span class="sourceLineNo">1135</span>    @Override<a name="line.1135"></a>
+<span class="sourceLineNo">1136</span>    public void onShutdown() {<a name="line.1136"></a>
+<span class="sourceLineNo">1137</span>      for (SyncRunner syncRunner : this.syncRunners) {<a name="line.1137"></a>
+<span class="sourceLineNo">1138</span>        syncRunner.interrupt();<a name="line.1138"></a>
+<span class="sourceLineNo">1139</span>      }<a name="line.1139"></a>
+<span class="sourceLineNo">1140</span>    }<a name="line.1140"></a>
+<span class="sourceLineNo">1141</span>  }<a name="line.1141"></a>
+<span class="sourceLineNo">1142</span><a name="line.1142"></a>
+<span class="sourceLineNo">1143</span>  private static void usage() {<a name="line.1143"></a>
+<span class="sourceLineNo">1144</span>    System.err.println("Usage: FSHLog &lt;ARGS&gt;");<a name="line.1144"></a>
+<span class="sourceLineNo">1145</span>    System.err.println("Arguments:");<a name="line.1145"></a>
+<span class="sourceLineNo">1146</span>    System.err.println(" --dump  Dump textual representation of passed one or more files");<a name="line.1146"></a>
+<span class="sourceLineNo">1147</span>    System.err.println("         For example: "<a name="line.1147"></a>
+<span class="sourceLineNo">1148</span>        + "FSHLog --dump hdfs://example.com:9000/hbase/WALs/MACHINE/LOGFILE");<a name="line.1148"></a>
+<span class="sourceLineNo">1149</span>    System.err.println(" --split Split the passed directory of WAL logs");<a name="line.1149"></a>
+<span class="sourceLineNo">1150</span>    System.err.println(<a name="line.1150"></a>
+<span class="sourceLineNo">1151</span>      "         For example: " + "FSHLog --split hdfs://example.com:9000/hbase/WALs/DIR");<a name="line.1151"></a>
+<span class="sourceLineNo">1152</span>  }<a name="line.1152"></a>
+<span class="sourceLineNo">1153</span><a name="line.1153"></a>
+<span class="sourceLineNo">1154</span>  /**<a name="line.1154"></a>
+<span class="sourceLineNo">1155</span>   * Pass one or more log file names and it will either dump out a text version on<a name="line.1155"></a>
+<span class="sourceLineNo">1156</span>   * &lt;code&gt;stdout&lt;/code&gt; or split the specified log files.<a name="line.1156"></a>
+<span class="sourceLineNo">1157</span>   */<a name="line.1157"></a>
+<span class="sourceLineNo">1158</span>  public static void main(String[] args) throws IOException {<a name="line.1158"></a>
+<span class="sourceLineNo">1159</span>    if (args.length &lt; 2) {<a name="line.1159"></a>
+<span class="sourceLineNo">1160</span>      usage();<a name="line.1160"></a>
+<span class="sourceLineNo">1161</span>      System.exit(-1);<a name="line.1161"></a>
+<span class="sourceLineNo">1162</span>    }<a name="line.1162"></a>
+<span class="sourceLineNo">1163</span>    // either dump using the WALPrettyPrinter or split, depending on args<a name="line.1163"></a>
+<span class="sourceLineNo">1164</span>    if (args[0].compareTo("--dump") == 0) {<a name="line.1164"></a>
+<span class="sourceLineNo">1165</span>      WALPrettyPrinter.run(Arrays.copyOfRange(args, 1, args.length));<a name="line.1165"></a>
+<span class="sourceLineNo">1166</span>    } else if (args[0].compareTo("--perf") == 0) {<a name="line.1166"></a>
+<span class="sourceLineNo">1167</span>      LOG.fatal("Please use the WALPerformanceEvaluation tool instead. i.e.:");<a name="line.1167"></a>
+<span class="sourceLineNo">1168</span>      LOG.fatal(<a name="line.1168"></a>
+<span class="sourceLineNo">1169</span>        "\thbase org.apache.hadoop.hbase.wal.WALPerformanceEvaluation --iterations " + args[1]);<a name="line.1169"></a>
+<span class="sourceLineNo">1170</span>      System.exit(-1);<a name="line.1170"></a>
+<span class="sourceLineNo">1171</span>    } else if (args[0].compareTo("--split") == 0) {<a name="line.1171"></a>
+<span class="sourceLineNo">1172</span>      Configuration conf = HBaseConfiguration.create();<a name="line.1172"></a>
+<span class="sourceLineNo">1173</span>      for (int i = 1; i &lt; ar

<TRUNCATED>

Mime
View raw message