hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [10/14] hbase git commit: Published site at 55087ce8887b5be38b0fda0dda3fbf2f92c13778.
Date Mon, 23 Nov 2015 23:03:27 GMT
http://git-wip-us.apache.org/repos/asf/hbase/blob/f843f57d/devapidocs/src-html/org/apache/hadoop/hbase/io/BoundedByteBufferPool.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/io/BoundedByteBufferPool.html b/devapidocs/src-html/org/apache/hadoop/hbase/io/BoundedByteBufferPool.html
index 9129044..36ae76e 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/io/BoundedByteBufferPool.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/io/BoundedByteBufferPool.html
@@ -27,13 +27,13 @@
 <span class="sourceLineNo">019</span><a name="line.19"></a>
 <span class="sourceLineNo">020</span>import java.nio.ByteBuffer;<a name="line.20"></a>
 <span class="sourceLineNo">021</span>import java.util.Queue;<a name="line.21"></a>
-<span class="sourceLineNo">022</span>import java.util.concurrent.atomic.AtomicLong;<a name="line.22"></a>
-<span class="sourceLineNo">023</span>import java.util.concurrent.locks.ReentrantLock;<a name="line.23"></a>
-<span class="sourceLineNo">024</span><a name="line.24"></a>
-<span class="sourceLineNo">025</span>import org.apache.commons.logging.Log;<a name="line.25"></a>
-<span class="sourceLineNo">026</span>import org.apache.commons.logging.LogFactory;<a name="line.26"></a>
-<span class="sourceLineNo">027</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.27"></a>
-<span class="sourceLineNo">028</span>import org.apache.hadoop.hbase.util.BoundedArrayQueue;<a name="line.28"></a>
+<span class="sourceLineNo">022</span>import java.util.concurrent.ConcurrentLinkedQueue;<a name="line.22"></a>
+<span class="sourceLineNo">023</span>import java.util.concurrent.atomic.AtomicInteger;<a name="line.23"></a>
+<span class="sourceLineNo">024</span>import java.util.concurrent.atomic.AtomicLong;<a name="line.24"></a>
+<span class="sourceLineNo">025</span><a name="line.25"></a>
+<span class="sourceLineNo">026</span>import org.apache.commons.logging.Log;<a name="line.26"></a>
+<span class="sourceLineNo">027</span>import org.apache.commons.logging.LogFactory;<a name="line.27"></a>
+<span class="sourceLineNo">028</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.28"></a>
 <span class="sourceLineNo">029</span><a name="line.29"></a>
 <span class="sourceLineNo">030</span>import com.google.common.annotations.VisibleForTesting;<a name="line.30"></a>
 <span class="sourceLineNo">031</span><a name="line.31"></a>
@@ -59,86 +59,143 @@
 <span class="sourceLineNo">051</span>public class BoundedByteBufferPool {<a name="line.51"></a>
 <span class="sourceLineNo">052</span>  private static final Log LOG = LogFactory.getLog(BoundedByteBufferPool.class);<a name="line.52"></a>
 <span class="sourceLineNo">053</span><a name="line.53"></a>
-<span class="sourceLineNo">054</span>  @VisibleForTesting<a name="line.54"></a>
-<span class="sourceLineNo">055</span>  final Queue&lt;ByteBuffer&gt; buffers;<a name="line.55"></a>
-<span class="sourceLineNo">056</span><a name="line.56"></a>
-<span class="sourceLineNo">057</span>  // Maximum size of a ByteBuffer to retain in pool<a name="line.57"></a>
-<span class="sourceLineNo">058</span>  private final int maxByteBufferSizeToCache;<a name="line.58"></a>
-<span class="sourceLineNo">059</span><a name="line.59"></a>
-<span class="sourceLineNo">060</span>  // A running average only it only rises, it never recedes<a name="line.60"></a>
-<span class="sourceLineNo">061</span>  @VisibleForTesting<a name="line.61"></a>
-<span class="sourceLineNo">062</span>  volatile int runningAverage;<a name="line.62"></a>
-<span class="sourceLineNo">063</span><a name="line.63"></a>
-<span class="sourceLineNo">064</span>  // Scratch that keeps rough total size of pooled bytebuffers<a name="line.64"></a>
-<span class="sourceLineNo">065</span>  private volatile int totalReservoirCapacity;<a name="line.65"></a>
-<span class="sourceLineNo">066</span><a name="line.66"></a>
-<span class="sourceLineNo">067</span>  // For reporting<a name="line.67"></a>
-<span class="sourceLineNo">068</span>  private AtomicLong allocations = new AtomicLong(0);<a name="line.68"></a>
-<span class="sourceLineNo">069</span><a name="line.69"></a>
-<span class="sourceLineNo">070</span>  private ReentrantLock lock =  new ReentrantLock();<a name="line.70"></a>
-<span class="sourceLineNo">071</span><a name="line.71"></a>
-<span class="sourceLineNo">072</span>  /**<a name="line.72"></a>
-<span class="sourceLineNo">073</span>   * @param maxByteBufferSizeToCache<a name="line.73"></a>
-<span class="sourceLineNo">074</span>   * @param initialByteBufferSize<a name="line.74"></a>
-<span class="sourceLineNo">075</span>   * @param maxToCache<a name="line.75"></a>
-<span class="sourceLineNo">076</span>   */<a name="line.76"></a>
-<span class="sourceLineNo">077</span>  public BoundedByteBufferPool(final int maxByteBufferSizeToCache, final int initialByteBufferSize,<a name="line.77"></a>
-<span class="sourceLineNo">078</span>      final int maxToCache) {<a name="line.78"></a>
-<span class="sourceLineNo">079</span>    this.maxByteBufferSizeToCache = maxByteBufferSizeToCache;<a name="line.79"></a>
-<span class="sourceLineNo">080</span>    this.runningAverage = initialByteBufferSize;<a name="line.80"></a>
-<span class="sourceLineNo">081</span>    this.buffers = new BoundedArrayQueue&lt;ByteBuffer&gt;(maxToCache);<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>  public ByteBuffer getBuffer() {<a name="line.84"></a>
-<span class="sourceLineNo">085</span>    ByteBuffer bb = null;<a name="line.85"></a>
-<span class="sourceLineNo">086</span>    lock.lock();<a name="line.86"></a>
-<span class="sourceLineNo">087</span>    try {<a name="line.87"></a>
-<span class="sourceLineNo">088</span>      bb = this.buffers.poll();<a name="line.88"></a>
-<span class="sourceLineNo">089</span>      if (bb != null) {<a name="line.89"></a>
-<span class="sourceLineNo">090</span>        this.totalReservoirCapacity -= bb.capacity();<a name="line.90"></a>
-<span class="sourceLineNo">091</span>      }<a name="line.91"></a>
-<span class="sourceLineNo">092</span>    } finally {<a name="line.92"></a>
-<span class="sourceLineNo">093</span>      lock.unlock();<a name="line.93"></a>
-<span class="sourceLineNo">094</span>    }<a name="line.94"></a>
-<span class="sourceLineNo">095</span>    if (bb != null) {<a name="line.95"></a>
-<span class="sourceLineNo">096</span>      // Clear sets limit == capacity. Postion == 0.<a name="line.96"></a>
-<span class="sourceLineNo">097</span>      bb.clear();<a name="line.97"></a>
-<span class="sourceLineNo">098</span>    } else {<a name="line.98"></a>
-<span class="sourceLineNo">099</span>      bb = ByteBuffer.allocateDirect(this.runningAverage);<a name="line.99"></a>
-<span class="sourceLineNo">100</span>      this.allocations.incrementAndGet();<a name="line.100"></a>
-<span class="sourceLineNo">101</span>    }<a name="line.101"></a>
-<span class="sourceLineNo">102</span>    if (LOG.isTraceEnabled()) {<a name="line.102"></a>
-<span class="sourceLineNo">103</span>      LOG.trace("runningAverage=" + this.runningAverage +<a name="line.103"></a>
-<span class="sourceLineNo">104</span>        ", totalCapacity=" + this.totalReservoirCapacity + ", count=" + this.buffers.size() +<a name="line.104"></a>
-<span class="sourceLineNo">105</span>        ", alloctions=" + this.allocations.get());<a name="line.105"></a>
-<span class="sourceLineNo">106</span>    }<a name="line.106"></a>
-<span class="sourceLineNo">107</span>    return bb;<a name="line.107"></a>
+<span class="sourceLineNo">054</span>  private final Queue&lt;ByteBuffer&gt; buffers = new ConcurrentLinkedQueue&lt;ByteBuffer&gt;();<a name="line.54"></a>
+<span class="sourceLineNo">055</span><a name="line.55"></a>
+<span class="sourceLineNo">056</span>  @VisibleForTesting<a name="line.56"></a>
+<span class="sourceLineNo">057</span>  int getQueueSize() {<a name="line.57"></a>
+<span class="sourceLineNo">058</span>    return buffers.size();<a name="line.58"></a>
+<span class="sourceLineNo">059</span>  }<a name="line.59"></a>
+<span class="sourceLineNo">060</span><a name="line.60"></a>
+<span class="sourceLineNo">061</span>  private final int maxToCache;<a name="line.61"></a>
+<span class="sourceLineNo">062</span><a name="line.62"></a>
+<span class="sourceLineNo">063</span>  // Maximum size of a ByteBuffer to retain in pool<a name="line.63"></a>
+<span class="sourceLineNo">064</span>  private final int maxByteBufferSizeToCache;<a name="line.64"></a>
+<span class="sourceLineNo">065</span><a name="line.65"></a>
+<span class="sourceLineNo">066</span>  // A running average only it only rises, it never recedes<a name="line.66"></a>
+<span class="sourceLineNo">067</span>  private final AtomicInteger runningAverageRef;<a name="line.67"></a>
+<span class="sourceLineNo">068</span><a name="line.68"></a>
+<span class="sourceLineNo">069</span>  @VisibleForTesting<a name="line.69"></a>
+<span class="sourceLineNo">070</span>  int getRunningAverage() {<a name="line.70"></a>
+<span class="sourceLineNo">071</span>    return runningAverageRef.get();<a name="line.71"></a>
+<span class="sourceLineNo">072</span>  }<a name="line.72"></a>
+<span class="sourceLineNo">073</span><a name="line.73"></a>
+<span class="sourceLineNo">074</span>  // Count (lower 32bit) and total capacity (upper 32bit) of pooled bytebuffers.<a name="line.74"></a>
+<span class="sourceLineNo">075</span>  // Both are non-negative. They are equal to or larger than those of the actual<a name="line.75"></a>
+<span class="sourceLineNo">076</span>  // queued buffers in any transition.<a name="line.76"></a>
+<span class="sourceLineNo">077</span>  private final AtomicLong stateRef = new AtomicLong();<a name="line.77"></a>
+<span class="sourceLineNo">078</span><a name="line.78"></a>
+<span class="sourceLineNo">079</span>  private static int toCountOfBuffers(long state) {<a name="line.79"></a>
+<span class="sourceLineNo">080</span>    return (int)state;<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>  private static int toTotalCapacity(long state) {<a name="line.83"></a>
+<span class="sourceLineNo">084</span>    return (int)(state &gt;&gt;&gt; 32);<a name="line.84"></a>
+<span class="sourceLineNo">085</span>  }<a name="line.85"></a>
+<span class="sourceLineNo">086</span><a name="line.86"></a>
+<span class="sourceLineNo">087</span>  private static long toState(int countOfBuffers, int totalCapacity) {<a name="line.87"></a>
+<span class="sourceLineNo">088</span>    return ((long)totalCapacity &lt;&lt; 32) | totalCapacity;<a name="line.88"></a>
+<span class="sourceLineNo">089</span>  }<a name="line.89"></a>
+<span class="sourceLineNo">090</span><a name="line.90"></a>
+<span class="sourceLineNo">091</span>  private static long subtractOneBufferFromState(long state, int capacity) {<a name="line.91"></a>
+<span class="sourceLineNo">092</span>    return state - ((long)capacity &lt;&lt; 32) - 1;<a name="line.92"></a>
+<span class="sourceLineNo">093</span>  }<a name="line.93"></a>
+<span class="sourceLineNo">094</span><a name="line.94"></a>
+<span class="sourceLineNo">095</span>  // For reporting, only used in the log<a name="line.95"></a>
+<span class="sourceLineNo">096</span>  private final AtomicLong allocationsRef = new AtomicLong();<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>   * @param maxByteBufferSizeToCache<a name="line.99"></a>
+<span class="sourceLineNo">100</span>   * @param initialByteBufferSize<a name="line.100"></a>
+<span class="sourceLineNo">101</span>   * @param maxToCache<a name="line.101"></a>
+<span class="sourceLineNo">102</span>   */<a name="line.102"></a>
+<span class="sourceLineNo">103</span>  public BoundedByteBufferPool(final int maxByteBufferSizeToCache, final int initialByteBufferSize,<a name="line.103"></a>
+<span class="sourceLineNo">104</span>      final int maxToCache) {<a name="line.104"></a>
+<span class="sourceLineNo">105</span>    this.maxByteBufferSizeToCache = maxByteBufferSizeToCache;<a name="line.105"></a>
+<span class="sourceLineNo">106</span>    this.runningAverageRef = new AtomicInteger(initialByteBufferSize);<a name="line.106"></a>
+<span class="sourceLineNo">107</span>    this.maxToCache = maxToCache;<a name="line.107"></a>
 <span class="sourceLineNo">108</span>  }<a name="line.108"></a>
 <span class="sourceLineNo">109</span><a name="line.109"></a>
-<span class="sourceLineNo">110</span>  public void putBuffer(ByteBuffer bb) {<a name="line.110"></a>
-<span class="sourceLineNo">111</span>    // If buffer is larger than we want to keep around, just let it go.<a name="line.111"></a>
-<span class="sourceLineNo">112</span>    if (bb.capacity() &gt; this.maxByteBufferSizeToCache) return;<a name="line.112"></a>
-<span class="sourceLineNo">113</span>    boolean success = false;<a name="line.113"></a>
-<span class="sourceLineNo">114</span>    int average = 0;<a name="line.114"></a>
-<span class="sourceLineNo">115</span>    lock.lock();<a name="line.115"></a>
-<span class="sourceLineNo">116</span>    try {<a name="line.116"></a>
-<span class="sourceLineNo">117</span>      success = this.buffers.offer(bb);<a name="line.117"></a>
-<span class="sourceLineNo">118</span>      if (success) {<a name="line.118"></a>
-<span class="sourceLineNo">119</span>        this.totalReservoirCapacity += bb.capacity();<a name="line.119"></a>
-<span class="sourceLineNo">120</span>        average = this.totalReservoirCapacity / this.buffers.size(); // size will never be 0.<a name="line.120"></a>
-<span class="sourceLineNo">121</span>      }<a name="line.121"></a>
-<span class="sourceLineNo">122</span>    } finally {<a name="line.122"></a>
-<span class="sourceLineNo">123</span>      lock.unlock();<a name="line.123"></a>
-<span class="sourceLineNo">124</span>    }<a name="line.124"></a>
-<span class="sourceLineNo">125</span>    if (!success) {<a name="line.125"></a>
-<span class="sourceLineNo">126</span>      LOG.warn("At capacity: " + this.buffers.size());<a name="line.126"></a>
-<span class="sourceLineNo">127</span>    } else {<a name="line.127"></a>
-<span class="sourceLineNo">128</span>      if (average &gt; this.runningAverage &amp;&amp; average &lt; this.maxByteBufferSizeToCache) {<a name="line.128"></a>
-<span class="sourceLineNo">129</span>        this.runningAverage = average;<a name="line.129"></a>
-<span class="sourceLineNo">130</span>      }<a name="line.130"></a>
-<span class="sourceLineNo">131</span>    }<a name="line.131"></a>
-<span class="sourceLineNo">132</span>  }<a name="line.132"></a>
-<span class="sourceLineNo">133</span>}<a name="line.133"></a>
+<span class="sourceLineNo">110</span>  public ByteBuffer getBuffer() {<a name="line.110"></a>
+<span class="sourceLineNo">111</span>    ByteBuffer bb = buffers.poll();<a name="line.111"></a>
+<span class="sourceLineNo">112</span>    if (bb != null) {<a name="line.112"></a>
+<span class="sourceLineNo">113</span>      long state;<a name="line.113"></a>
+<span class="sourceLineNo">114</span>      while (true) {<a name="line.114"></a>
+<span class="sourceLineNo">115</span>        long prevState = stateRef.get();<a name="line.115"></a>
+<span class="sourceLineNo">116</span>        state = subtractOneBufferFromState(prevState, bb.capacity());<a name="line.116"></a>
+<span class="sourceLineNo">117</span>        if (stateRef.compareAndSet(prevState, state)) {<a name="line.117"></a>
+<span class="sourceLineNo">118</span>          break;<a name="line.118"></a>
+<span class="sourceLineNo">119</span>        }<a name="line.119"></a>
+<span class="sourceLineNo">120</span>      }<a name="line.120"></a>
+<span class="sourceLineNo">121</span>      // Clear sets limit == capacity. Postion == 0.<a name="line.121"></a>
+<span class="sourceLineNo">122</span>      bb.clear();<a name="line.122"></a>
+<span class="sourceLineNo">123</span><a name="line.123"></a>
+<span class="sourceLineNo">124</span>      if (LOG.isTraceEnabled()) {<a name="line.124"></a>
+<span class="sourceLineNo">125</span>        int countOfBuffers = toCountOfBuffers(state);<a name="line.125"></a>
+<span class="sourceLineNo">126</span>        int totalCapacity = toTotalCapacity(state);<a name="line.126"></a>
+<span class="sourceLineNo">127</span>        LOG.trace("totalCapacity=" + totalCapacity + ", count=" + countOfBuffers);<a name="line.127"></a>
+<span class="sourceLineNo">128</span>      }<a name="line.128"></a>
+<span class="sourceLineNo">129</span>      return bb;<a name="line.129"></a>
+<span class="sourceLineNo">130</span>    }<a name="line.130"></a>
+<span class="sourceLineNo">131</span><a name="line.131"></a>
+<span class="sourceLineNo">132</span>    int runningAverage = runningAverageRef.get();<a name="line.132"></a>
+<span class="sourceLineNo">133</span>    bb = ByteBuffer.allocateDirect(runningAverage);<a name="line.133"></a>
+<span class="sourceLineNo">134</span><a name="line.134"></a>
+<span class="sourceLineNo">135</span>    if (LOG.isTraceEnabled()) {<a name="line.135"></a>
+<span class="sourceLineNo">136</span>      long allocations = allocationsRef.incrementAndGet();<a name="line.136"></a>
+<span class="sourceLineNo">137</span>      LOG.trace("runningAverage=" + runningAverage + ", alloctions=" + allocations);<a name="line.137"></a>
+<span class="sourceLineNo">138</span>    }<a name="line.138"></a>
+<span class="sourceLineNo">139</span>    return bb;<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>  public void putBuffer(ByteBuffer bb) {<a name="line.142"></a>
+<span class="sourceLineNo">143</span>    // If buffer is larger than we want to keep around, just let it go.<a name="line.143"></a>
+<span class="sourceLineNo">144</span>    if (bb.capacity() &gt; maxByteBufferSizeToCache) {<a name="line.144"></a>
+<span class="sourceLineNo">145</span>      return;<a name="line.145"></a>
+<span class="sourceLineNo">146</span>    }<a name="line.146"></a>
+<span class="sourceLineNo">147</span><a name="line.147"></a>
+<span class="sourceLineNo">148</span>    int countOfBuffers;<a name="line.148"></a>
+<span class="sourceLineNo">149</span>    int totalCapacity;<a name="line.149"></a>
+<span class="sourceLineNo">150</span>    while (true) {<a name="line.150"></a>
+<span class="sourceLineNo">151</span>      long prevState = stateRef.get();<a name="line.151"></a>
+<span class="sourceLineNo">152</span>      countOfBuffers = toCountOfBuffers(prevState);<a name="line.152"></a>
+<span class="sourceLineNo">153</span>      if (countOfBuffers &gt;= maxToCache) {<a name="line.153"></a>
+<span class="sourceLineNo">154</span>        if (LOG.isWarnEnabled()) {<a name="line.154"></a>
+<span class="sourceLineNo">155</span>          LOG.warn("At capacity: " + countOfBuffers);<a name="line.155"></a>
+<span class="sourceLineNo">156</span>        }<a name="line.156"></a>
+<span class="sourceLineNo">157</span>        return;<a name="line.157"></a>
+<span class="sourceLineNo">158</span>      }<a name="line.158"></a>
+<span class="sourceLineNo">159</span>      countOfBuffers++;<a name="line.159"></a>
+<span class="sourceLineNo">160</span>      assert 0 &lt; countOfBuffers &amp;&amp; countOfBuffers &lt;= maxToCache;<a name="line.160"></a>
+<span class="sourceLineNo">161</span><a name="line.161"></a>
+<span class="sourceLineNo">162</span>      totalCapacity = toTotalCapacity(prevState) + bb.capacity();<a name="line.162"></a>
+<span class="sourceLineNo">163</span>      if (totalCapacity &lt; 0) {<a name="line.163"></a>
+<span class="sourceLineNo">164</span>        if (LOG.isWarnEnabled()) {<a name="line.164"></a>
+<span class="sourceLineNo">165</span>          LOG.warn("Overflowed total capacity.");<a name="line.165"></a>
+<span class="sourceLineNo">166</span>        }<a name="line.166"></a>
+<span class="sourceLineNo">167</span>        return;<a name="line.167"></a>
+<span class="sourceLineNo">168</span>      }<a name="line.168"></a>
+<span class="sourceLineNo">169</span><a name="line.169"></a>
+<span class="sourceLineNo">170</span>      long state = toState(countOfBuffers, totalCapacity);<a name="line.170"></a>
+<span class="sourceLineNo">171</span>      if (stateRef.compareAndSet(prevState, state)) {<a name="line.171"></a>
+<span class="sourceLineNo">172</span>        break;<a name="line.172"></a>
+<span class="sourceLineNo">173</span>      }<a name="line.173"></a>
+<span class="sourceLineNo">174</span>    }<a name="line.174"></a>
+<span class="sourceLineNo">175</span><a name="line.175"></a>
+<span class="sourceLineNo">176</span>    // ConcurrentLinkQueue#offer says "this method will never return false"<a name="line.176"></a>
+<span class="sourceLineNo">177</span>    buffers.offer(bb);<a name="line.177"></a>
+<span class="sourceLineNo">178</span><a name="line.178"></a>
+<span class="sourceLineNo">179</span>    int runningAverageUpdate = Math.min(<a name="line.179"></a>
+<span class="sourceLineNo">180</span>        totalCapacity / countOfBuffers, // size will never be 0.<a name="line.180"></a>
+<span class="sourceLineNo">181</span>        maxByteBufferSizeToCache);<a name="line.181"></a>
+<span class="sourceLineNo">182</span>    while (true) {<a name="line.182"></a>
+<span class="sourceLineNo">183</span>      int prev = runningAverageRef.get();<a name="line.183"></a>
+<span class="sourceLineNo">184</span>      if (prev &gt;= runningAverageUpdate || // only rises, never recedes<a name="line.184"></a>
+<span class="sourceLineNo">185</span>          runningAverageRef.compareAndSet(prev, runningAverageUpdate)) {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>        break;<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>
 
 
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/f843f57d/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/FSHLog.RingBufferEventHandler.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/FSHLog.RingBufferEventHandler.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/FSHLog.RingBufferEventHandler.html
index ca636ce..06e7632 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/FSHLog.RingBufferEventHandler.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/wal/FSHLog.RingBufferEventHandler.html
@@ -1761,222 +1761,216 @@
 <span class="sourceLineNo">1753</span>        }<a name="line.1753"></a>
 <span class="sourceLineNo">1754</span><a name="line.1754"></a>
 <span class="sourceLineNo">1755</span>        // TODO: Check size and if big go ahead and call a sync if we have enough data.<a name="line.1755"></a>
-<span class="sourceLineNo">1756</span><a name="line.1756"></a>
-<span class="sourceLineNo">1757</span>        // If not a batch, return to consume more events from the ring buffer before proceeding;<a name="line.1757"></a>
-<span class="sourceLineNo">1758</span>        // we want to get up a batch of syncs and appends before we go do a filesystem sync.<a name="line.1758"></a>
-<span class="sourceLineNo">1759</span>        if (!endOfBatch || this.syncFuturesCount &lt;= 0) return;<a name="line.1759"></a>
-<span class="sourceLineNo">1760</span><a name="line.1760"></a>
-<span class="sourceLineNo">1761</span>        // Now we have a batch.<a name="line.1761"></a>
-<span class="sourceLineNo">1762</span><a name="line.1762"></a>
-<span class="sourceLineNo">1763</span>        if (LOG.isTraceEnabled()) {<a name="line.1763"></a>
-<span class="sourceLineNo">1764</span>          LOG.trace("Sequence=" + sequence + ", syncCount=" + this.syncFuturesCount);<a name="line.1764"></a>
-<span class="sourceLineNo">1765</span>        }<a name="line.1765"></a>
-<span class="sourceLineNo">1766</span><a name="line.1766"></a>
-<span class="sourceLineNo">1767</span>        if (this.exception == null) {<a name="line.1767"></a>
-<span class="sourceLineNo">1768</span>          // Below expects that the offer 'transfers' responsibility for the outstanding syncs to<a name="line.1768"></a>
-<span class="sourceLineNo">1769</span>          // the syncRunner. We should never get an exception in here.<a name="line.1769"></a>
-<span class="sourceLineNo">1770</span>          this.syncRunnerIndex = (this.syncRunnerIndex + 1) % this.syncRunners.length;<a name="line.1770"></a>
-<span class="sourceLineNo">1771</span>          try {<a name="line.1771"></a>
-<span class="sourceLineNo">1772</span>            this.syncRunners[this.syncRunnerIndex].offer(sequence, this.syncFutures,<a name="line.1772"></a>
-<span class="sourceLineNo">1773</span>              this.syncFuturesCount);<a name="line.1773"></a>
-<span class="sourceLineNo">1774</span>          } catch (Exception e) {<a name="line.1774"></a>
-<span class="sourceLineNo">1775</span>            // Should NEVER get here.<a name="line.1775"></a>
-<span class="sourceLineNo">1776</span>            requestLogRoll();<a name="line.1776"></a>
-<span class="sourceLineNo">1777</span>            this.exception = new DamagedWALException("Failed offering sync", e);<a name="line.1777"></a>
-<span class="sourceLineNo">1778</span>          }<a name="line.1778"></a>
+<span class="sourceLineNo">1756</span>        // This is a sync. If existing exception, fall through. Else look to see if batch.<a name="line.1756"></a>
+<span class="sourceLineNo">1757</span>        if (this.exception == null) {<a name="line.1757"></a>
+<span class="sourceLineNo">1758</span>          // If not a batch, return to consume more events from the ring buffer before proceeding;<a name="line.1758"></a>
+<span class="sourceLineNo">1759</span>          // we want to get up a batch of syncs and appends before we go do a filesystem sync.<a name="line.1759"></a>
+<span class="sourceLineNo">1760</span>          if (!endOfBatch || this.syncFuturesCount &lt;= 0) return;<a name="line.1760"></a>
+<span class="sourceLineNo">1761</span>          // Below expects that the offer 'transfers' responsibility for the outstanding syncs to<a name="line.1761"></a>
+<span class="sourceLineNo">1762</span>          // the syncRunner. We should never get an exception in here.<a name="line.1762"></a>
+<span class="sourceLineNo">1763</span>          this.syncRunnerIndex = (this.syncRunnerIndex + 1) % this.syncRunners.length;<a name="line.1763"></a>
+<span class="sourceLineNo">1764</span>          try {<a name="line.1764"></a>
+<span class="sourceLineNo">1765</span>            this.syncRunners[this.syncRunnerIndex].offer(sequence, this.syncFutures,<a name="line.1765"></a>
+<span class="sourceLineNo">1766</span>              this.syncFuturesCount);<a name="line.1766"></a>
+<span class="sourceLineNo">1767</span>          } catch (Exception e) {<a name="line.1767"></a>
+<span class="sourceLineNo">1768</span>            // Should NEVER get here.<a name="line.1768"></a>
+<span class="sourceLineNo">1769</span>            requestLogRoll();<a name="line.1769"></a>
+<span class="sourceLineNo">1770</span>            this.exception = new DamagedWALException("Failed offering sync", e);<a name="line.1770"></a>
+<span class="sourceLineNo">1771</span>          }<a name="line.1771"></a>
+<span class="sourceLineNo">1772</span>        }<a name="line.1772"></a>
+<span class="sourceLineNo">1773</span>        // We may have picked up an exception above trying to offer sync<a name="line.1773"></a>
+<span class="sourceLineNo">1774</span>        if (this.exception != null) {<a name="line.1774"></a>
+<span class="sourceLineNo">1775</span>          cleanupOutstandingSyncsOnException(sequence,<a name="line.1775"></a>
+<span class="sourceLineNo">1776</span>            this.exception instanceof DamagedWALException?<a name="line.1776"></a>
+<span class="sourceLineNo">1777</span>              this.exception:<a name="line.1777"></a>
+<span class="sourceLineNo">1778</span>              new DamagedWALException("On sync", this.exception));<a name="line.1778"></a>
 <span class="sourceLineNo">1779</span>        }<a name="line.1779"></a>
-<span class="sourceLineNo">1780</span>        // We may have picked up an exception above trying to offer sync<a name="line.1780"></a>
-<span class="sourceLineNo">1781</span>        if (this.exception != null) {<a name="line.1781"></a>
-<span class="sourceLineNo">1782</span>          cleanupOutstandingSyncsOnException(sequence,<a name="line.1782"></a>
-<span class="sourceLineNo">1783</span>            new DamagedWALException("On sync", this.exception));<a name="line.1783"></a>
-<span class="sourceLineNo">1784</span>        }<a name="line.1784"></a>
-<span class="sourceLineNo">1785</span>        attainSafePoint(sequence);<a name="line.1785"></a>
-<span class="sourceLineNo">1786</span>        this.syncFuturesCount = 0;<a name="line.1786"></a>
-<span class="sourceLineNo">1787</span>      } catch (Throwable t) {<a name="line.1787"></a>
-<span class="sourceLineNo">1788</span>        LOG.error("UNEXPECTED!!! syncFutures.length=" + this.syncFutures.length, t);<a name="line.1788"></a>
-<span class="sourceLineNo">1789</span>      }<a name="line.1789"></a>
+<span class="sourceLineNo">1780</span>        attainSafePoint(sequence);<a name="line.1780"></a>
+<span class="sourceLineNo">1781</span>        this.syncFuturesCount = 0;<a name="line.1781"></a>
+<span class="sourceLineNo">1782</span>      } catch (Throwable t) {<a name="line.1782"></a>
+<span class="sourceLineNo">1783</span>        LOG.error("UNEXPECTED!!! syncFutures.length=" + this.syncFutures.length, t);<a name="line.1783"></a>
+<span class="sourceLineNo">1784</span>      }<a name="line.1784"></a>
+<span class="sourceLineNo">1785</span>    }<a name="line.1785"></a>
+<span class="sourceLineNo">1786</span><a name="line.1786"></a>
+<span class="sourceLineNo">1787</span>    SafePointZigZagLatch attainSafePoint() {<a name="line.1787"></a>
+<span class="sourceLineNo">1788</span>      this.zigzagLatch = new SafePointZigZagLatch();<a name="line.1788"></a>
+<span class="sourceLineNo">1789</span>      return this.zigzagLatch;<a name="line.1789"></a>
 <span class="sourceLineNo">1790</span>    }<a name="line.1790"></a>
 <span class="sourceLineNo">1791</span><a name="line.1791"></a>
-<span class="sourceLineNo">1792</span>    SafePointZigZagLatch attainSafePoint() {<a name="line.1792"></a>
-<span class="sourceLineNo">1793</span>      this.zigzagLatch = new SafePointZigZagLatch();<a name="line.1793"></a>
-<span class="sourceLineNo">1794</span>      return this.zigzagLatch;<a name="line.1794"></a>
-<span class="sourceLineNo">1795</span>    }<a name="line.1795"></a>
-<span class="sourceLineNo">1796</span><a name="line.1796"></a>
-<span class="sourceLineNo">1797</span>    /**<a name="line.1797"></a>
-<span class="sourceLineNo">1798</span>     * Check if we should attain safe point.  If so, go there and then wait till signalled before<a name="line.1798"></a>
-<span class="sourceLineNo">1799</span>     * we proceeding.<a name="line.1799"></a>
-<span class="sourceLineNo">1800</span>     */<a name="line.1800"></a>
-<span class="sourceLineNo">1801</span>    private void attainSafePoint(final long currentSequence) {<a name="line.1801"></a>
-<span class="sourceLineNo">1802</span>      if (this.zigzagLatch == null || !this.zigzagLatch.isCocked()) return;<a name="line.1802"></a>
-<span class="sourceLineNo">1803</span>      // If here, another thread is waiting on us to get to safe point.  Don't leave it hanging.<a name="line.1803"></a>
-<span class="sourceLineNo">1804</span>      beforeWaitOnSafePoint();<a name="line.1804"></a>
-<span class="sourceLineNo">1805</span>      try {<a name="line.1805"></a>
-<span class="sourceLineNo">1806</span>        // Wait on outstanding syncers; wait for them to finish syncing (unless we've been<a name="line.1806"></a>
-<span class="sourceLineNo">1807</span>        // shutdown or unless our latch has been thrown because we have been aborted or unless<a name="line.1807"></a>
-<span class="sourceLineNo">1808</span>        // this WAL is broken and we can't get a sync/append to complete).<a name="line.1808"></a>
-<span class="sourceLineNo">1809</span>        while (!this.shutdown &amp;&amp; this.zigzagLatch.isCocked() &amp;&amp;<a name="line.1809"></a>
-<span class="sourceLineNo">1810</span>            highestSyncedSequence.get() &lt; currentSequence &amp;&amp;<a name="line.1810"></a>
-<span class="sourceLineNo">1811</span>            // We could be in here and all syncs are failing or failed. Check for this. Otherwise<a name="line.1811"></a>
-<span class="sourceLineNo">1812</span>            // we'll just be stuck here for ever. In other words, ensure there syncs running.<a name="line.1812"></a>
-<span class="sourceLineNo">1813</span>            isOutstandingSyncs()) {<a name="line.1813"></a>
-<span class="sourceLineNo">1814</span>          synchronized (this.safePointWaiter) {<a name="line.1814"></a>
-<span class="sourceLineNo">1815</span>            this.safePointWaiter.wait(0, 1);<a name="line.1815"></a>
-<span class="sourceLineNo">1816</span>          }<a name="line.1816"></a>
-<span class="sourceLineNo">1817</span>        }<a name="line.1817"></a>
-<span class="sourceLineNo">1818</span>        // Tell waiting thread we've attained safe point. Can clear this.throwable if set here<a name="line.1818"></a>
-<span class="sourceLineNo">1819</span>        // because we know that next event through the ringbuffer will be going to a new WAL<a name="line.1819"></a>
-<span class="sourceLineNo">1820</span>        // after we do the zigzaglatch dance.<a name="line.1820"></a>
-<span class="sourceLineNo">1821</span>        this.exception = null;<a name="line.1821"></a>
-<span class="sourceLineNo">1822</span>        this.zigzagLatch.safePointAttained();<a name="line.1822"></a>
-<span class="sourceLineNo">1823</span>      } catch (InterruptedException e) {<a name="line.1823"></a>
-<span class="sourceLineNo">1824</span>        LOG.warn("Interrupted ", e);<a name="line.1824"></a>
-<span class="sourceLineNo">1825</span>        Thread.currentThread().interrupt();<a name="line.1825"></a>
-<span class="sourceLineNo">1826</span>      }<a name="line.1826"></a>
-<span class="sourceLineNo">1827</span>    }<a name="line.1827"></a>
-<span class="sourceLineNo">1828</span><a name="line.1828"></a>
-<span class="sourceLineNo">1829</span>    /**<a name="line.1829"></a>
-<span class="sourceLineNo">1830</span>     * Append to the WAL.  Does all CP and WAL listener calls.<a name="line.1830"></a>
-<span class="sourceLineNo">1831</span>     * @param entry<a name="line.1831"></a>
-<span class="sourceLineNo">1832</span>     * @throws Exception<a name="line.1832"></a>
-<span class="sourceLineNo">1833</span>     */<a name="line.1833"></a>
-<span class="sourceLineNo">1834</span>    void append(final FSWALEntry entry) throws Exception {<a name="line.1834"></a>
-<span class="sourceLineNo">1835</span>      // TODO: WORK ON MAKING THIS APPEND FASTER. DOING WAY TOO MUCH WORK WITH CPs, PBing, etc.<a name="line.1835"></a>
-<span class="sourceLineNo">1836</span>      atHeadOfRingBufferEventHandlerAppend();<a name="line.1836"></a>
-<span class="sourceLineNo">1837</span><a name="line.1837"></a>
-<span class="sourceLineNo">1838</span>      long start = EnvironmentEdgeManager.currentTime();<a name="line.1838"></a>
-<span class="sourceLineNo">1839</span>      byte [] encodedRegionName = entry.getKey().getEncodedRegionName();<a name="line.1839"></a>
-<span class="sourceLineNo">1840</span>      long regionSequenceId = WALKey.NO_SEQUENCE_ID;<a name="line.1840"></a>
-<span class="sourceLineNo">1841</span>      try {<a name="line.1841"></a>
-<span class="sourceLineNo">1842</span>        // We are about to append this edit; update the region-scoped sequence number.  Do it<a name="line.1842"></a>
-<span class="sourceLineNo">1843</span>        // here inside this single appending/writing thread.  Events are ordered on the ringbuffer<a name="line.1843"></a>
-<span class="sourceLineNo">1844</span>        // so region sequenceids will also be in order.<a name="line.1844"></a>
-<span class="sourceLineNo">1845</span>        regionSequenceId = entry.stampRegionSequenceId();<a name="line.1845"></a>
-<span class="sourceLineNo">1846</span>        // Edits are empty, there is nothing to append.  Maybe empty when we are looking for a<a name="line.1846"></a>
-<span class="sourceLineNo">1847</span>        // region sequence id only, a region edit/sequence id that is not associated with an actual<a name="line.1847"></a>
-<span class="sourceLineNo">1848</span>        // edit. It has to go through all the rigmarole to be sure we have the right ordering.<a name="line.1848"></a>
-<span class="sourceLineNo">1849</span>        if (entry.getEdit().isEmpty()) {<a name="line.1849"></a>
-<span class="sourceLineNo">1850</span>          return;<a name="line.1850"></a>
-<span class="sourceLineNo">1851</span>        }<a name="line.1851"></a>
-<span class="sourceLineNo">1852</span><a name="line.1852"></a>
-<span class="sourceLineNo">1853</span>        // Coprocessor hook.<a name="line.1853"></a>
-<span class="sourceLineNo">1854</span>        if (!coprocessorHost.preWALWrite(entry.getHRegionInfo(), entry.getKey(),<a name="line.1854"></a>
-<span class="sourceLineNo">1855</span>            entry.getEdit())) {<a name="line.1855"></a>
-<span class="sourceLineNo">1856</span>          if (entry.getEdit().isReplay()) {<a name="line.1856"></a>
-<span class="sourceLineNo">1857</span>            // Set replication scope null so that this won't be replicated<a name="line.1857"></a>
-<span class="sourceLineNo">1858</span>            entry.getKey().setScopes(null);<a name="line.1858"></a>
-<span class="sourceLineNo">1859</span>          }<a name="line.1859"></a>
-<span class="sourceLineNo">1860</span>        }<a name="line.1860"></a>
-<span class="sourceLineNo">1861</span>        if (!listeners.isEmpty()) {<a name="line.1861"></a>
-<span class="sourceLineNo">1862</span>          for (WALActionsListener i: listeners) {<a name="line.1862"></a>
-<span class="sourceLineNo">1863</span>            // TODO: Why does listener take a table description and CPs take a regioninfo?  Fix.<a name="line.1863"></a>
-<span class="sourceLineNo">1864</span>            i.visitLogEntryBeforeWrite(entry.getHTableDescriptor(), entry.getKey(),<a name="line.1864"></a>
-<span class="sourceLineNo">1865</span>              entry.getEdit());<a name="line.1865"></a>
-<span class="sourceLineNo">1866</span>          }<a name="line.1866"></a>
-<span class="sourceLineNo">1867</span>        }<a name="line.1867"></a>
-<span class="sourceLineNo">1868</span><a name="line.1868"></a>
-<span class="sourceLineNo">1869</span>        writer.append(entry);<a name="line.1869"></a>
-<span class="sourceLineNo">1870</span>        assert highestUnsyncedSequence &lt; entry.getSequence();<a name="line.1870"></a>
-<span class="sourceLineNo">1871</span>        highestUnsyncedSequence = entry.getSequence();<a name="line.1871"></a>
-<span class="sourceLineNo">1872</span>        sequenceIdAccounting.update(encodedRegionName, entry.getFamilyNames(), regionSequenceId,<a name="line.1872"></a>
-<span class="sourceLineNo">1873</span>          entry.isInMemstore());<a name="line.1873"></a>
-<span class="sourceLineNo">1874</span>        coprocessorHost.postWALWrite(entry.getHRegionInfo(), entry.getKey(), entry.getEdit());<a name="line.1874"></a>
-<span class="sourceLineNo">1875</span>        // Update metrics.<a name="line.1875"></a>
-<span class="sourceLineNo">1876</span>        postAppend(entry, EnvironmentEdgeManager.currentTime() - start);<a name="line.1876"></a>
-<span class="sourceLineNo">1877</span>      } catch (Exception e) {<a name="line.1877"></a>
-<span class="sourceLineNo">1878</span>        String msg = "Append sequenceId=" + regionSequenceId +<a name="line.1878"></a>
-<span class="sourceLineNo">1879</span>          ", requesting roll of WAL";<a name="line.1879"></a>
-<span class="sourceLineNo">1880</span>        LOG.warn(msg, e);<a name="line.1880"></a>
-<span class="sourceLineNo">1881</span>        requestLogRoll();<a name="line.1881"></a>
-<span class="sourceLineNo">1882</span>        throw new DamagedWALException(msg, e);<a name="line.1882"></a>
-<span class="sourceLineNo">1883</span>      }<a name="line.1883"></a>
-<span class="sourceLineNo">1884</span>      numEntries.incrementAndGet();<a name="line.1884"></a>
-<span class="sourceLineNo">1885</span>    }<a name="line.1885"></a>
-<span class="sourceLineNo">1886</span><a name="line.1886"></a>
-<span class="sourceLineNo">1887</span>    @Override<a name="line.1887"></a>
-<span class="sourceLineNo">1888</span>    public void onStart() {<a name="line.1888"></a>
-<span class="sourceLineNo">1889</span>      for (SyncRunner syncRunner: this.syncRunners) syncRunner.start();<a name="line.1889"></a>
-<span class="sourceLineNo">1890</span>    }<a name="line.1890"></a>
+<span class="sourceLineNo">1792</span>    /**<a name="line.1792"></a>
+<span class="sourceLineNo">1793</span>     * Check if we should attain safe point.  If so, go there and then wait till signalled before<a name="line.1793"></a>
+<span class="sourceLineNo">1794</span>     * we proceeding.<a name="line.1794"></a>
+<span class="sourceLineNo">1795</span>     */<a name="line.1795"></a>
+<span class="sourceLineNo">1796</span>    private void attainSafePoint(final long currentSequence) {<a name="line.1796"></a>
+<span class="sourceLineNo">1797</span>      if (this.zigzagLatch == null || !this.zigzagLatch.isCocked()) return;<a name="line.1797"></a>
+<span class="sourceLineNo">1798</span>      // If here, another thread is waiting on us to get to safe point.  Don't leave it hanging.<a name="line.1798"></a>
+<span class="sourceLineNo">1799</span>      beforeWaitOnSafePoint();<a name="line.1799"></a>
+<span class="sourceLineNo">1800</span>      try {<a name="line.1800"></a>
+<span class="sourceLineNo">1801</span>        // Wait on outstanding syncers; wait for them to finish syncing (unless we've been<a name="line.1801"></a>
+<span class="sourceLineNo">1802</span>        // shutdown or unless our latch has been thrown because we have been aborted or unless<a name="line.1802"></a>
+<span class="sourceLineNo">1803</span>        // this WAL is broken and we can't get a sync/append to complete).<a name="line.1803"></a>
+<span class="sourceLineNo">1804</span>        while (!this.shutdown &amp;&amp; this.zigzagLatch.isCocked() &amp;&amp;<a name="line.1804"></a>
+<span class="sourceLineNo">1805</span>            highestSyncedSequence.get() &lt; currentSequence &amp;&amp;<a name="line.1805"></a>
+<span class="sourceLineNo">1806</span>            // We could be in here and all syncs are failing or failed. Check for this. Otherwise<a name="line.1806"></a>
+<span class="sourceLineNo">1807</span>            // we'll just be stuck here for ever. In other words, ensure there syncs running.<a name="line.1807"></a>
+<span class="sourceLineNo">1808</span>            isOutstandingSyncs()) {<a name="line.1808"></a>
+<span class="sourceLineNo">1809</span>          synchronized (this.safePointWaiter) {<a name="line.1809"></a>
+<span class="sourceLineNo">1810</span>            this.safePointWaiter.wait(0, 1);<a name="line.1810"></a>
+<span class="sourceLineNo">1811</span>          }<a name="line.1811"></a>
+<span class="sourceLineNo">1812</span>        }<a name="line.1812"></a>
+<span class="sourceLineNo">1813</span>        // Tell waiting thread we've attained safe point. Can clear this.throwable if set here<a name="line.1813"></a>
+<span class="sourceLineNo">1814</span>        // because we know that next event through the ringbuffer will be going to a new WAL<a name="line.1814"></a>
+<span class="sourceLineNo">1815</span>        // after we do the zigzaglatch dance.<a name="line.1815"></a>
+<span class="sourceLineNo">1816</span>        this.exception = null;<a name="line.1816"></a>
+<span class="sourceLineNo">1817</span>        this.zigzagLatch.safePointAttained();<a name="line.1817"></a>
+<span class="sourceLineNo">1818</span>      } catch (InterruptedException e) {<a name="line.1818"></a>
+<span class="sourceLineNo">1819</span>        LOG.warn("Interrupted ", e);<a name="line.1819"></a>
+<span class="sourceLineNo">1820</span>        Thread.currentThread().interrupt();<a name="line.1820"></a>
+<span class="sourceLineNo">1821</span>      }<a name="line.1821"></a>
+<span class="sourceLineNo">1822</span>    }<a name="line.1822"></a>
+<span class="sourceLineNo">1823</span><a name="line.1823"></a>
+<span class="sourceLineNo">1824</span>    /**<a name="line.1824"></a>
+<span class="sourceLineNo">1825</span>     * Append to the WAL.  Does all CP and WAL listener calls.<a name="line.1825"></a>
+<span class="sourceLineNo">1826</span>     * @param entry<a name="line.1826"></a>
+<span class="sourceLineNo">1827</span>     * @throws Exception<a name="line.1827"></a>
+<span class="sourceLineNo">1828</span>     */<a name="line.1828"></a>
+<span class="sourceLineNo">1829</span>    void append(final FSWALEntry entry) throws Exception {<a name="line.1829"></a>
+<span class="sourceLineNo">1830</span>      // TODO: WORK ON MAKING THIS APPEND FASTER. DOING WAY TOO MUCH WORK WITH CPs, PBing, etc.<a name="line.1830"></a>
+<span class="sourceLineNo">1831</span>      atHeadOfRingBufferEventHandlerAppend();<a name="line.1831"></a>
+<span class="sourceLineNo">1832</span><a name="line.1832"></a>
+<span class="sourceLineNo">1833</span>      long start = EnvironmentEdgeManager.currentTime();<a name="line.1833"></a>
+<span class="sourceLineNo">1834</span>      byte [] encodedRegionName = entry.getKey().getEncodedRegionName();<a name="line.1834"></a>
+<span class="sourceLineNo">1835</span>      long regionSequenceId = WALKey.NO_SEQUENCE_ID;<a name="line.1835"></a>
+<span class="sourceLineNo">1836</span>      try {<a name="line.1836"></a>
+<span class="sourceLineNo">1837</span>        // We are about to append this edit; update the region-scoped sequence number.  Do it<a name="line.1837"></a>
+<span class="sourceLineNo">1838</span>        // here inside this single appending/writing thread.  Events are ordered on the ringbuffer<a name="line.1838"></a>
+<span class="sourceLineNo">1839</span>        // so region sequenceids will also be in order.<a name="line.1839"></a>
+<span class="sourceLineNo">1840</span>        regionSequenceId = entry.stampRegionSequenceId();<a name="line.1840"></a>
+<span class="sourceLineNo">1841</span>        // Edits are empty, there is nothing to append.  Maybe empty when we are looking for a<a name="line.1841"></a>
+<span class="sourceLineNo">1842</span>        // region sequence id only, a region edit/sequence id that is not associated with an actual<a name="line.1842"></a>
+<span class="sourceLineNo">1843</span>        // edit. It has to go through all the rigmarole to be sure we have the right ordering.<a name="line.1843"></a>
+<span class="sourceLineNo">1844</span>        if (entry.getEdit().isEmpty()) {<a name="line.1844"></a>
+<span class="sourceLineNo">1845</span>          return;<a name="line.1845"></a>
+<span class="sourceLineNo">1846</span>        }<a name="line.1846"></a>
+<span class="sourceLineNo">1847</span><a name="line.1847"></a>
+<span class="sourceLineNo">1848</span>        // Coprocessor hook.<a name="line.1848"></a>
+<span class="sourceLineNo">1849</span>        if (!coprocessorHost.preWALWrite(entry.getHRegionInfo(), entry.getKey(),<a name="line.1849"></a>
+<span class="sourceLineNo">1850</span>            entry.getEdit())) {<a name="line.1850"></a>
+<span class="sourceLineNo">1851</span>          if (entry.getEdit().isReplay()) {<a name="line.1851"></a>
+<span class="sourceLineNo">1852</span>            // Set replication scope null so that this won't be replicated<a name="line.1852"></a>
+<span class="sourceLineNo">1853</span>            entry.getKey().setScopes(null);<a name="line.1853"></a>
+<span class="sourceLineNo">1854</span>          }<a name="line.1854"></a>
+<span class="sourceLineNo">1855</span>        }<a name="line.1855"></a>
+<span class="sourceLineNo">1856</span>        if (!listeners.isEmpty()) {<a name="line.1856"></a>
+<span class="sourceLineNo">1857</span>          for (WALActionsListener i: listeners) {<a name="line.1857"></a>
+<span class="sourceLineNo">1858</span>            // TODO: Why does listener take a table description and CPs take a regioninfo?  Fix.<a name="line.1858"></a>
+<span class="sourceLineNo">1859</span>            i.visitLogEntryBeforeWrite(entry.getHTableDescriptor(), entry.getKey(),<a name="line.1859"></a>
+<span class="sourceLineNo">1860</span>              entry.getEdit());<a name="line.1860"></a>
+<span class="sourceLineNo">1861</span>          }<a name="line.1861"></a>
+<span class="sourceLineNo">1862</span>        }<a name="line.1862"></a>
+<span class="sourceLineNo">1863</span><a name="line.1863"></a>
+<span class="sourceLineNo">1864</span>        writer.append(entry);<a name="line.1864"></a>
+<span class="sourceLineNo">1865</span>        assert highestUnsyncedSequence &lt; entry.getSequence();<a name="line.1865"></a>
+<span class="sourceLineNo">1866</span>        highestUnsyncedSequence = entry.getSequence();<a name="line.1866"></a>
+<span class="sourceLineNo">1867</span>        sequenceIdAccounting.update(encodedRegionName, entry.getFamilyNames(), regionSequenceId,<a name="line.1867"></a>
+<span class="sourceLineNo">1868</span>          entry.isInMemstore());<a name="line.1868"></a>
+<span class="sourceLineNo">1869</span>        coprocessorHost.postWALWrite(entry.getHRegionInfo(), entry.getKey(), entry.getEdit());<a name="line.1869"></a>
+<span class="sourceLineNo">1870</span>        // Update metrics.<a name="line.1870"></a>
+<span class="sourceLineNo">1871</span>        postAppend(entry, EnvironmentEdgeManager.currentTime() - start);<a name="line.1871"></a>
+<span class="sourceLineNo">1872</span>      } catch (Exception e) {<a name="line.1872"></a>
+<span class="sourceLineNo">1873</span>        String msg = "Append sequenceId=" + regionSequenceId + ", requesting roll of WAL";<a name="line.1873"></a>
+<span class="sourceLineNo">1874</span>        LOG.warn(msg, e);<a name="line.1874"></a>
+<span class="sourceLineNo">1875</span>        requestLogRoll();<a name="line.1875"></a>
+<span class="sourceLineNo">1876</span>        throw new DamagedWALException(msg, e);<a name="line.1876"></a>
+<span class="sourceLineNo">1877</span>      }<a name="line.1877"></a>
+<span class="sourceLineNo">1878</span>      numEntries.incrementAndGet();<a name="line.1878"></a>
+<span class="sourceLineNo">1879</span>    }<a name="line.1879"></a>
+<span class="sourceLineNo">1880</span><a name="line.1880"></a>
+<span class="sourceLineNo">1881</span>    @Override<a name="line.1881"></a>
+<span class="sourceLineNo">1882</span>    public void onStart() {<a name="line.1882"></a>
+<span class="sourceLineNo">1883</span>      for (SyncRunner syncRunner: this.syncRunners) syncRunner.start();<a name="line.1883"></a>
+<span class="sourceLineNo">1884</span>    }<a name="line.1884"></a>
+<span class="sourceLineNo">1885</span><a name="line.1885"></a>
+<span class="sourceLineNo">1886</span>    @Override<a name="line.1886"></a>
+<span class="sourceLineNo">1887</span>    public void onShutdown() {<a name="line.1887"></a>
+<span class="sourceLineNo">1888</span>      for (SyncRunner syncRunner: this.syncRunners) syncRunner.interrupt();<a name="line.1888"></a>
+<span class="sourceLineNo">1889</span>    }<a name="line.1889"></a>
+<span class="sourceLineNo">1890</span>  }<a name="line.1890"></a>
 <span class="sourceLineNo">1891</span><a name="line.1891"></a>
-<span class="sourceLineNo">1892</span>    @Override<a name="line.1892"></a>
-<span class="sourceLineNo">1893</span>    public void onShutdown() {<a name="line.1893"></a>
-<span class="sourceLineNo">1894</span>      for (SyncRunner syncRunner: this.syncRunners) syncRunner.interrupt();<a name="line.1894"></a>
-<span class="sourceLineNo">1895</span>    }<a name="line.1895"></a>
-<span class="sourceLineNo">1896</span>  }<a name="line.1896"></a>
-<span class="sourceLineNo">1897</span><a name="line.1897"></a>
-<span class="sourceLineNo">1898</span>  /**<a name="line.1898"></a>
-<span class="sourceLineNo">1899</span>   * Exposed for testing only.  Use to tricks like halt the ring buffer appending.<a name="line.1899"></a>
-<span class="sourceLineNo">1900</span>   */<a name="line.1900"></a>
-<span class="sourceLineNo">1901</span>  @VisibleForTesting<a name="line.1901"></a>
-<span class="sourceLineNo">1902</span>  void atHeadOfRingBufferEventHandlerAppend() {<a name="line.1902"></a>
-<span class="sourceLineNo">1903</span>    // Noop<a name="line.1903"></a>
-<span class="sourceLineNo">1904</span>  }<a name="line.1904"></a>
-<span class="sourceLineNo">1905</span><a name="line.1905"></a>
-<span class="sourceLineNo">1906</span>  private static IOException ensureIOException(final Throwable t) {<a name="line.1906"></a>
-<span class="sourceLineNo">1907</span>    return (t instanceof IOException)? (IOException)t: new IOException(t);<a name="line.1907"></a>
-<span class="sourceLineNo">1908</span>  }<a name="line.1908"></a>
-<span class="sourceLineNo">1909</span><a name="line.1909"></a>
-<span class="sourceLineNo">1910</span>  private static void usage() {<a name="line.1910"></a>
-<span class="sourceLineNo">1911</span>    System.err.println("Usage: FSHLog &lt;ARGS&gt;");<a name="line.1911"></a>
-<span class="sourceLineNo">1912</span>    System.err.println("Arguments:");<a name="line.1912"></a>
-<span class="sourceLineNo">1913</span>    System.err.println(" --dump  Dump textual representation of passed one or more files");<a name="line.1913"></a>
-<span class="sourceLineNo">1914</span>    System.err.println("         For example: " +<a name="line.1914"></a>
-<span class="sourceLineNo">1915</span>      "FSHLog --dump hdfs://example.com:9000/hbase/.logs/MACHINE/LOGFILE");<a name="line.1915"></a>
-<span class="sourceLineNo">1916</span>    System.err.println(" --split Split the passed directory of WAL logs");<a name="line.1916"></a>
-<span class="sourceLineNo">1917</span>    System.err.println("         For example: " +<a name="line.1917"></a>
-<span class="sourceLineNo">1918</span>      "FSHLog --split hdfs://example.com:9000/hbase/.logs/DIR");<a name="line.1918"></a>
-<span class="sourceLineNo">1919</span>  }<a name="line.1919"></a>
-<span class="sourceLineNo">1920</span><a name="line.1920"></a>
-<span class="sourceLineNo">1921</span>  /**<a name="line.1921"></a>
-<span class="sourceLineNo">1922</span>   * Pass one or more log file names and it will either dump out a text version<a name="line.1922"></a>
-<span class="sourceLineNo">1923</span>   * on &lt;code&gt;stdout&lt;/code&gt; or split the specified log files.<a name="line.1923"></a>
-<span class="sourceLineNo">1924</span>   *<a name="line.1924"></a>
-<span class="sourceLineNo">1925</span>   * @param args<a name="line.1925"></a>
-<span class="sourceLineNo">1926</span>   * @throws IOException<a name="line.1926"></a>
-<span class="sourceLineNo">1927</span>   */<a name="line.1927"></a>
-<span class="sourceLineNo">1928</span>  public static void main(String[] args) throws IOException {<a name="line.1928"></a>
-<span class="sourceLineNo">1929</span>    if (args.length &lt; 2) {<a name="line.1929"></a>
-<span class="sourceLineNo">1930</span>      usage();<a name="line.1930"></a>
-<span class="sourceLineNo">1931</span>      System.exit(-1);<a name="line.1931"></a>
-<span class="sourceLineNo">1932</span>    }<a name="line.1932"></a>
-<span class="sourceLineNo">1933</span>    // either dump using the WALPrettyPrinter or split, depending on args<a name="line.1933"></a>
-<span class="sourceLineNo">1934</span>    if (args[0].compareTo("--dump") == 0) {<a name="line.1934"></a>
-<span class="sourceLineNo">1935</span>      WALPrettyPrinter.run(Arrays.copyOfRange(args, 1, args.length));<a name="line.1935"></a>
-<span class="sourceLineNo">1936</span>    } else if (args[0].compareTo("--perf") == 0) {<a name="line.1936"></a>
-<span class="sourceLineNo">1937</span>      LOG.fatal("Please use the WALPerformanceEvaluation tool instead. i.e.:");<a name="line.1937"></a>
-<span class="sourceLineNo">1938</span>      LOG.fatal("\thbase org.apache.hadoop.hbase.wal.WALPerformanceEvaluation --iterations " +<a name="line.1938"></a>
-<span class="sourceLineNo">1939</span>          args[1]);<a name="line.1939"></a>
-<span class="sourceLineNo">1940</span>      System.exit(-1);<a name="line.1940"></a>
-<span class="sourceLineNo">1941</span>    } else if (args[0].compareTo("--split") == 0) {<a name="line.1941"></a>
-<span class="sourceLineNo">1942</span>      Configuration conf = HBaseConfiguration.create();<a name="line.1942"></a>
-<span class="sourceLineNo">1943</span>      for (int i = 1; i &lt; args.length; i++) {<a name="line.1943"></a>
-<span class="sourceLineNo">1944</span>        try {<a name="line.1944"></a>
-<span class="sourceLineNo">1945</span>          Path logPath = new Path(args[i]);<a name="line.1945"></a>
-<span class="sourceLineNo">1946</span>          FSUtils.setFsDefault(conf, logPath);<a name="line.1946"></a>
-<span class="sourceLineNo">1947</span>          split(conf, logPath);<a name="line.1947"></a>
-<span class="sourceLineNo">1948</span>        } catch (IOException t) {<a name="line.1948"></a>
-<span class="sourceLineNo">1949</span>          t.printStackTrace(System.err);<a name="line.1949"></a>
-<span class="sourceLineNo">1950</span>          System.exit(-1);<a name="line.1950"></a>
-<span class="sourceLineNo">1951</span>        }<a name="line.1951"></a>
-<span class="sourceLineNo">1952</span>      }<a name="line.1952"></a>
-<span class="sourceLineNo">1953</span>    } else {<a name="line.1953"></a>
-<span class="sourceLineNo">1954</span>      usage();<a name="line.1954"></a>
-<span class="sourceLineNo">1955</span>      System.exit(-1);<a name="line.1955"></a>
-<span class="sourceLineNo">1956</span>    }<a name="line.1956"></a>
-<span class="sourceLineNo">1957</span>  }<a name="line.1957"></a>
-<span class="sourceLineNo">1958</span><a name="line.1958"></a>
-<span class="sourceLineNo">1959</span>  /**<a name="line.1959"></a>
-<span class="sourceLineNo">1960</span>   * This method gets the pipeline for the current WAL.<a name="line.1960"></a>
-<span class="sourceLineNo">1961</span>   */<a name="line.1961"></a>
-<span class="sourceLineNo">1962</span>  @VisibleForTesting<a name="line.1962"></a>
-<span class="sourceLineNo">1963</span>  DatanodeInfo[] getPipeLine() {<a name="line.1963"></a>
-<span class="sourceLineNo">1964</span>    if (this.hdfs_out != null) {<a name="line.1964"></a>
-<span class="sourceLineNo">1965</span>      if (this.hdfs_out.getWrappedStream() instanceof DFSOutputStream) {<a name="line.1965"></a>
-<span class="sourceLineNo">1966</span>        return ((DFSOutputStream) this.hdfs_out.getWrappedStream()).getPipeline();<a name="line.1966"></a>
-<span class="sourceLineNo">1967</span>      }<a name="line.1967"></a>
-<span class="sourceLineNo">1968</span>    }<a name="line.1968"></a>
-<span class="sourceLineNo">1969</span>    return new DatanodeInfo[0];<a name="line.1969"></a>
-<span class="sourceLineNo">1970</span>  }<a name="line.1970"></a>
-<span class="sourceLineNo">1971</span>}<a name="line.1971"></a>
+<span class="sourceLineNo">1892</span>  /**<a name="line.1892"></a>
+<span class="sourceLineNo">1893</span>   * Exposed for testing only.  Use to tricks like halt the ring buffer appending.<a name="line.1893"></a>
+<span class="sourceLineNo">1894</span>   */<a name="line.1894"></a>
+<span class="sourceLineNo">1895</span>  @VisibleForTesting<a name="line.1895"></a>
+<span class="sourceLineNo">1896</span>  void atHeadOfRingBufferEventHandlerAppend() {<a name="line.1896"></a>
+<span class="sourceLineNo">1897</span>    // Noop<a name="line.1897"></a>
+<span class="sourceLineNo">1898</span>  }<a name="line.1898"></a>
+<span class="sourceLineNo">1899</span><a name="line.1899"></a>
+<span class="sourceLineNo">1900</span>  private static IOException ensureIOException(final Throwable t) {<a name="line.1900"></a>
+<span class="sourceLineNo">1901</span>    return (t instanceof IOException)? (IOException)t: new IOException(t);<a name="line.1901"></a>
+<span class="sourceLineNo">1902</span>  }<a name="line.1902"></a>
+<span class="sourceLineNo">1903</span><a name="line.1903"></a>
+<span class="sourceLineNo">1904</span>  private static void usage() {<a name="line.1904"></a>
+<span class="sourceLineNo">1905</span>    System.err.println("Usage: FSHLog &lt;ARGS&gt;");<a name="line.1905"></a>
+<span class="sourceLineNo">1906</span>    System.err.println("Arguments:");<a name="line.1906"></a>
+<span class="sourceLineNo">1907</span>    System.err.println(" --dump  Dump textual representation of passed one or more files");<a name="line.1907"></a>
+<span class="sourceLineNo">1908</span>    System.err.println("         For example: " +<a name="line.1908"></a>
+<span class="sourceLineNo">1909</span>      "FSHLog --dump hdfs://example.com:9000/hbase/.logs/MACHINE/LOGFILE");<a name="line.1909"></a>
+<span class="sourceLineNo">1910</span>    System.err.println(" --split Split the passed directory of WAL logs");<a name="line.1910"></a>
+<span class="sourceLineNo">1911</span>    System.err.println("         For example: " +<a name="line.1911"></a>
+<span class="sourceLineNo">1912</span>      "FSHLog --split hdfs://example.com:9000/hbase/.logs/DIR");<a name="line.1912"></a>
+<span class="sourceLineNo">1913</span>  }<a name="line.1913"></a>
+<span class="sourceLineNo">1914</span><a name="line.1914"></a>
+<span class="sourceLineNo">1915</span>  /**<a name="line.1915"></a>
+<span class="sourceLineNo">1916</span>   * Pass one or more log file names and it will either dump out a text version<a name="line.1916"></a>
+<span class="sourceLineNo">1917</span>   * on &lt;code&gt;stdout&lt;/code&gt; or split the specified log files.<a name="line.1917"></a>
+<span class="sourceLineNo">1918</span>   *<a name="line.1918"></a>
+<span class="sourceLineNo">1919</span>   * @param args<a name="line.1919"></a>
+<span class="sourceLineNo">1920</span>   * @throws IOException<a name="line.1920"></a>
+<span class="sourceLineNo">1921</span>   */<a name="line.1921"></a>
+<span class="sourceLineNo">1922</span>  public static void main(String[] args) throws IOException {<a name="line.1922"></a>
+<span class="sourceLineNo">1923</span>    if (args.length &lt; 2) {<a name="line.1923"></a>
+<span class="sourceLineNo">1924</span>      usage();<a name="line.1924"></a>
+<span class="sourceLineNo">1925</span>      System.exit(-1);<a name="line.1925"></a>
+<span class="sourceLineNo">1926</span>    }<a name="line.1926"></a>
+<span class="sourceLineNo">1927</span>    // either dump using the WALPrettyPrinter or split, depending on args<a name="line.1927"></a>
+<span class="sourceLineNo">1928</span>    if (args[0].compareTo("--dump") == 0) {<a name="line.1928"></a>
+<span class="sourceLineNo">1929</span>      WALPrettyPrinter.run(Arrays.copyOfRange(args, 1, args.length));<a name="line.1929"></a>
+<span class="sourceLineNo">1930</span>    } else if (args[0].compareTo("--perf") == 0) {<a name="line.1930"></a>
+<span class="sourceLineNo">1931</span>      LOG.fatal("Please use the WALPerformanceEvaluation tool instead. i.e.:");<a name="line.1931"></a>
+<span class="sourceLineNo">1932</span>      LOG.fatal("\thbase org.apache.hadoop.hbase.wal.WALPerformanceEvaluation --iterations " +<a name="line.1932"></a>
+<span class="sourceLineNo">1933</span>          args[1]);<a name="line.1933"></a>
+<span class="sourceLineNo">1934</span>      System.exit(-1);<a name="line.1934"></a>
+<span class="sourceLineNo">1935</span>    } else if (args[0].compareTo("--split") == 0) {<a name="line.1935"></a>
+<span class="sourceLineNo">1936</span>      Configuration conf = HBaseConfiguration.create();<a name="line.1936"></a>
+<span class="sourceLineNo">1937</span>      for (int i = 1; i &lt; args.length; i++) {<a name="line.1937"></a>
+<span class="sourceLineNo">1938</span>        try {<a name="line.1938"></a>
+<span class="sourceLineNo">1939</span>          Path logPath = new Path(args[i]);<a name="line.1939"></a>
+<span class="sourceLineNo">1940</span>          FSUtils.setFsDefault(conf, logPath);<a name="line.1940"></a>
+<span class="sourceLineNo">1941</span>          split(conf, logPath);<a name="line.1941"></a>
+<span class="sourceLineNo">1942</span>        } catch (IOException t) {<a name="line.1942"></a>
+<span class="sourceLineNo">1943</span>          t.printStackTrace(System.err);<a name="line.1943"></a>
+<span class="sourceLineNo">1944</span>          System.exit(-1);<a name="line.1944"></a>
+<span class="sourceLineNo">1945</span>        }<a name="line.1945"></a>
+<span class="sourceLineNo">1946</span>      }<a name="line.1946"></a>
+<span class="sourceLineNo">1947</span>    } else {<a name="line.1947"></a>
+<span class="sourceLineNo">1948</span>      usage();<a name="line.1948"></a>
+<span class="sourceLineNo">1949</span>      System.exit(-1);<a name="line.1949"></a>
+<span class="sourceLineNo">1950</span>    }<a name="line.1950"></a>
+<span class="sourceLineNo">1951</span>  }<a name="line.1951"></a>
+<span class="sourceLineNo">1952</span><a name="line.1952"></a>
+<span class="sourceLineNo">1953</span>  /**<a name="line.1953"></a>
+<span class="sourceLineNo">1954</span>   * This method gets the pipeline for the current WAL.<a name="line.1954"></a>
+<span class="sourceLineNo">1955</span>   */<a name="line.1955"></a>
+<span class="sourceLineNo">1956</span>  @VisibleForTesting<a name="line.1956"></a>
+<span class="sourceLineNo">1957</span>  DatanodeInfo[] getPipeLine() {<a name="line.1957"></a>
+<span class="sourceLineNo">1958</span>    if (this.hdfs_out != null) {<a name="line.1958"></a>
+<span class="sourceLineNo">1959</span>      if (this.hdfs_out.getWrappedStream() instanceof DFSOutputStream) {<a name="line.1959"></a>
+<span class="sourceLineNo">1960</span>        return ((DFSOutputStream) this.hdfs_out.getWrappedStream()).getPipeline();<a name="line.1960"></a>
+<span class="sourceLineNo">1961</span>      }<a name="line.1961"></a>
+<span class="sourceLineNo">1962</span>    }<a name="line.1962"></a>
+<span class="sourceLineNo">1963</span>    return new DatanodeInfo[0];<a name="line.1963"></a>
+<span class="sourceLineNo">1964</span>  }<a name="line.1964"></a>
+<span class="sourceLineNo">1965</span>}<a name="line.1965"></a>
 
 
 


Mime
View raw message