http://git-wip-us.apache.org/repos/asf/hbase-site/blob/5269c877/devapidocs/src-html/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceShipper.WorkerState.html
----------------------------------------------------------------------
diff --git 
a/devapidocs/src-html/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceShipper.WorkerState.html
 
b/devapidocs/src-html/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceShipper.WorkerState.html
index 484b604..70c4db7 100644
--- 
a/devapidocs/src-html/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceShipper.WorkerState.html
+++ 
b/devapidocs/src-html/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceShipper.WorkerState.html
@@ -95,222 +95,219 @@
 <span class="sourceLineNo">087</span>    
setWorkerState(WorkerState.RUNNING);<a name="line.87"></a>
 <span class="sourceLineNo">088</span>    // Loop until we close down<a 
name="line.88"></a>
 <span class="sourceLineNo">089</span>    while (isActive()) {<a 
name="line.89"></a>
-<span class="sourceLineNo">090</span>      int sleepMultiplier = 1;<a 
name="line.90"></a>
-<span class="sourceLineNo">091</span>      // Sleep until replication is 
enabled again<a name="line.91"></a>
-<span class="sourceLineNo">092</span>      if (!source.isPeerEnabled()) {<a 
name="line.92"></a>
-<span class="sourceLineNo">093</span>        if (sleepForRetries("Replication 
is disabled", sleepMultiplier)) {<a name="line.93"></a>
-<span class="sourceLineNo">094</span>          sleepMultiplier++;<a 
name="line.94"></a>
-<span class="sourceLineNo">095</span>        }<a name="line.95"></a>
-<span class="sourceLineNo">096</span>        continue;<a name="line.96"></a>
-<span class="sourceLineNo">097</span>      }<a name="line.97"></a>
-<span class="sourceLineNo">098</span>      try {<a name="line.98"></a>
-<span class="sourceLineNo">099</span>        WALEntryBatch entryBatch = 
entryReader.take();<a name="line.99"></a>
-<span class="sourceLineNo">100</span>        // the NO_MORE_DATA instance has 
no path so do not all shipEdits<a name="line.100"></a>
-<span class="sourceLineNo">101</span>        if (entryBatch == 
WALEntryBatch.NO_MORE_DATA) {<a name="line.101"></a>
-<span class="sourceLineNo">102</span>          noMoreData();<a 
name="line.102"></a>
-<span class="sourceLineNo">103</span>        } else {<a name="line.103"></a>
-<span class="sourceLineNo">104</span>          shipEdits(entryBatch);<a 
name="line.104"></a>
-<span class="sourceLineNo">105</span>        }<a name="line.105"></a>
-<span class="sourceLineNo">106</span>      } catch (InterruptedException e) 
{<a name="line.106"></a>
-<span class="sourceLineNo">107</span>        LOG.trace("Interrupted while 
waiting for next replication entry batch", e);<a name="line.107"></a>
-<span class="sourceLineNo">108</span>        
Thread.currentThread().interrupt();<a name="line.108"></a>
-<span class="sourceLineNo">109</span>      }<a name="line.109"></a>
-<span class="sourceLineNo">110</span>    }<a name="line.110"></a>
-<span class="sourceLineNo">111</span>    // If the worker exits run loop 
without finishing its task, mark it as stopped.<a name="line.111"></a>
-<span class="sourceLineNo">112</span>    if (!isFinished()) {<a 
name="line.112"></a>
-<span class="sourceLineNo">113</span>      
setWorkerState(WorkerState.STOPPED);<a name="line.113"></a>
-<span class="sourceLineNo">114</span>    } else {<a name="line.114"></a>
-<span class="sourceLineNo">115</span>      postFinish();<a name="line.115"></a>
-<span class="sourceLineNo">116</span>    }<a name="line.116"></a>
-<span class="sourceLineNo">117</span>  }<a name="line.117"></a>
-<span class="sourceLineNo">118</span><a name="line.118"></a>
-<span class="sourceLineNo">119</span>  // To be implemented by recovered 
shipper<a name="line.119"></a>
-<span class="sourceLineNo">120</span>  protected void noMoreData() {<a 
name="line.120"></a>
-<span class="sourceLineNo">121</span>  }<a name="line.121"></a>
-<span class="sourceLineNo">122</span><a name="line.122"></a>
-<span class="sourceLineNo">123</span>  // To be implemented by recovered 
shipper<a name="line.123"></a>
-<span class="sourceLineNo">124</span>  protected void postFinish() {<a 
name="line.124"></a>
-<span class="sourceLineNo">125</span>  }<a name="line.125"></a>
-<span class="sourceLineNo">126</span><a name="line.126"></a>
-<span class="sourceLineNo">127</span>  /**<a name="line.127"></a>
-<span class="sourceLineNo">128</span>   * Do the shipping logic<a 
name="line.128"></a>
-<span class="sourceLineNo">129</span>   */<a name="line.129"></a>
-<span class="sourceLineNo">130</span>  private void shipEdits(WALEntryBatch 
entryBatch) {<a name="line.130"></a>
-<span class="sourceLineNo">131</span>    List&lt;Entry&gt; entries = 
entryBatch.getWalEntries();<a name="line.131"></a>
-<span class="sourceLineNo">132</span>    int sleepMultiplier = 0;<a 
name="line.132"></a>
-<span class="sourceLineNo">133</span>    if (entries.isEmpty()) {<a 
name="line.133"></a>
-<span class="sourceLineNo">134</span>      if (updateLogPosition(entryBatch)) 
{<a name="line.134"></a>
-<span class="sourceLineNo">135</span>        // if there was nothing to ship 
and it's not an error<a name="line.135"></a>
-<span class="sourceLineNo">136</span>        // set "ageOfLastShippedOp" to 
&lt;now&gt; to indicate that we're current<a name="line.136"></a>
-<span class="sourceLineNo">137</span>        
source.getSourceMetrics().setAgeOfLastShippedOp(EnvironmentEdgeManager.currentTime(),<a
 name="line.137"></a>
-<span class="sourceLineNo">138</span>          walGroupId);<a 
name="line.138"></a>
-<span class="sourceLineNo">139</span>      }<a name="line.139"></a>
-<span class="sourceLineNo">140</span>      return;<a name="line.140"></a>
-<span class="sourceLineNo">141</span>    }<a name="line.141"></a>
-<span class="sourceLineNo">142</span>    int currentSize = (int) 
entryBatch.getHeapSize();<a name="line.142"></a>
-<span class="sourceLineNo">143</span>    while (isActive()) {<a 
name="line.143"></a>
-<span class="sourceLineNo">144</span>      try {<a name="line.144"></a>
-<span class="sourceLineNo">145</span>        try {<a name="line.145"></a>
-<span class="sourceLineNo">146</span>          
source.tryThrottle(currentSize);<a name="line.146"></a>
-<span class="sourceLineNo">147</span>        } catch (InterruptedException e) 
{<a name="line.147"></a>
-<span class="sourceLineNo">148</span>          LOG.debug("Interrupted while 
sleeping for throttling control");<a name="line.148"></a>
-<span class="sourceLineNo">149</span>          
Thread.currentThread().interrupt();<a name="line.149"></a>
-<span class="sourceLineNo">150</span>          // current thread might be 
interrupted to terminate<a name="line.150"></a>
-<span class="sourceLineNo">151</span>          // directly go back to while() 
for confirm this<a name="line.151"></a>
-<span class="sourceLineNo">152</span>          continue;<a name="line.152"></a>
-<span class="sourceLineNo">153</span>        }<a name="line.153"></a>
-<span class="sourceLineNo">154</span><a name="line.154"></a>
-<span class="sourceLineNo">155</span>        // create replicateContext here, 
so the entries can be GC'd upon return from this call<a name="line.155"></a>
-<span class="sourceLineNo">156</span>        // stack<a name="line.156"></a>
-<span class="sourceLineNo">157</span>        
ReplicationEndpoint.ReplicateContext replicateContext =<a name="line.157"></a>
-<span class="sourceLineNo">158</span>            new 
ReplicationEndpoint.ReplicateContext();<a name="line.158"></a>
-<span class="sourceLineNo">159</span>        
replicateContext.setEntries(entries).setSize(currentSize);<a 
name="line.159"></a>
-<span class="sourceLineNo">160</span>        
replicateContext.setWalGroupId(walGroupId);<a name="line.160"></a>
-<span class="sourceLineNo">161</span><a name="line.161"></a>
-<span class="sourceLineNo">162</span>        long startTimeNs = 
System.nanoTime();<a name="line.162"></a>
-<span class="sourceLineNo">163</span>        // send the edits to the 
endpoint. Will block until the edits are shipped and acknowledged<a 
name="line.163"></a>
-<span class="sourceLineNo">164</span>        boolean replicated = 
source.getReplicationEndpoint().replicate(replicateContext);<a 
name="line.164"></a>
-<span class="sourceLineNo">165</span>        long endTimeNs = 
System.nanoTime();<a name="line.165"></a>
-<span class="sourceLineNo">166</span><a name="line.166"></a>
-<span class="sourceLineNo">167</span>        if (!replicated) {<a 
name="line.167"></a>
-<span class="sourceLineNo">168</span>          continue;<a name="line.168"></a>
-<span class="sourceLineNo">169</span>        } else {<a name="line.169"></a>
-<span class="sourceLineNo">170</span>          sleepMultiplier = 
Math.max(sleepMultiplier - 1, 0);<a name="line.170"></a>
-<span class="sourceLineNo">171</span>        }<a name="line.171"></a>
-<span class="sourceLineNo">172</span>        // Clean up hfile references<a 
name="line.172"></a>
-<span class="sourceLineNo">173</span>        for (Entry entry : entries) {<a 
name="line.173"></a>
-<span class="sourceLineNo">174</span>          
cleanUpHFileRefs(entry.getEdit());<a name="line.174"></a>
-<span class="sourceLineNo">175</span>        }<a name="line.175"></a>
-<span class="sourceLineNo">176</span>        // Log and clean up WAL logs<a 
name="line.176"></a>
-<span class="sourceLineNo">177</span>        updateLogPosition(entryBatch);<a 
name="line.177"></a>
-<span class="sourceLineNo">178</span><a name="line.178"></a>
-<span class="sourceLineNo">179</span>        source.postShipEdits(entries, 
currentSize);<a name="line.179"></a>
-<span class="sourceLineNo">180</span>        // FIXME check relationship 
between wal group and overall<a name="line.180"></a>
-<span class="sourceLineNo">181</span>        
source.getSourceMetrics().shipBatch(entryBatch.getNbOperations(), 
currentSize,<a name="line.181"></a>
-<span class="sourceLineNo">182</span>          entryBatch.getNbHFiles());<a 
name="line.182"></a>
-<span class="sourceLineNo">183</span>        
source.getSourceMetrics().setAgeOfLastShippedOp(<a name="line.183"></a>
-<span class="sourceLineNo">184</span>          entries.get(entries.size() - 
1).getKey().getWriteTime(), walGroupId);<a name="line.184"></a>
-<span class="sourceLineNo">185</span>        if (LOG.isTraceEnabled()) {<a 
name="line.185"></a>
-<span class="sourceLineNo">186</span>          LOG.trace("Replicated " + 
entries.size() + " entries or " + entryBatch.getNbOperations()<a 
name="line.186"></a>
-<span class="sourceLineNo">187</span>              + " operations in " + 
((endTimeNs - startTimeNs) / 1000000) + " ms");<a name="line.187"></a>
-<span class="sourceLineNo">188</span>        }<a name="line.188"></a>
-<span class="sourceLineNo">189</span>        break;<a name="line.189"></a>
-<span class="sourceLineNo">190</span>      } catch (Exception ex) {<a 
name="line.190"></a>
-<span class="sourceLineNo">191</span>        
LOG.warn(source.getReplicationEndpoint().getClass().getName() + " threw unknown 
exception:"<a name="line.191"></a>
-<span class="sourceLineNo">192</span>            + 
org.apache.hadoop.util.StringUtils.stringifyException(ex));<a 
name="line.192"></a>
-<span class="sourceLineNo">193</span>        if 
(sleepForRetries("ReplicationEndpoint threw exception", sleepMultiplier)) {<a 
name="line.193"></a>
-<span class="sourceLineNo">194</span>          sleepMultiplier++;<a 
name="line.194"></a>
-<span class="sourceLineNo">195</span>        }<a name="line.195"></a>
-<span class="sourceLineNo">196</span>      }<a name="line.196"></a>
-<span class="sourceLineNo">197</span>    }<a name="line.197"></a>
-<span class="sourceLineNo">198</span>  }<a name="line.198"></a>
-<span class="sourceLineNo">199</span><a name="line.199"></a>
-<span class="sourceLineNo">200</span>  private void cleanUpHFileRefs(WALEdit 
edit) throws IOException {<a name="line.200"></a>
-<span class="sourceLineNo">201</span>    String peerId = source.getPeerId();<a 
name="line.201"></a>
-<span class="sourceLineNo">202</span>    if (peerId.contains("-")) {<a 
name="line.202"></a>
-<span class="sourceLineNo">203</span>      // peerClusterZnode will be in the 
form peerId + "-" + rsZNode.<a name="line.203"></a>
-<span class="sourceLineNo">204</span>      // A peerId will not have "-" in 
its name, see HBASE-11394<a name="line.204"></a>
-<span class="sourceLineNo">205</span>      peerId = peerId.split("-")[0];<a 
name="line.205"></a>
-<span class="sourceLineNo">206</span>    }<a name="line.206"></a>
-<span class="sourceLineNo">207</span>    List&lt;Cell&gt; cells = 
edit.getCells();<a name="line.207"></a>
-<span class="sourceLineNo">208</span>    int totalCells = cells.size();<a 
name="line.208"></a>
-<span class="sourceLineNo">209</span>    for (int i = 0; i &lt; totalCells; 
i++) {<a name="line.209"></a>
-<span class="sourceLineNo">210</span>      Cell cell = cells.get(i);<a 
name="line.210"></a>
-<span class="sourceLineNo">211</span>      if 
(CellUtil.matchingQualifier(cell, WALEdit.BULK_LOAD)) {<a name="line.211"></a>
-<span class="sourceLineNo">212</span>        BulkLoadDescriptor bld = 
WALEdit.getBulkLoadDescriptor(cell);<a name="line.212"></a>
-<span class="sourceLineNo">213</span>        List&lt;StoreDescriptor&gt; 
stores = bld.getStoresList();<a name="line.213"></a>
-<span class="sourceLineNo">214</span>        int totalStores = 
stores.size();<a name="line.214"></a>
-<span class="sourceLineNo">215</span>        for (int j = 0; j &lt; 
totalStores; j++) {<a name="line.215"></a>
-<span class="sourceLineNo">216</span>          List&lt;String&gt; 
storeFileList = stores.get(j).getStoreFileList();<a name="line.216"></a>
-<span class="sourceLineNo">217</span>          
source.getSourceManager().cleanUpHFileRefs(peerId, storeFileList);<a 
name="line.217"></a>
-<span class="sourceLineNo">218</span>          
source.getSourceMetrics().decrSizeOfHFileRefsQueue(storeFileList.size());<a 
name="line.218"></a>
-<span class="sourceLineNo">219</span>        }<a name="line.219"></a>
-<span class="sourceLineNo">220</span>      }<a name="line.220"></a>
-<span class="sourceLineNo">221</span>    }<a name="line.221"></a>
-<span class="sourceLineNo">222</span>  }<a name="line.222"></a>
-<span class="sourceLineNo">223</span><a name="line.223"></a>
-<span class="sourceLineNo">224</span>  private boolean 
updateLogPosition(WALEntryBatch batch) {<a name="line.224"></a>
-<span class="sourceLineNo">225</span>    boolean updated = false;<a 
name="line.225"></a>
-<span class="sourceLineNo">226</span>    // if end of file is true, then the 
logPositionAndCleanOldLogs method will remove the file<a name="line.226"></a>
-<span class="sourceLineNo">227</span>    // record on zk, so let's call it. 
The last wal position maybe zero if end of file is true and<a 
name="line.227"></a>
-<span class="sourceLineNo">228</span>    // there is no entry in the batch. It 
is OK because that the queue storage will ignore the zero<a name="line.228"></a>
-<span class="sourceLineNo">229</span>    // position and the file will be 
removed soon in cleanOldLogs.<a name="line.229"></a>
-<span class="sourceLineNo">230</span>    if (batch.isEndOfFile() || 
!batch.getLastWalPath().equals(currentPath) ||<a name="line.230"></a>
-<span class="sourceLineNo">231</span>      batch.getLastWalPosition() != 
currentPosition) {<a name="line.231"></a>
-<span class="sourceLineNo">232</span>      
source.getSourceManager().logPositionAndCleanOldLogs(source.getQueueId(),<a 
name="line.232"></a>
-<span class="sourceLineNo">233</span>        source.isRecovered(), batch);<a 
name="line.233"></a>
-<span class="sourceLineNo">234</span>      updated = true;<a 
name="line.234"></a>
-<span class="sourceLineNo">235</span>    }<a name="line.235"></a>
-<span class="sourceLineNo">236</span>    // if end of file is true, then we 
can just skip to the next file in queue.<a name="line.236"></a>
-<span class="sourceLineNo">237</span>    // the only exception is for 
recovered queue, if we reach the end of the queue, then there will<a 
name="line.237"></a>
-<span class="sourceLineNo">238</span>    // no more files so here the 
currentPath may be null.<a name="line.238"></a>
-<span class="sourceLineNo">239</span>    if (batch.isEndOfFile()) {<a 
name="line.239"></a>
-<span class="sourceLineNo">240</span>      currentPath = 
entryReader.getCurrentPath();<a name="line.240"></a>
-<span class="sourceLineNo">241</span>      currentPosition = 0L;<a 
name="line.241"></a>
-<span class="sourceLineNo">242</span>    } else {<a name="line.242"></a>
-<span class="sourceLineNo">243</span>      currentPath = 
batch.getLastWalPath();<a name="line.243"></a>
-<span class="sourceLineNo">244</span>      currentPosition = 
batch.getLastWalPosition();<a name="line.244"></a>
-<span class="sourceLineNo">245</span>    }<a name="line.245"></a>
-<span class="sourceLineNo">246</span>    return updated;<a name="line.246"></a>
-<span class="sourceLineNo">247</span>  }<a name="line.247"></a>
-<span class="sourceLineNo">248</span><a name="line.248"></a>
-<span class="sourceLineNo">249</span>  public void 
startup(UncaughtExceptionHandler handler) {<a name="line.249"></a>
-<span class="sourceLineNo">250</span>    String name = 
Thread.currentThread().getName();<a name="line.250"></a>
-<span class="sourceLineNo">251</span>    
Threads.setDaemonThreadRunning(this,<a name="line.251"></a>
-<span class="sourceLineNo">252</span>      name + ".replicationSource.shipper" 
+ walGroupId + "," + source.getQueueId(), handler);<a name="line.252"></a>
-<span class="sourceLineNo">253</span>  }<a name="line.253"></a>
-<span class="sourceLineNo">254</span><a name="line.254"></a>
-<span class="sourceLineNo">255</span>  Path getCurrentPath() {<a 
name="line.255"></a>
-<span class="sourceLineNo">256</span>    return 
entryReader.getCurrentPath();<a name="line.256"></a>
-<span class="sourceLineNo">257</span>  }<a name="line.257"></a>
-<span class="sourceLineNo">258</span><a name="line.258"></a>
-<span class="sourceLineNo">259</span>  long getCurrentPosition() {<a 
name="line.259"></a>
-<span class="sourceLineNo">260</span>    return currentPosition;<a 
name="line.260"></a>
-<span class="sourceLineNo">261</span>  }<a name="line.261"></a>
-<span class="sourceLineNo">262</span><a name="line.262"></a>
-<span class="sourceLineNo">263</span>  void 
setWALReader(ReplicationSourceWALReader entryReader) {<a name="line.263"></a>
-<span class="sourceLineNo">264</span>    this.entryReader = entryReader;<a 
name="line.264"></a>
-<span class="sourceLineNo">265</span>  }<a name="line.265"></a>
-<span class="sourceLineNo">266</span><a name="line.266"></a>
-<span class="sourceLineNo">267</span>  long getStartPosition() {<a 
name="line.267"></a>
-<span class="sourceLineNo">268</span>    return 0;<a name="line.268"></a>
-<span class="sourceLineNo">269</span>  }<a name="line.269"></a>
-<span class="sourceLineNo">270</span><a name="line.270"></a>
-<span class="sourceLineNo">271</span>  private boolean isActive() {<a 
name="line.271"></a>
-<span class="sourceLineNo">272</span>    return source.isSourceActive() 
&amp;&amp; state == WorkerState.RUNNING &amp;&amp; !isInterrupted();<a 
name="line.272"></a>
-<span class="sourceLineNo">273</span>  }<a name="line.273"></a>
-<span class="sourceLineNo">274</span><a name="line.274"></a>
-<span class="sourceLineNo">275</span>  protected final void 
setWorkerState(WorkerState state) {<a name="line.275"></a>
-<span class="sourceLineNo">276</span>    this.state = state;<a 
name="line.276"></a>
-<span class="sourceLineNo">277</span>  }<a name="line.277"></a>
-<span class="sourceLineNo">278</span><a name="line.278"></a>
-<span class="sourceLineNo">279</span>  void stopWorker() {<a 
name="line.279"></a>
-<span class="sourceLineNo">280</span>    
setWorkerState(WorkerState.STOPPED);<a name="line.280"></a>
-<span class="sourceLineNo">281</span>  }<a name="line.281"></a>
-<span class="sourceLineNo">282</span><a name="line.282"></a>
-<span class="sourceLineNo">283</span>  public boolean isFinished() {<a 
name="line.283"></a>
-<span class="sourceLineNo">284</span>    return state == 
WorkerState.FINISHED;<a name="line.284"></a>
-<span class="sourceLineNo">285</span>  }<a name="line.285"></a>
-<span class="sourceLineNo">286</span><a name="line.286"></a>
-<span class="sourceLineNo">287</span>  /**<a name="line.287"></a>
-<span class="sourceLineNo">288</span>   * Do the sleeping logic<a 
name="line.288"></a>
-<span class="sourceLineNo">289</span>   * @param msg Why we sleep<a 
name="line.289"></a>
-<span class="sourceLineNo">290</span>   * @param sleepMultiplier by how many 
times the default sleeping time is augmented<a name="line.290"></a>
-<span class="sourceLineNo">291</span>   * @return True if 
&lt;code&gt;sleepMultiplier&lt;/code&gt; is &amp;lt; 
&lt;code&gt;maxRetriesMultiplier&lt;/code&gt;<a name="line.291"></a>
-<span class="sourceLineNo">292</span>   */<a name="line.292"></a>
-<span class="sourceLineNo">293</span>  public boolean sleepForRetries(String 
msg, int sleepMultiplier) {<a name="line.293"></a>
-<span class="sourceLineNo">294</span>    try {<a name="line.294"></a>
-<span class="sourceLineNo">295</span>      if (LOG.isTraceEnabled()) {<a 
name="line.295"></a>
-<span class="sourceLineNo">296</span>        LOG.trace(msg + ", sleeping " + 
sleepForRetries + " times " + sleepMultiplier);<a name="line.296"></a>
-<span class="sourceLineNo">297</span>      }<a name="line.297"></a>
-<span class="sourceLineNo">298</span>      Thread.sleep(this.sleepForRetries * 
sleepMultiplier);<a name="line.298"></a>
-<span class="sourceLineNo">299</span>    } catch (InterruptedException e) {<a 
name="line.299"></a>
-<span class="sourceLineNo">300</span>      LOG.debug("Interrupted while 
sleeping between retries");<a name="line.300"></a>
-<span class="sourceLineNo">301</span>      
Thread.currentThread().interrupt();<a name="line.301"></a>
-<span class="sourceLineNo">302</span>    }<a name="line.302"></a>
-<span class="sourceLineNo">303</span>    return sleepMultiplier &lt; 
maxRetriesMultiplier;<a name="line.303"></a>
-<span class="sourceLineNo">304</span>  }<a name="line.304"></a>
-<span class="sourceLineNo">305</span>}<a name="line.305"></a>
+<span class="sourceLineNo">090</span>      // Sleep until replication is 
enabled again<a name="line.90"></a>
+<span class="sourceLineNo">091</span>      if (!source.isPeerEnabled()) {<a 
name="line.91"></a>
+<span class="sourceLineNo">092</span>        // The peer enabled check is in 
memory, not expensive, so do not need to increase the<a name="line.92"></a>
+<span class="sourceLineNo">093</span>        // sleep interval as it may cause 
a long lag when we enable the peer.<a name="line.93"></a>
+<span class="sourceLineNo">094</span>        sleepForRetries("Replication is 
disabled", 1);<a name="line.94"></a>
+<span class="sourceLineNo">095</span>        continue;<a name="line.95"></a>
+<span class="sourceLineNo">096</span>      }<a name="line.96"></a>
+<span class="sourceLineNo">097</span>      try {<a name="line.97"></a>
+<span class="sourceLineNo">098</span>        WALEntryBatch entryBatch = 
entryReader.take();<a name="line.98"></a>
+<span class="sourceLineNo">099</span>        // the NO_MORE_DATA instance has 
no path so do not all shipEdits<a name="line.99"></a>
+<span class="sourceLineNo">100</span>        if (entryBatch == 
WALEntryBatch.NO_MORE_DATA) {<a name="line.100"></a>
+<span class="sourceLineNo">101</span>          noMoreData();<a 
name="line.101"></a>
+<span class="sourceLineNo">102</span>        } else {<a name="line.102"></a>
+<span class="sourceLineNo">103</span>          shipEdits(entryBatch);<a 
name="line.103"></a>
+<span class="sourceLineNo">104</span>        }<a name="line.104"></a>
+<span class="sourceLineNo">105</span>      } catch (InterruptedException e) 
{<a name="line.105"></a>
+<span class="sourceLineNo">106</span>        LOG.trace("Interrupted while 
waiting for next replication entry batch", e);<a name="line.106"></a>
+<span class="sourceLineNo">107</span>        
Thread.currentThread().interrupt();<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>    // If the worker exits run loop 
without finishing its task, mark it as stopped.<a name="line.110"></a>
+<span class="sourceLineNo">111</span>    if (!isFinished()) {<a 
name="line.111"></a>
+<span class="sourceLineNo">112</span>      
setWorkerState(WorkerState.STOPPED);<a name="line.112"></a>
+<span class="sourceLineNo">113</span>    } else {<a name="line.113"></a>
+<span class="sourceLineNo">114</span>      postFinish();<a name="line.114"></a>
+<span class="sourceLineNo">115</span>    }<a name="line.115"></a>
+<span class="sourceLineNo">116</span>  }<a name="line.116"></a>
+<span class="sourceLineNo">117</span><a name="line.117"></a>
+<span class="sourceLineNo">118</span>  // To be implemented by recovered 
shipper<a name="line.118"></a>
+<span class="sourceLineNo">119</span>  protected void noMoreData() {<a 
name="line.119"></a>
+<span class="sourceLineNo">120</span>  }<a name="line.120"></a>
+<span class="sourceLineNo">121</span><a name="line.121"></a>
+<span class="sourceLineNo">122</span>  // To be implemented by recovered 
shipper<a name="line.122"></a>
+<span class="sourceLineNo">123</span>  protected void postFinish() {<a 
name="line.123"></a>
+<span class="sourceLineNo">124</span>  }<a name="line.124"></a>
+<span class="sourceLineNo">125</span><a name="line.125"></a>
+<span class="sourceLineNo">126</span>  /**<a name="line.126"></a>
+<span class="sourceLineNo">127</span>   * Do the shipping logic<a 
name="line.127"></a>
+<span class="sourceLineNo">128</span>   */<a name="line.128"></a>
+<span class="sourceLineNo">129</span>  private void shipEdits(WALEntryBatch 
entryBatch) {<a name="line.129"></a>
+<span class="sourceLineNo">130</span>    List&lt;Entry&gt; entries = 
entryBatch.getWalEntries();<a name="line.130"></a>
+<span class="sourceLineNo">131</span>    int sleepMultiplier = 0;<a 
name="line.131"></a>
+<span class="sourceLineNo">132</span>    if (entries.isEmpty()) {<a 
name="line.132"></a>
+<span class="sourceLineNo">133</span>      if (updateLogPosition(entryBatch)) 
{<a name="line.133"></a>
+<span class="sourceLineNo">134</span>        // if there was nothing to ship 
and it's not an error<a name="line.134"></a>
+<span class="sourceLineNo">135</span>        // set "ageOfLastShippedOp" to 
&lt;now&gt; to indicate that we're current<a name="line.135"></a>
+<span class="sourceLineNo">136</span>        
source.getSourceMetrics().setAgeOfLastShippedOp(EnvironmentEdgeManager.currentTime(),<a
 name="line.136"></a>
+<span class="sourceLineNo">137</span>          walGroupId);<a 
name="line.137"></a>
+<span class="sourceLineNo">138</span>      }<a name="line.138"></a>
+<span class="sourceLineNo">139</span>      return;<a name="line.139"></a>
+<span class="sourceLineNo">140</span>    }<a name="line.140"></a>
+<span class="sourceLineNo">141</span>    int currentSize = (int) 
entryBatch.getHeapSize();<a name="line.141"></a>
+<span class="sourceLineNo">142</span>    while (isActive()) {<a 
name="line.142"></a>
+<span class="sourceLineNo">143</span>      try {<a name="line.143"></a>
+<span class="sourceLineNo">144</span>        try {<a name="line.144"></a>
+<span class="sourceLineNo">145</span>          
source.tryThrottle(currentSize);<a name="line.145"></a>
+<span class="sourceLineNo">146</span>        } catch (InterruptedException e) 
{<a name="line.146"></a>
+<span class="sourceLineNo">147</span>          LOG.debug("Interrupted while 
sleeping for throttling control");<a name="line.147"></a>
+<span class="sourceLineNo">148</span>          
Thread.currentThread().interrupt();<a name="line.148"></a>
+<span class="sourceLineNo">149</span>          // current thread might be 
interrupted to terminate<a name="line.149"></a>
+<span class="sourceLineNo">150</span>          // directly go back to while() 
for confirm this<a name="line.150"></a>
+<span class="sourceLineNo">151</span>          continue;<a name="line.151"></a>
+<span class="sourceLineNo">152</span>        }<a name="line.152"></a>
+<span class="sourceLineNo">153</span><a name="line.153"></a>
+<span class="sourceLineNo">154</span>        // create replicateContext here, 
so the entries can be GC'd upon return from this call<a name="line.154"></a>
+<span class="sourceLineNo">155</span>        // stack<a name="line.155"></a>
+<span class="sourceLineNo">156</span>        
ReplicationEndpoint.ReplicateContext replicateContext =<a name="line.156"></a>
+<span class="sourceLineNo">157</span>            new 
ReplicationEndpoint.ReplicateContext();<a name="line.157"></a>
+<span class="sourceLineNo">158</span>        
replicateContext.setEntries(entries).setSize(currentSize);<a 
name="line.158"></a>
+<span class="sourceLineNo">159</span>        
replicateContext.setWalGroupId(walGroupId);<a name="line.159"></a>
+<span class="sourceLineNo">160</span><a name="line.160"></a>
+<span class="sourceLineNo">161</span>        long startTimeNs = 
System.nanoTime();<a name="line.161"></a>
+<span class="sourceLineNo">162</span>        // send the edits to the 
endpoint. Will block until the edits are shipped and acknowledged<a 
name="line.162"></a>
+<span class="sourceLineNo">163</span>        boolean replicated = 
source.getReplicationEndpoint().replicate(replicateContext);<a 
name="line.163"></a>
+<span class="sourceLineNo">164</span>        long endTimeNs = 
System.nanoTime();<a name="line.164"></a>
+<span class="sourceLineNo">165</span><a name="line.165"></a>
+<span class="sourceLineNo">166</span>        if (!replicated) {<a 
name="line.166"></a>
+<span class="sourceLineNo">167</span>          continue;<a name="line.167"></a>
+<span class="sourceLineNo">168</span>        } else {<a name="line.168"></a>
+<span class="sourceLineNo">169</span>          sleepMultiplier = 
Math.max(sleepMultiplier - 1, 0);<a name="line.169"></a>
+<span class="sourceLineNo">170</span>        }<a name="line.170"></a>
+<span class="sourceLineNo">171</span>        // Clean up hfile references<a 
name="line.171"></a>
+<span class="sourceLineNo">172</span>        for (Entry entry : entries) {<a 
name="line.172"></a>
+<span class="sourceLineNo">173</span>          
cleanUpHFileRefs(entry.getEdit());<a name="line.173"></a>
+<span class="sourceLineNo">174</span>        }<a name="line.174"></a>
+<span class="sourceLineNo">175</span>        // Log and clean up WAL logs<a 
name="line.175"></a>
+<span class="sourceLineNo">176</span>        updateLogPosition(entryBatch);<a 
name="line.176"></a>
+<span class="sourceLineNo">177</span><a name="line.177"></a>
+<span class="sourceLineNo">178</span>        source.postShipEdits(entries, 
currentSize);<a name="line.178"></a>
+<span class="sourceLineNo">179</span>        // FIXME check relationship 
between wal group and overall<a name="line.179"></a>
+<span class="sourceLineNo">180</span>        
source.getSourceMetrics().shipBatch(entryBatch.getNbOperations(), 
currentSize,<a name="line.180"></a>
+<span class="sourceLineNo">181</span>          entryBatch.getNbHFiles());<a 
name="line.181"></a>
+<span class="sourceLineNo">182</span>        
source.getSourceMetrics().setAgeOfLastShippedOp(<a name="line.182"></a>
+<span class="sourceLineNo">183</span>          entries.get(entries.size() - 
1).getKey().getWriteTime(), walGroupId);<a name="line.183"></a>
+<span class="sourceLineNo">184</span>        if (LOG.isTraceEnabled()) {<a 
name="line.184"></a>
+<span class="sourceLineNo">185</span>          LOG.trace("Replicated " + 
entries.size() + " entries or " + entryBatch.getNbOperations()<a 
name="line.185"></a>
+<span class="sourceLineNo">186</span>              + " operations in " + 
((endTimeNs - startTimeNs) / 1000000) + " ms");<a name="line.186"></a>
+<span class="sourceLineNo">187</span>        }<a name="line.187"></a>
+<span class="sourceLineNo">188</span>        break;<a name="line.188"></a>
+<span class="sourceLineNo">189</span>      } catch (Exception ex) {<a 
name="line.189"></a>
+<span class="sourceLineNo">190</span>        LOG.warn("{} threw unknown 
exception:",<a name="line.190"></a>
+<span class="sourceLineNo">191</span>          
source.getReplicationEndpoint().getClass().getName(), ex);<a 
name="line.191"></a>
+<span class="sourceLineNo">192</span>        if 
(sleepForRetries("ReplicationEndpoint threw exception", sleepMultiplier)) {<a 
name="line.192"></a>
+<span class="sourceLineNo">193</span>          sleepMultiplier++;<a 
name="line.193"></a>
+<span class="sourceLineNo">194</span>        }<a name="line.194"></a>
+<span class="sourceLineNo">195</span>      }<a name="line.195"></a>
+<span class="sourceLineNo">196</span>    }<a name="line.196"></a>
+<span class="sourceLineNo">197</span>  }<a name="line.197"></a>
+<span class="sourceLineNo">198</span><a name="line.198"></a>
+<span class="sourceLineNo">199</span>  private void cleanUpHFileRefs(WALEdit 
edit) throws IOException {<a name="line.199"></a>
+<span class="sourceLineNo">200</span>    String peerId = source.getPeerId();<a 
name="line.200"></a>
+<span class="sourceLineNo">201</span>    if (peerId.contains("-")) {<a 
name="line.201"></a>
+<span class="sourceLineNo">202</span>      // peerClusterZnode will be in the 
form peerId + "-" + rsZNode.<a name="line.202"></a>
+<span class="sourceLineNo">203</span>      // A peerId will not have "-" in 
its name, see HBASE-11394<a name="line.203"></a>
+<span class="sourceLineNo">204</span>      peerId = peerId.split("-")[0];<a 
name="line.204"></a>
+<span class="sourceLineNo">205</span>    }<a name="line.205"></a>
+<span class="sourceLineNo">206</span>    List&lt;Cell&gt; cells = 
edit.getCells();<a name="line.206"></a>
+<span class="sourceLineNo">207</span>    int totalCells = cells.size();<a 
name="line.207"></a>
+<span class="sourceLineNo">208</span>    for (int i = 0; i &lt; totalCells; 
i++) {<a name="line.208"></a>
+<span class="sourceLineNo">209</span>      Cell cell = cells.get(i);<a 
name="line.209"></a>
+<span class="sourceLineNo">210</span>      if 
(CellUtil.matchingQualifier(cell, WALEdit.BULK_LOAD)) {<a name="line.210"></a>
+<span class="sourceLineNo">211</span>        BulkLoadDescriptor bld = 
WALEdit.getBulkLoadDescriptor(cell);<a name="line.211"></a>
+<span class="sourceLineNo">212</span>        List&lt;StoreDescriptor&gt; 
stores = bld.getStoresList();<a name="line.212"></a>
+<span class="sourceLineNo">213</span>        int totalStores = 
stores.size();<a name="line.213"></a>
+<span class="sourceLineNo">214</span>        for (int j = 0; j &lt; 
totalStores; j++) {<a name="line.214"></a>
+<span class="sourceLineNo">215</span>          List&lt;String&gt; 
storeFileList = stores.get(j).getStoreFileList();<a name="line.215"></a>
+<span class="sourceLineNo">216</span>          
source.getSourceManager().cleanUpHFileRefs(peerId, storeFileList);<a 
name="line.216"></a>
+<span class="sourceLineNo">217</span>          
source.getSourceMetrics().decrSizeOfHFileRefsQueue(storeFileList.size());<a 
name="line.217"></a>
+<span class="sourceLineNo">218</span>        }<a name="line.218"></a>
+<span class="sourceLineNo">219</span>      }<a name="line.219"></a>
+<span class="sourceLineNo">220</span>    }<a name="line.220"></a>
+<span class="sourceLineNo">221</span>  }<a name="line.221"></a>
+<span class="sourceLineNo">222</span><a name="line.222"></a>
+<span class="sourceLineNo">223</span>  private boolean 
updateLogPosition(WALEntryBatch batch) {<a name="line.223"></a>
+<span class="sourceLineNo">224</span>    boolean updated = false;<a 
name="line.224"></a>
+<span class="sourceLineNo">225</span>    // if end of file is true, then the 
logPositionAndCleanOldLogs method will remove the file<a name="line.225"></a>
+<span class="sourceLineNo">226</span>    // record on zk, so let's call it. 
The last wal position maybe zero if end of file is true and<a 
name="line.226"></a>
+<span class="sourceLineNo">227</span>    // there is no entry in the batch. It 
is OK because that the queue storage will ignore the zero<a name="line.227"></a>
+<span class="sourceLineNo">228</span>    // position and the file will be 
removed soon in cleanOldLogs.<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    if (batch.isEndOfFile() || 
!batch.getLastWalPath().equals(currentPath) ||<a name="line.229"></a>
+<span class="sourceLineNo">230</span>      batch.getLastWalPosition() != 
currentPosition) {<a name="line.230"></a>
+<span class="sourceLineNo">231</span>      
source.getSourceManager().logPositionAndCleanOldLogs(source.getQueueId(),<a 
name="line.231"></a>
+<span class="sourceLineNo">232</span>        source.isRecovered(), batch);<a 
name="line.232"></a>
+<span class="sourceLineNo">233</span>      updated = true;<a 
name="line.233"></a>
+<span class="sourceLineNo">234</span>    }<a name="line.234"></a>
+<span class="sourceLineNo">235</span>    // if end of file is true, then we 
can just skip to the next file in queue.<a name="line.235"></a>
+<span class="sourceLineNo">236</span>    // the only exception is for 
recovered queue, if we reach the end of the queue, then there will<a 
name="line.236"></a>
+<span class="sourceLineNo">237</span>    // no more files so here the 
currentPath may be null.<a name="line.237"></a>
+<span class="sourceLineNo">238</span>    if (batch.isEndOfFile()) {<a 
name="line.238"></a>
+<span class="sourceLineNo">239</span>      currentPath = 
entryReader.getCurrentPath();<a name="line.239"></a>
+<span class="sourceLineNo">240</span>      currentPosition = 0L;<a 
name="line.240"></a>
+<span class="sourceLineNo">241</span>    } else {<a name="line.241"></a>
+<span class="sourceLineNo">242</span>      currentPath = 
batch.getLastWalPath();<a name="line.242"></a>
+<span class="sourceLineNo">243</span>      currentPosition = 
batch.getLastWalPosition();<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    }<a name="line.244"></a>
+<span class="sourceLineNo">245</span>    return updated;<a name="line.245"></a>
+<span class="sourceLineNo">246</span>  }<a name="line.246"></a>
+<span class="sourceLineNo">247</span><a name="line.247"></a>
+<span class="sourceLineNo">248</span>  public void 
startup(UncaughtExceptionHandler handler) {<a name="line.248"></a>
+<span class="sourceLineNo">249</span>    String name = 
Thread.currentThread().getName();<a name="line.249"></a>
+<span class="sourceLineNo">250</span>    
Threads.setDaemonThreadRunning(this,<a name="line.250"></a>
+<span class="sourceLineNo">251</span>      name + ".replicationSource.shipper" 
+ walGroupId + "," + source.getQueueId(), handler);<a name="line.251"></a>
+<span class="sourceLineNo">252</span>  }<a name="line.252"></a>
+<span class="sourceLineNo">253</span><a name="line.253"></a>
+<span class="sourceLineNo">254</span>  Path getCurrentPath() {<a 
name="line.254"></a>
+<span class="sourceLineNo">255</span>    return 
entryReader.getCurrentPath();<a name="line.255"></a>
+<span class="sourceLineNo">256</span>  }<a name="line.256"></a>
+<span class="sourceLineNo">257</span><a name="line.257"></a>
+<span class="sourceLineNo">258</span>  long getCurrentPosition() {<a 
name="line.258"></a>
+<span class="sourceLineNo">259</span>    return currentPosition;<a 
name="line.259"></a>
+<span class="sourceLineNo">260</span>  }<a name="line.260"></a>
+<span class="sourceLineNo">261</span><a name="line.261"></a>
+<span class="sourceLineNo">262</span>  void 
setWALReader(ReplicationSourceWALReader entryReader) {<a name="line.262"></a>
+<span class="sourceLineNo">263</span>    this.entryReader = entryReader;<a 
name="line.263"></a>
+<span class="sourceLineNo">264</span>  }<a name="line.264"></a>
+<span class="sourceLineNo">265</span><a name="line.265"></a>
+<span class="sourceLineNo">266</span>  long getStartPosition() {<a 
name="line.266"></a>
+<span class="sourceLineNo">267</span>    return 0;<a name="line.267"></a>
+<span class="sourceLineNo">268</span>  }<a name="line.268"></a>
+<span class="sourceLineNo">269</span><a name="line.269"></a>
+<span class="sourceLineNo">270</span>  private boolean isActive() {<a 
name="line.270"></a>
+<span class="sourceLineNo">271</span>    return source.isSourceActive() 
&amp;&amp; state == WorkerState.RUNNING &amp;&amp; !isInterrupted();<a 
name="line.271"></a>
+<span class="sourceLineNo">272</span>  }<a name="line.272"></a>
+<span class="sourceLineNo">273</span><a name="line.273"></a>
+<span class="sourceLineNo">274</span>  protected final void 
setWorkerState(WorkerState state) {<a name="line.274"></a>
+<span class="sourceLineNo">275</span>    this.state = state;<a 
name="line.275"></a>
+<span class="sourceLineNo">276</span>  }<a name="line.276"></a>
+<span class="sourceLineNo">277</span><a name="line.277"></a>
+<span class="sourceLineNo">278</span>  void stopWorker() {<a 
name="line.278"></a>
+<span class="sourceLineNo">279</span>    
setWorkerState(WorkerState.STOPPED);<a name="line.279"></a>
+<span class="sourceLineNo">280</span>  }<a name="line.280"></a>
+<span class="sourceLineNo">281</span><a name="line.281"></a>
+<span class="sourceLineNo">282</span>  public boolean isFinished() {<a 
name="line.282"></a>
+<span class="sourceLineNo">283</span>    return state == 
WorkerState.FINISHED;<a name="line.283"></a>
+<span class="sourceLineNo">284</span>  }<a name="line.284"></a>
+<span class="sourceLineNo">285</span><a name="line.285"></a>
+<span class="sourceLineNo">286</span>  /**<a name="line.286"></a>
+<span class="sourceLineNo">287</span>   * Do the sleeping logic<a 
name="line.287"></a>
+<span class="sourceLineNo">288</span>   * @param msg Why we sleep<a 
name="line.288"></a>
+<span class="sourceLineNo">289</span>   * @param sleepMultiplier by how many 
times the default sleeping time is augmented<a name="line.289"></a>
+<span class="sourceLineNo">290</span>   * @return True if 
&lt;code&gt;sleepMultiplier&lt;/code&gt; is &amp;lt; 
&lt;code&gt;maxRetriesMultiplier&lt;/code&gt;<a name="line.290"></a>
+<span class="sourceLineNo">291</span>   */<a name="line.291"></a>
+<span class="sourceLineNo">292</span>  public boolean sleepForRetries(String 
msg, int sleepMultiplier) {<a name="line.292"></a>
+<span class="sourceLineNo">293</span>    try {<a name="line.293"></a>
+<span class="sourceLineNo">294</span>      LOG.trace("{}, sleeping {} times 
{}", msg, sleepForRetries, sleepMultiplier);<a name="line.294"></a>
+<span class="sourceLineNo">295</span>      Thread.sleep(this.sleepForRetries * 
sleepMultiplier);<a name="line.295"></a>
+<span class="sourceLineNo">296</span>    } catch (InterruptedException e) {<a 
name="line.296"></a>
+<span class="sourceLineNo">297</span>      LOG.debug("Interrupted while 
sleeping between retries");<a name="line.297"></a>
+<span class="sourceLineNo">298</span>      
Thread.currentThread().interrupt();<a name="line.298"></a>
+<span class="sourceLineNo">299</span>    }<a name="line.299"></a>
+<span class="sourceLineNo">300</span>    return sleepMultiplier &lt; 
maxRetriesMultiplier;<a name="line.300"></a>
+<span class="sourceLineNo">301</span>  }<a name="line.301"></a>
+<span class="sourceLineNo">302</span>}<a name="line.302"></a>
 
 
 

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/5269c877/devapidocs/src-html/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceShipper.html
----------------------------------------------------------------------
diff --git 
a/devapidocs/src-html/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceShipper.html
 
b/devapidocs/src-html/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceShipper.html
index 484b604..70c4db7 100644
--- 
a/devapidocs/src-html/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceShipper.html
+++ 
b/devapidocs/src-html/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceShipper.html
@@ -95,222 +95,219 @@
 <span class="sourceLineNo">087</span>    
setWorkerState(WorkerState.RUNNING);<a name="line.87"></a>
 <span class="sourceLineNo">088</span>    // Loop until we close down<a 
name="line.88"></a>
 <span class="sourceLineNo">089</span>    while (isActive()) {<a 
name="line.89"></a>
-<span class="sourceLineNo">090</span>      int sleepMultiplier = 1;<a 
name="line.90"></a>
-<span class="sourceLineNo">091</span>      // Sleep until replication is 
enabled again<a name="line.91"></a>
-<span class="sourceLineNo">092</span>      if (!source.isPeerEnabled()) {<a 
name="line.92"></a>
-<span class="sourceLineNo">093</span>        if (sleepForRetries("Replication 
is disabled", sleepMultiplier)) {<a name="line.93"></a>
-<span class="sourceLineNo">094</span>          sleepMultiplier++;<a 
name="line.94"></a>
-<span class="sourceLineNo">095</span>        }<a name="line.95"></a>
-<span class="sourceLineNo">096</span>        continue;<a name="line.96"></a>
-<span class="sourceLineNo">097</span>      }<a name="line.97"></a>
-<span class="sourceLineNo">098</span>      try {<a name="line.98"></a>
-<span class="sourceLineNo">099</span>        WALEntryBatch entryBatch = 
entryReader.take();<a name="line.99"></a>
-<span class="sourceLineNo">100</span>        // the NO_MORE_DATA instance has 
no path so do not all shipEdits<a name="line.100"></a>
-<span class="sourceLineNo">101</span>        if (entryBatch == 
WALEntryBatch.NO_MORE_DATA) {<a name="line.101"></a>
-<span class="sourceLineNo">102</span>          noMoreData();<a 
name="line.102"></a>
-<span class="sourceLineNo">103</span>        } else {<a name="line.103"></a>
-<span class="sourceLineNo">104</span>          shipEdits(entryBatch);<a 
name="line.104"></a>
-<span class="sourceLineNo">105</span>        }<a name="line.105"></a>
-<span class="sourceLineNo">106</span>      } catch (InterruptedException e) 
{<a name="line.106"></a>
-<span class="sourceLineNo">107</span>        LOG.trace("Interrupted while 
waiting for next replication entry batch", e);<a name="line.107"></a>
-<span class="sourceLineNo">108</span>        
Thread.currentThread().interrupt();<a name="line.108"></a>
-<span class="sourceLineNo">109</span>      }<a name="line.109"></a>
-<span class="sourceLineNo">110</span>    }<a name="line.110"></a>
-<span class="sourceLineNo">111</span>    // If the worker exits run loop 
without finishing its task, mark it as stopped.<a name="line.111"></a>
-<span class="sourceLineNo">112</span>    if (!isFinished()) {<a 
name="line.112"></a>
-<span class="sourceLineNo">113</span>      
setWorkerState(WorkerState.STOPPED);<a name="line.113"></a>
-<span class="sourceLineNo">114</span>    } else {<a name="line.114"></a>
-<span class="sourceLineNo">115</span>      postFinish();<a name="line.115"></a>
-<span class="sourceLineNo">116</span>    }<a name="line.116"></a>
-<span class="sourceLineNo">117</span>  }<a name="line.117"></a>
-<span class="sourceLineNo">118</span><a name="line.118"></a>
-<span class="sourceLineNo">119</span>  // To be implemented by recovered 
shipper<a name="line.119"></a>
-<span class="sourceLineNo">120</span>  protected void noMoreData() {<a 
name="line.120"></a>
-<span class="sourceLineNo">121</span>  }<a name="line.121"></a>
-<span class="sourceLineNo">122</span><a name="line.122"></a>
-<span class="sourceLineNo">123</span>  // To be implemented by recovered 
shipper<a name="line.123"></a>
-<span class="sourceLineNo">124</span>  protected void postFinish() {<a 
name="line.124"></a>
-<span class="sourceLineNo">125</span>  }<a name="line.125"></a>
-<span class="sourceLineNo">126</span><a name="line.126"></a>
-<span class="sourceLineNo">127</span>  /**<a name="line.127"></a>
-<span class="sourceLineNo">128</span>   * Do the shipping logic<a 
name="line.128"></a>
-<span class="sourceLineNo">129</span>   */<a name="line.129"></a>
-<span class="sourceLineNo">130</span>  private void shipEdits(WALEntryBatch 
entryBatch) {<a name="line.130"></a>
-<span class="sourceLineNo">131</span>    List&lt;Entry&gt; entries = 
entryBatch.getWalEntries();<a name="line.131"></a>
-<span class="sourceLineNo">132</span>    int sleepMultiplier = 0;<a 
name="line.132"></a>
-<span class="sourceLineNo">133</span>    if (entries.isEmpty()) {<a 
name="line.133"></a>
-<span class="sourceLineNo">134</span>      if (updateLogPosition(entryBatch)) 
{<a name="line.134"></a>
-<span class="sourceLineNo">135</span>        // if there was nothing to ship 
and it's not an error<a name="line.135"></a>
-<span class="sourceLineNo">136</span>        // set "ageOfLastShippedOp" to 
&lt;now&gt; to indicate that we're current<a name="line.136"></a>
-<span class="sourceLineNo">137</span>        
source.getSourceMetrics().setAgeOfLastShippedOp(EnvironmentEdgeManager.currentTime(),<a
 name="line.137"></a>
-<span class="sourceLineNo">138</span>          walGroupId);<a 
name="line.138"></a>
-<span class="sourceLineNo">139</span>      }<a name="line.139"></a>
-<span class="sourceLineNo">140</span>      return;<a name="line.140"></a>
-<span class="sourceLineNo">141</span>    }<a name="line.141"></a>
-<span class="sourceLineNo">142</span>    int currentSize = (int) 
entryBatch.getHeapSize();<a name="line.142"></a>
-<span class="sourceLineNo">143</span>    while (isActive()) {<a 
name="line.143"></a>
-<span class="sourceLineNo">144</span>      try {<a name="line.144"></a>
-<span class="sourceLineNo">145</span>        try {<a name="line.145"></a>
-<span class="sourceLineNo">146</span>          
source.tryThrottle(currentSize);<a name="line.146"></a>
-<span class="sourceLineNo">147</span>        } catch (InterruptedException e) 
{<a name="line.147"></a>
-<span class="sourceLineNo">148</span>          LOG.debug("Interrupted while 
sleeping for throttling control");<a name="line.148"></a>
-<span class="sourceLineNo">149</span>          
Thread.currentThread().interrupt();<a name="line.149"></a>
-<span class="sourceLineNo">150</span>          // current thread might be 
interrupted to terminate<a name="line.150"></a>
-<span class="sourceLineNo">151</span>          // directly go back to while() 
for confirm this<a name="line.151"></a>
-<span class="sourceLineNo">152</span>          continue;<a name="line.152"></a>
-<span class="sourceLineNo">153</span>        }<a name="line.153"></a>
-<span class="sourceLineNo">154</span><a name="line.154"></a>
-<span class="sourceLineNo">155</span>        // create replicateContext here, 
so the entries can be GC'd upon return from this call<a name="line.155"></a>
-<span class="sourceLineNo">156</span>        // stack<a name="line.156"></a>
-<span class="sourceLineNo">157</span>        
ReplicationEndpoint.ReplicateContext replicateContext =<a name="line.157"></a>
-<span class="sourceLineNo">158</span>            new 
ReplicationEndpoint.ReplicateContext();<a name="line.158"></a>
-<span class="sourceLineNo">159</span>        
replicateContext.setEntries(entries).setSize(currentSize);<a 
name="line.159"></a>
-<span class="sourceLineNo">160</span>        
replicateContext.setWalGroupId(walGroupId);<a name="line.160"></a>
-<span class="sourceLineNo">161</span><a name="line.161"></a>
-<span class="sourceLineNo">162</span>        long startTimeNs = 
System.nanoTime();<a name="line.162"></a>
-<span class="sourceLineNo">163</span>        // send the edits to the 
endpoint. Will block until the edits are shipped and acknowledged<a 
name="line.163"></a>
-<span class="sourceLineNo">164</span>        boolean replicated = 
source.getReplicationEndpoint().replicate(replicateContext);<a 
name="line.164"></a>
-<span class="sourceLineNo">165</span>        long endTimeNs = 
System.nanoTime();<a name="line.165"></a>
-<span class="sourceLineNo">166</span><a name="line.166"></a>
-<span class="sourceLineNo">167</span>        if (!replicated) {<a 
name="line.167"></a>
-<span class="sourceLineNo">168</span>          continue;<a name="line.168"></a>
-<span class="sourceLineNo">169</span>        } else {<a name="line.169"></a>
-<span class="sourceLineNo">170</span>          sleepMultiplier = 
Math.max(sleepMultiplier - 1, 0);<a name="line.170"></a>
-<span class="sourceLineNo">171</span>        }<a name="line.171"></a>
-<span class="sourceLineNo">172</span>        // Clean up hfile references<a 
name="line.172"></a>
-<span class="sourceLineNo">173</span>        for (Entry entry : entries) {<a 
name="line.173"></a>
-<span class="sourceLineNo">174</span>          
cleanUpHFileRefs(entry.getEdit());<a name="line.174"></a>
-<span class="sourceLineNo">175</span>        }<a name="line.175"></a>
-<span class="sourceLineNo">176</span>        // Log and clean up WAL logs<a 
name="line.176"></a>
-<span class="sourceLineNo">177</span>        updateLogPosition(entryBatch);<a 
name="line.177"></a>
-<span class="sourceLineNo">178</span><a name="line.178"></a>
-<span class="sourceLineNo">179</span>        source.postShipEdits(entries, 
currentSize);<a name="line.179"></a>
-<span class="sourceLineNo">180</span>        // FIXME check relationship 
between wal group and overall<a name="line.180"></a>
-<span class="sourceLineNo">181</span>        
source.getSourceMetrics().shipBatch(entryBatch.getNbOperations(), 
currentSize,<a name="line.181"></a>
-<span class="sourceLineNo">182</span>          entryBatch.getNbHFiles());<a 
name="line.182"></a>
-<span class="sourceLineNo">183</span>        
source.getSourceMetrics().setAgeOfLastShippedOp(<a name="line.183"></a>
-<span class="sourceLineNo">184</span>          entries.get(entries.size() - 
1).getKey().getWriteTime(), walGroupId);<a name="line.184"></a>
-<span class="sourceLineNo">185</span>        if (LOG.isTraceEnabled()) {<a 
name="line.185"></a>
-<span class="sourceLineNo">186</span>          LOG.trace("Replicated " + 
entries.size() + " entries or " + entryBatch.getNbOperations()<a 
name="line.186"></a>
-<span class="sourceLineNo">187</span>              + " operations in " + 
((endTimeNs - startTimeNs) / 1000000) + " ms");<a name="line.187"></a>
-<span class="sourceLineNo">188</span>        }<a name="line.188"></a>
-<span class="sourceLineNo">189</span>        break;<a name="line.189"></a>
-<span class="sourceLineNo">190</span>      } catch (Exception ex) {<a 
name="line.190"></a>
-<span class="sourceLineNo">191</span>        
LOG.warn(source.getReplicationEndpoint().getClass().getName() + " threw unknown 
exception:"<a name="line.191"></a>
-<span class="sourceLineNo">192</span>            + 
org.apache.hadoop.util.StringUtils.stringifyException(ex));<a 
name="line.192"></a>
-<span class="sourceLineNo">193</span>        if 
(sleepForRetries("ReplicationEndpoint threw exception", sleepMultiplier)) {<a 
name="line.193"></a>
-<span class="sourceLineNo">194</span>          sleepMultiplier++;<a 
name="line.194"></a>
-<span class="sourceLineNo">195</span>        }<a name="line.195"></a>
-<span class="sourceLineNo">196</span>      }<a name="line.196"></a>
-<span class="sourceLineNo">197</span>    }<a name="line.197"></a>
-<span class="sourceLineNo">198</span>  }<a name="line.198"></a>
-<span class="sourceLineNo">199</span><a name="line.199"></a>
-<span class="sourceLineNo">200</span>  private void cleanUpHFileRefs(WALEdit 
edit) throws IOException {<a name="line.200"></a>
-<span class="sourceLineNo">201</span>    String peerId = source.getPeerId();<a 
name="line.201"></a>
-<span class="sourceLineNo">202</span>    if (peerId.contains("-")) {<a 
name="line.202"></a>
-<span class="sourceLineNo">203</span>      // peerClusterZnode will be in the 
form peerId + "-" + rsZNode.<a name="line.203"></a>
-<span class="sourceLineNo">204</span>      // A peerId will not have "-" in 
its name, see HBASE-11394<a name="line.204"></a>
-<span class="sourceLineNo">205</span>      peerId = peerId.split("-")[0];<a 
name="line.205"></a>
-<span class="sourceLineNo">206</span>    }<a name="line.206"></a>
-<span class="sourceLineNo">207</span>    List&lt;Cell&gt; cells = 
edit.getCells();<a name="line.207"></a>
-<span class="sourceLineNo">208</span>    int totalCells = cells.size();<a 
name="line.208"></a>
-<span class="sourceLineNo">209</span>    for (int i = 0; i &lt; totalCells; 
i++) {<a name="line.209"></a>
-<span class="sourceLineNo">210</span>      Cell cell = cells.get(i);<a 
name="line.210"></a>
-<span class="sourceLineNo">211</span>      if 
(CellUtil.matchingQualifier(cell, WALEdit.BULK_LOAD)) {<a name="line.211"></a>
-<span class="sourceLineNo">212</span>        BulkLoadDescriptor bld = 
WALEdit.getBulkLoadDescriptor(cell);<a name="line.212"></a>
-<span class="sourceLineNo">213</span>        List&lt;StoreDescriptor&gt; 
stores = bld.getStoresList();<a name="line.213"></a>
-<span class="sourceLineNo">214</span>        int totalStores = 
stores.size();<a name="line.214"></a>
-<span class="sourceLineNo">215</span>        for (int j = 0; j &lt; 
totalStores; j++) {<a name="line.215"></a>
-<span class="sourceLineNo">216</span>          List&lt;String&gt; 
storeFileList = stores.get(j).getStoreFileList();<a name="line.216"></a>
-<span class="sourceLineNo">217</span>          
source.getSourceManager().cleanUpHFileRefs(peerId, storeFileList);<a 
name="line.217"></a>
-<span class="sourceLineNo">218</span>          
source.getSourceMetrics().decrSizeOfHFileRefsQueue(storeFileList.size());<a 
name="line.218"></a>
-<span class="sourceLineNo">219</span>        }<a name="line.219"></a>
-<span class="sourceLineNo">220</span>      }<a name="line.220"></a>
-<span class="sourceLineNo">221</span>    }<a name="line.221"></a>
-<span class="sourceLineNo">222</span>  }<a name="line.222"></a>
-<span class="sourceLineNo">223</span><a name="line.223"></a>
-<span class="sourceLineNo">224</span>  private boolean 
updateLogPosition(WALEntryBatch batch) {<a name="line.224"></a>
-<span class="sourceLineNo">225</span>    boolean updated = false;<a 
name="line.225"></a>
-<span class="sourceLineNo">226</span>    // if end of file is true, then the 
logPositionAndCleanOldLogs method will remove the file<a name="line.226"></a>
-<span class="sourceLineNo">227</span>    // record on zk, so let's call it. 
The last wal position maybe zero if end of file is true and<a 
name="line.227"></a>
-<span class="sourceLineNo">228</span>    // there is no entry in the batch. It 
is OK because that the queue storage will ignore the zero<a name="line.228"></a>
-<span class="sourceLineNo">229</span>    // position and the file will be 
removed soon in cleanOldLogs.<a name="line.229"></a>
-<span class="sourceLineNo">230</span>    if (batch.isEndOfFile() || 
!batch.getLastWalPath().equals(currentPath) ||<a name="line.230"></a>
-<span class="sourceLineNo">231</span>      batch.getLastWalPosition() != 
currentPosition) {<a name="line.231"></a>
-<span class="sourceLineNo">232</span>      
source.getSourceManager().logPositionAndCleanOldLogs(source.getQueueId(),<a 
name="line.232"></a>
-<span class="sourceLineNo">233</span>        source.isRecovered(), batch);<a 
name="line.233"></a>
-<span class="sourceLineNo">234</span>      updated = true;<a 
name="line.234"></a>
-<span class="sourceLineNo">235</span>    }<a name="line.235"></a>
-<span class="sourceLineNo">236</span>    // if end of file is true, then we 
can just skip to the next file in queue.<a name="line.236"></a>
-<span class="sourceLineNo">237</span>    // the only exception is for 
recovered queue, if we reach the end of the queue, then there will<a 
name="line.237"></a>
-<span class="sourceLineNo">238</span>    // no more files so here the 
currentPath may be null.<a name="line.238"></a>
-<span class="sourceLineNo">239</span>    if (batch.isEndOfFile()) {<a 
name="line.239"></a>
-<span class="sourceLineNo">240</span>      currentPath = 
entryReader.getCurrentPath();<a name="line.240"></a>
-<span class="sourceLineNo">241</span>      currentPosition = 0L;<a 
name="line.241"></a>
-<span class="sourceLineNo">242</span>    } else {<a name="line.242"></a>
-<span class="sourceLineNo">243</span>      currentPath = 
batch.getLastWalPath();<a name="line.243"></a>
-<span class="sourceLineNo">244</span>      currentPosition = 
batch.getLastWalPosition();<a name="line.244"></a>
-<span class="sourceLineNo">245</span>    }<a name="line.245"></a>
-<span class="sourceLineNo">246</span>    return updated;<a name="line.246"></a>
-<span class="sourceLineNo">247</span>  }<a name="line.247"></a>
-<span class="sourceLineNo">248</span><a name="line.248"></a>
-<span class="sourceLineNo">249</span>  public void 
startup(UncaughtExceptionHandler handler) {<a name="line.249"></a>
-<span class="sourceLineNo">250</span>    String name = 
Thread.currentThread().getName();<a name="line.250"></a>
-<span class="sourceLineNo">251</span>    
Threads.setDaemonThreadRunning(this,<a name="line.251"></a>
-<span class="sourceLineNo">252</span>      name + ".replicationSource.shipper" 
+ walGroupId + "," + source.getQueueId(), handler);<a name="line.252"></a>
-<span class="sourceLineNo">253</span>  }<a name="line.253"></a>
-<span class="sourceLineNo">254</span><a name="line.254"></a>
-<span class="sourceLineNo">255</span>  Path getCurrentPath() {<a 
name="line.255"></a>
-<span class="sourceLineNo">256</span>    return 
entryReader.getCurrentPath();<a name="line.256"></a>
-<span class="sourceLineNo">257</span>  }<a name="line.257"></a>
-<span class="sourceLineNo">258</span><a name="line.258"></a>
-<span class="sourceLineNo">259</span>  long getCurrentPosition() {<a 
name="line.259"></a>
-<span class="sourceLineNo">260</span>    return currentPosition;<a 
name="line.260"></a>
-<span class="sourceLineNo">261</span>  }<a name="line.261"></a>
-<span class="sourceLineNo">262</span><a name="line.262"></a>
-<span class="sourceLineNo">263</span>  void 
setWALReader(ReplicationSourceWALReader entryReader) {<a name="line.263"></a>
-<span class="sourceLineNo">264</span>    this.entryReader = entryReader;<a 
name="line.264"></a>
-<span class="sourceLineNo">265</span>  }<a name="line.265"></a>
-<span class="sourceLineNo">266</span><a name="line.266"></a>
-<span class="sourceLineNo">267</span>  long getStartPosition() {<a 
name="line.267"></a>
-<span class="sourceLineNo">268</span>    return 0;<a name="line.268"></a>
-<span class="sourceLineNo">269</span>  }<a name="line.269"></a>
-<span class="sourceLineNo">270</span><a name="line.270"></a>
-<span class="sourceLineNo">271</span>  private boolean isActive() {<a 
name="line.271"></a>
-<span class="sourceLineNo">272</span>    return source.isSourceActive() 
&amp;&amp; state == WorkerState.RUNNING &amp;&amp; !isInterrupted();<a 
name="line.272"></a>
-<span class="sourceLineNo">273</span>  }<a name="line.273"></a>
-<span class="sourceLineNo">274</span><a name="line.274"></a>
-<span class="sourceLineNo">275</span>  protected final void 
setWorkerState(WorkerState state) {<a name="line.275"></a>
-<span class="sourceLineNo">276</span>    this.state = state;<a 
name="line.276"></a>
-<span class="sourceLineNo">277</span>  }<a name="line.277"></a>
-<span class="sourceLineNo">278</span><a name="line.278"></a>
-<span class="sourceLineNo">279</span>  void stopWorker() {<a 
name="line.279"></a>
-<span class="sourceLineNo">280</span>    
setWorkerState(WorkerState.STOPPED);<a name="line.280"></a>
-<span class="sourceLineNo">281</span>  }<a name="line.281"></a>
-<span class="sourceLineNo">282</span><a name="line.282"></a>
-<span class="sourceLineNo">283</span>  public boolean isFinished() {<a 
name="line.283"></a>
-<span class="sourceLineNo">284</span>    return state == 
WorkerState.FINISHED;<a name="line.284"></a>
-<span class="sourceLineNo">285</span>  }<a name="line.285"></a>
-<span class="sourceLineNo">286</span><a name="line.286"></a>
-<span class="sourceLineNo">287</span>  /**<a name="line.287"></a>
-<span class="sourceLineNo">288</span>   * Do the sleeping logic<a 
name="line.288"></a>
-<span class="sourceLineNo">289</span>   * @param msg Why we sleep<a 
name="line.289"></a>
-<span class="sourceLineNo">290</span>   * @param sleepMultiplier by how many 
times the default sleeping time is augmented<a name="line.290"></a>
-<span class="sourceLineNo">291</span>   * @return True if 
&lt;code&gt;sleepMultiplier&lt;/code&gt; is &amp;lt; 
&lt;code&gt;maxRetriesMultiplier&lt;/code&gt;<a name="line.291"></a>
-<span class="sourceLineNo">292</span>   */<a name="line.292"></a>
-<span class="sourceLineNo">293</span>  public boolean sleepForRetries(String 
msg, int sleepMultiplier) {<a name="line.293"></a>
-<span class="sourceLineNo">294</span>    try {<a name="line.294"></a>
-<span class="sourceLineNo">295</span>      if (LOG.isTraceEnabled()) {<a 
name="line.295"></a>
-<span class="sourceLineNo">296</span>        LOG.trace(msg + ", sleeping " + 
sleepForRetries + " times " + sleepMultiplier);<a name="line.296"></a>
-<span class="sourceLineNo">297</span>      }<a name="line.297"></a>
-<span class="sourceLineNo">298</span>      Thread.sleep(this.sleepForRetries * 
sleepMultiplier);<a name="line.298"></a>
-<span class="sourceLineNo">299</span>    } catch (InterruptedException e) {<a 
name="line.299"></a>
-<span class="sourceLineNo">300</span>      LOG.debug("Interrupted while 
sleeping between retries");<a name="line.300"></a>
-<span class="sourceLineNo">301</span>      
Thread.currentThread().interrupt();<a name="line.301"></a>
-<span class="sourceLineNo">302</span>    }<a name="line.302"></a>
-<span class="sourceLineNo">303</span>    return sleepMultiplier &lt; 
maxRetriesMultiplier;<a name="line.303"></a>
-<span class="sourceLineNo">304</span>  }<a name="line.304"></a>
-<span class="sourceLineNo">305</span>}<a name="line.305"></a>
+<span class="sourceLineNo">090</span>      // Sleep until replication is 
enabled again<a name="line.90"></a>
+<span class="sourceLineNo">091</span>      if (!source.isPeerEnabled()) {<a 
name="line.91"></a>
+<span class="sourceLineNo">092</span>        // The peer enabled check is in 
memory, not expensive, so do not need to increase the<a name="line.92"></a>
+<span class="sourceLineNo">093</span>        // sleep interval as it may cause 
a long lag when we enable the peer.<a name="line.93"></a>
+<span class="sourceLineNo">094</span>        sleepForRetries("Replication is 
disabled", 1);<a name="line.94"></a>
+<span class="sourceLineNo">095</span>        continue;<a name="line.95"></a>
+<span class="sourceLineNo">096</span>      }<a name="line.96"></a>
+<span class="sourceLineNo">097</span>      try {<a name="line.97"></a>
+<span class="sourceLineNo">098</span>        WALEntryBatch entryBatch = 
entryReader.take();<a name="line.98"></a>
+<span class="sourceLineNo">099</span>        // the NO_MORE_DATA instance has 
no path so do not all shipEdits<a name="line.99"></a>
+<span class="sourceLineNo">100</span>        if (entryBatch == 
WALEntryBatch.NO_MORE_DATA) {<a name="line.100"></a>
+<span class="sourceLineNo">101</span>          noMoreData();<a 
name="line.101"></a>
+<span class="sourceLineNo">102</span>        } else {<a name="line.102"></a>
+<span class="sourceLineNo">103</span>          shipEdits(entryBatch);<a 
name="line.103"></a>
+<span class="sourceLineNo">104</span>        }<a name="line.104"></a>
+<span class="sourceLineNo">105</span>      } catch (InterruptedException e) 
{<a name="line.105"></a>
+<span class="sourceLineNo">106</span>        LOG.trace("Interrupted while 
waiting for next replication entry batch", e);<a name="line.106"></a>
+<span class="sourceLineNo">107</span>        
Thread.currentThread().interrupt();<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>    // If the worker exits run loop 
without finishing its task, mark it as stopped.<a name="line.110"></a>
+<span class="sourceLineNo">111</span>    if (!isFinished()) {<a 
name="line.111"></a>
+<span class="sourceLineNo">112</span>      
setWorkerState(WorkerState.STOPPED);<a name="line.112"></a>
+<span class="sourceLineNo">113</span>    } else {<a name="line.113"></a>
+<span class="sourceLineNo">114</span>      postFinish();<a name="line.114"></a>
+<span class="sourceLineNo">115</span>    }<a name="line.115"></a>
+<span class="sourceLineNo">116</span>  }<a name="line.116"></a>
+<span class="sourceLineNo">117</span><a name="line.117"></a>
+<span class="sourceLineNo">118</span>  // To be implemented by recovered 
shipper<a name="line.118"></a>
+<span class="sourceLineNo">119</span>  protected void noMoreData() {<a 
name="line.119"></a>
+<span class="sourceLineNo">120</span>  }<a name="line.120"></a>
+<span class="sourceLineNo">121</span><a name="line.121"></a>
+<span class="sourceLineNo">122</span>  // To be implemented by recovered 
shipper<a name="line.122"></a>
+<span class="sourceLineNo">123</span>  protected void postFinish() {<a 
name="line.123"></a>
+<span class="sourceLineNo">124</span>  }<a name="line.124"></a>
+<span class="sourceLineNo">125</span><a name="line.125"></a>
+<span class="sourceLineNo">126</span>  /**<a name="line.126"></a>
+<span class="sourceLineNo">127</span>   * Do the shipping logic<a 
name="line.127"></a>
+<span class="sourceLineNo">128</span>   */<a name="line.128"></a>
+<span class="sourceLineNo">129</span>  private void shipEdits(WALEntryBatch 
entryBatch) {<a name="line.129"></a>
+<span class="sourceLineNo">130</span>    List&lt;Entry&gt; entries = 
entryBatch.getWalEntries();<a name="line.130"></a>
+<span class="sourceLineNo">131</span>    int sleepMultiplier = 0;<a 
name="line.131"></a>
+<span class="sourceLineNo">132</span>    if (entries.isEmpty()) {<a 
name="line.132"></a>
+<span class="sourceLineNo">133</span>      if (updateLogPosition(entryBatch)) 
{<a name="line.133"></a>
+<span class="sourceLineNo">134</span>        // if there was nothing to ship 
and it's not an error<a name="line.134"></a>
+<span class="sourceLineNo">135</span>        // set "ageOfLastShippedOp" to 
&lt;now&gt; to indicate that we're current<a name="line.135"></a>
+<span class="sourceLineNo">136</span>        
source.getSourceMetrics().setAgeOfLastShippedOp(EnvironmentEdgeManager.currentTime(),<a
 name="line.136"></a>
+<span class="sourceLineNo">137</span>          walGroupId);<a 
name="line.137"></a>
+<span class="sourceLineNo">138</span>      }<a name="line.138"></a>
+<span class="sourceLineNo">139</span>      return;<a name="line.139"></a>
+<span class="sourceLineNo">140</span>    }<a name="line.140"></a>
+<span class="sourceLineNo">141</span>    int currentSize = (int) 
entryBatch.getHeapSize();<a name="line.141"></a>
+<span class="sourceLineNo">142</span>    while (isActive()) {<a 
name="line.142"></a>
+<span class="sourceLineNo">143</span>      try {<a name="line.143"></a>
+<span class="sourceLineNo">144</span>        try {<a name="line.144"></a>
+<span class="sourceLineNo">145</span>          
source.tryThrottle(currentSize);<a name="line.145"></a>
+<span class="sourceLineNo">146</span>        } catch (InterruptedException e) 
{<a name="line.146"></a>
+<span class="sourceLineNo">147</span>          LOG.debug("Interrupted while 
sleeping for throttling control");<a name="line.147"></a>
+<span class="sourceLineNo">148</span>          
Thread.currentThread().interrupt();<a name="line.148"></a>
+<span class="sourceLineNo">149</span>          // current thread might be 
interrupted to terminate<a name="line.149"></a>
+<span class="sourceLineNo">150</span>          // directly go back to while() 
for confirm this<a name="line.150"></a>
+<span class="sourceLineNo">151</span>          continue;<a name="line.151"></a>
+<span class="sourceLineNo">152</span>        }<a name="line.152"></a>
+<span class="sourceLineNo">153</span><a name="line.153"></a>
+<span class="sourceLineNo">154</span>        // create replicateContext here, 
so the entries can be GC'd upon return from this call<a name="line.154"></a>
+<span class="sourceLineNo">155</span>        // stack<a name="line.155"></a>
+<span class="sourceLineNo">156</span>        
ReplicationEndpoint.ReplicateContext replicateContext =<a name="line.156"></a>
+<span class="sourceLineNo">157</span>            new 
ReplicationEndpoint.ReplicateContext();<a name="line.157"></a>
+<span class="sourceLineNo">158</span>        
replicateContext.setEntries(entries).setSize(currentSize);<a 
name="line.158"></a>
+<span class="sourceLineNo">159</span>        
replicateContext.setWalGroupId(walGroupId);<a name="line.159"></a>
+<span class="sourceLineNo">160</span><a name="line.160"></a>
+<span class="sourceLineNo">161</span>        long startTimeNs = 
System.nanoTime();<a name="line.161"></a>
+<span class="sourceLineNo">162</span>        // send the edits to the 
endpoint. Will block until the edits are shipped and acknowledged<a 
name="line.162"></a>
+<span class="sourceLineNo">163</span>        boolean replicated = 
source.getReplicationEndpoint().replicate(replicateContext);<a 
name="line.163"></a>
+<span class="sourceLineNo">164</span>        long endTimeNs = 
System.nanoTime();<a name="line.164"></a>
+<span class="sourceLineNo">165</span><a name="line.165"></a>
+<span class="sourceLineNo">166</span>        if (!replicated) {<a 
name="line.166"></a>
+<span class="sourceLineNo">167</span>          continue;<a name="line.167"></a>
+<span class="sourceLineNo">168</span>        } else {<a name="line.168"></a>
+<span class="sourceLineNo">169</span>          sleepMultiplier = 
Math.max(sleepMultiplier - 1, 0);<a name="line.169"></a>
+<span class="sourceLineNo">170</span>        }<a name="line.170"></a>
+<span class="sourceLineNo">171</span>        // Clean up hfile references<a 
name="line.171"></a>
+<span class="sourceLineNo">172</span>        for (Entry entry : entries) {<a 
name="line.172"></a>
+<span class="sourceLineNo">173</span>          
cleanUpHFileRefs(entry.getEdit());<a name="line.173"></a>
+<span class="sourceLineNo">174</span>        }<a name="line.174"></a>
+<span class="sourceLineNo">175</span>        // Log and clean up WAL logs<a 
name="line.175"></a>
+<span class="sourceLineNo">176</span>        updateLogPosition(entryBatch);<a 
name="line.176"></a>
+<span class="sourceLineNo">177</span><a name="line.177"></a>
+<span class="sourceLineNo">178</span>        source.postShipEdits(entries, 
currentSize);<a name="line.178"></a>
+<span class="sourceLineNo">179</span>        // FIXME check relationship 
between wal group and overall<a name="line.179"></a>
+<span class="sourceLineNo">180</span>        
source.getSourceMetrics().shipBatch(entryBatch.getNbOperations(), 
currentSize,<a name="line.180"></a>
+<span class="sourceLineNo">181</span>          entryBatch.getNbHFiles());<a 
name="line.181"></a>
+<span class="sourceLineNo">182</span>        
source.getSourceMetrics().setAgeOfLastShippedOp(<a name="line.182"></a>
+<span class="sourceLineNo">183</span>          entries.get(entries.size() - 
1).getKey().getWriteTime(), walGroupId);<a name="line.183"></a>
+<span class="sourceLineNo">184</span>        if (LOG.isTraceEnabled()) {<a 
name="line.184"></a>
+<span class="sourceLineNo">185</span>          LOG.trace("Replicated " + 
entries.size() + " entries or " + entryBatch.getNbOperations()<a 
name="line.185"></a>
+<span class="sourceLineNo">186</span>              + " operations in " + 
((endTimeNs - startTimeNs) / 1000000) + " ms");<a name="line.186"></a>
+<span class="sourceLineNo">187</span>        }<a name="line.187"></a>
+<span class="sourceLineNo">188</span>        break;<a name="line.188"></a>
+<span class="sourceLineNo">189</span>      } catch (Exception ex) {<a 
name="line.189"></a>
+<span class="sourceLineNo">190</span>        LOG.warn("{} threw unknown 
exception:",<a name="line.190"></a>
+<span class="sourceLineNo">191</span>          
source.getReplicationEndpoint().getClass().getName(), ex);<a 
name="line.191"></a>
+<span class="sourceLineNo">192</span>        if 
(sleepForRetries("ReplicationEndpoint threw exception", sleepMultiplier)) {<a 
name="line.192"></a>
+<span class="sourceLineNo">193</span>          sleepMultiplier++;<a 
name="line.193"></a>
+<span class="sourceLineNo">194</span>        }<a name="line.194"></a>
+<span class="sourceLineNo">195</span>      }<a name="line.195"></a>
+<span class="sourceLineNo">196</span>    }<a name="line.196"></a>
+<span class="sourceLineNo">197</span>  }<a name="line.197"></a>
+<span class="sourceLineNo">198</span><a name="line.198"></a>
+<span class="sourceLineNo">199</span>  private void cleanUpHFileRefs(WALEdit 
edit) throws IOException {<a name="line.199"></a>
+<span class="sourceLineNo">200</span>    String peerId = source.getPeerId();<a 
name="line.200"></a>
+<span class="sourceLineNo">201</span>    if (peerId.contains("-")) {<a 
name="line.201"></a>
+<span class="sourceLineNo">202</span>      // peerClusterZnode will be in the 
form peerId + "-" + rsZNode.<a name="line.202"></a>
+<span class="sourceLineNo">203</span>      // A peerId will not have "-" in 
its name, see HBASE-11394<a name="line.203"></a>
+<span class="sourceLineNo">204</span>      peerId = peerId.split("-")[0];<a 
name="line.204"></a>
+<span class="sourceLineNo">205</span>    }<a name="line.205"></a>
+<span class="sourceLineNo">206</span>    List&lt;Cell&gt; cells = 
edit.getCells();<a name="line.206"></a>
+<span class="sourceLineNo">207</span>    int totalCells = cells.size();<a 
name="line.207"></a>
+<span class="sourceLineNo">208</span>    for (int i = 0; i &lt; totalCells; 
i++) {<a name="line.208"></a>
+<span class="sourceLineNo">209</span>      Cell cell = cells.get(i);<a 
name="line.209"></a>
+<span class="sourceLineNo">210</span>      if 
(CellUtil.matchingQualifier(cell, WALEdit.BULK_LOAD)) {<a name="line.210"></a>
+<span class="sourceLineNo">211</span>        BulkLoadDescriptor bld = 
WALEdit.getBulkLoadDescriptor(cell);<a name="line.211"></a>
+<span class="sourceLineNo">212</span>        List&lt;StoreDescriptor&gt; 
stores = bld.getStoresList();<a name="line.212"></a>
+<span class="sourceLineNo">213</span>        int totalStores = 
stores.size();<a name="line.213"></a>
+<span class="sourceLineNo">214</span>        for (int j = 0; j &lt; 
totalStores; j++) {<a name="line.214"></a>
+<span class="sourceLineNo">215</span>          List&lt;String&gt; 
storeFileList = stores.get(j).getStoreFileList();<a name="line.215"></a>
+<span class="sourceLineNo">216</span>          
source.getSourceManager().cleanUpHFileRefs(peerId, storeFileList);<a 
name="line.216"></a>
+<span class="sourceLineNo">217</span>          
source.getSourceMetrics().decrSizeOfHFileRefsQueue(storeFileList.size());<a 
name="line.217"></a>
+<span class="sourceLineNo">218</span>        }<a name="line.218"></a>
+<span class="sourceLineNo">219</span>      }<a name="line.219"></a>
+<span class="sourceLineNo">220</span>    }<a name="line.220"></a>
+<span class="sourceLineNo">221</span>  }<a name="line.221"></a>
+<span class="sourceLineNo">222</span><a name="line.222"></a>
+<span class="sourceLineNo">223</span>  private boolean 
updateLogPosition(WALEntryBatch batch) {<a name="line.223"></a>
+<span class="sourceLineNo">224</span>    boolean updated = false;<a 
name="line.224"></a>
+<span class="sourceLineNo">225</span>    // if end of file is true, then the 
logPositionAndCleanOldLogs method will remove the file<a name="line.225"></a>
+<span class="sourceLineNo">226</span>    // record on zk, so let's call it. 
The last wal position maybe zero if end of file is true and<a 
name="line.226"></a>
+<span class="sourceLineNo">227</span>    // there is no entry in the batch. It 
is OK because that the queue storage will ignore the zero<a name="line.227"></a>
+<span class="sourceLineNo">228</span>    // position and the file will be 
removed soon in cleanOldLogs.<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    if (batch.isEndOfFile() || 
!batch.getLastWalPath().equals(currentPath) ||<a name="line.229"></a>
+<span class="sourceLineNo">230</span>      batch.getLastWalPosition() != 
currentPosition) {<a name="line.230"></a>
+<span class="sourceLineNo">231</span>      
source.getSourceManager().logPositionAndCleanOldLogs(source.getQueueId(),<a 
name="line.231"></a>
+<span class="sourceLineNo">232</span>        source.isRecovered(), batch);<a 
name="line.232"></a>
+<span class="sourceLineNo">233</span>      updated = true;<a 
name="line.233"></a>
+<span class="sourceLineNo">234</span>    }<a name="line.234"></a>
+<span class="sourceLineNo">235</span>    // if end of file is true, then we 
can just skip to the next file in queue.<a name="line.235"></a>
+<span class="sourceLineNo">236</span>    // the only exception is for 
recovered queue, if we reach the end of the queue, then there will<a 
name="line.236"></a>
+<span class="sourceLineNo">237</span>    // no more files so here the 
currentPath may be null.<a name="line.237"></a>
+<span class="sourceLineNo">238</span>    if (batch.isEndOfFile()) {<a 
name="line.238"></a>
+<span class="sourceLineNo">239</span>      currentPath = 
entryReader.getCurrentPath();<a name="line.239"></a>
+<span class="sourceLineNo">240</span>      currentPosition = 0L;<a 
name="line.240"></a>
+<span class="sourceLineNo">241</span>    } else {<a name="line.241"></a>
+<span class="sourceLineNo">242</span>      currentPath = 
batch.getLastWalPath();<a name="line.242"></a>
+<span class="sourceLineNo">243</span>      currentPosition = 
batch.getLastWalPosition();<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    }<a name="line.244"></a>
+<span class="sourceLineNo">245</span>    return updated;<a name="line.245"></a>
+<span class="sourceLineNo">246</span>  }<a name="line.246"></a>
+<span class="sourceLineNo">247</span><a name="line.247"></a>
+<span class="sourceLineNo">248</span>  public void 
startup(UncaughtExceptionHandler handler) {<a name="line.248"></a>
+<span class="sourceLineNo">249</span>    String name = 
Thread.currentThread().getName();<a name="line.249"></a>
+<span class="sourceLineNo">250</span>    
Threads.setDaemonThreadRunning(this,<a name="line.250"></a>
+<span class="sourceLineNo">251</span>      name + ".replicationSource.shipper" 
+ walGroupId + "," + source.getQueueId(), handler);<a name="line.251"></a>
+<span class="sourceLineNo">252</span>  }<a name="line.252"></a>
+<span class="sourceLineNo">253</span><a name="line.253"></a>
+<span class="sourceLineNo">254</span>  Path getCurrentPath() {<a 
name="line.254"></a>
+<span class="sourceLineNo">255</span>    return 
entryReader.getCurrentPath();<a name="line.255"></a>
+<span class="sourceLineNo">256</span>  }<a name="line.256"></a>
+<span class="sourceLineNo">257</span><a name="line.257"></a>
+<span class="sourceLineNo">258</span>  long getCurrentPosition() {<a 
name="line.258"></a>
+<span class="sourceLineNo">259</span>    return currentPosition;<a 
name="line.259"></a>
+<span class="sourceLineNo">260</span>  }<a name="line.260"></a>
+<span class="sourceLineNo">261</span><a name="line.261"></a>
+<span class="sourceLineNo">262</span>  void 
setWALReader(ReplicationSourceWALReader entryReader) {<a name="line.262"></a>
+<span class="sourceLineNo">263</span>    this.entryReader = entryReader;<a 
name="line.263"></a>
+<span class="sourceLineNo">264</span>  }<a name="line.264"></a>
+<span class="sourceLineNo">265</span><a name="line.265"></a>
+<span class="sourceLineNo">266</span>  long getStartPosition() {<a 
name="line.266"></a>
+<span class="sourceLineNo">267</span>    return 0;<a name="line.267"></a>
+<span class="sourceLineNo">268</span>  }<a name="line.268"></a>
+<span class="sourceLineNo">269</span><a name="line.269"></a>
+<span class="sourceLineNo">270</span>  private boolean isActive() {<a 
name="line.270"></a>
+<span class="sourceLineNo">271</span>    return source.isSourceActive() 
&amp;&amp; state == WorkerState.RUNNING &amp;&amp; !isInterrupted();<a 
name="line.271"></a>
+<span class="sourceLineNo">272</span>  }<a name="line.272"></a>
+<span class="sourceLineNo">273</span><a name="line.273"></a>
+<span class="sourceLineNo">274</span>  protected final void 
setWorkerState(WorkerState state) {<a name="line.274"></a>
+<span class="sourceLineNo">275</span>    this.state = state;<a 
name="line.275"></a>
+<span class="sourceLineNo">276</span>  }<a name="line.276"></a>
+<span class="sourceLineNo">277</span><a name="line.277"></a>
+<span class="sourceLineNo">278</span>  void stopWorker() {<a 
name="line.278"></a>
+<span class="sourceLineNo">279</span>    
setWorkerState(WorkerState.STOPPED);<a name="line.279"></a>
+<span class="sourceLineNo">280</span>  }<a name="line.280"></a>
+<span class="sourceLineNo">281</span><a name="line.281"></a>
+<span class="sourceLineNo">282</span>  public boolean isFinished() {<a 
name="line.282"></a>
+<span class="sourceLineNo">283</span>    return state == 
WorkerState.FINISHED;<a name="line.283"></a>
+<span class="sourceLineNo">284</span>  }<a name="line.284"></a>
+<span class="sourceLineNo">285</span><a name="line.285"></a>
+<span class="sourceLineNo">286</span>  /**<a name="line.286"></a>
+<span class="sourceLineNo">287</span>   * Do the sleeping logic<a 
name="line.287"></a>
+<span class="sourceLineNo">288</span>   * @param msg Why we sleep<a 
name="line.288"></a>
+<span class="sourceLineNo">289</span>   * @param sleepMultiplier by how many 
times the default sleeping time is augmented<a name="line.289"></a>
+<span class="sourceLineNo">290</span>   * @return True if 
&lt;code&gt;sleepMultiplier&lt;/code&gt; is &amp;lt; 
&lt;code&gt;maxRetriesMultiplier&lt;/code&gt;<a name="line.290"></a>
+<span class="sourceLineNo">291</span>   */<a name="line.291"></a>
+<span class="sourceLineNo">292</span>  public boolean sleepForRetries(String 
msg, int sleepMultiplier) {<a name="line.292"></a>
+<span class="sourceLineNo">293</span>    try {<a name="line.293"></a>
+<span class="sourceLineNo">294</span>      LOG.trace("{}, sleeping {} times 
{}", msg, sleepForRetries, sleepMultiplier);<a name="line.294"></a>
+<span class="sourceLineNo">295</span>      Thread.sleep(this.sleepForRetries * 
sleepMultiplier);<a name="line.295"></a>
+<span class="sourceLineNo">296</span>    } catch (InterruptedException e) {<a 
name="line.296"></a>
+<span class="sourceLineNo">297</span>      LOG.debug("Interrupted while 
sleeping between retries");<a name="line.297"></a>
+<span class="sourceLineNo">298</span>      
Thread.currentThread().interrupt();<a name="line.298"></a>
+<span class="sourceLineNo">299</span>    }<a name="line.299"></a>
+<span class="sourceLineNo">300</span>    return sleepMultiplier &lt; 
maxRetriesMultiplier;<a name="line.300"></a>
+<span class="sourceLineNo">301</span>  }<a name="line.301"></a>
+<span class="sourceLineNo">302</span>}<a name="line.302"></a>
 
 
 

Reply via email to