hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [03/45] hbase-site git commit: Published site at 04622254f7209c5cfeadcfa137a97fbed161075a.
Date Mon, 14 Dec 2015 16:38:14 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/736088b3/xref/org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html
----------------------------------------------------------------------
diff --git a/xref/org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html b/xref/org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html
index 16626cb..f033bbf 100644
--- a/xref/org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html
+++ b/xref/org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html
@@ -39,7 +39,7 @@
 <a class="jxr_linenumber" name="29" href="#29">29</a>  <strong class="jxr_keyword">import</strong> java.util.concurrent.ExecutionException;
 <a class="jxr_linenumber" name="30" href="#30">30</a>  <strong class="jxr_keyword">import</strong> java.util.concurrent.ExecutorCompletionService;
 <a class="jxr_linenumber" name="31" href="#31">31</a>  <strong class="jxr_keyword">import</strong> java.util.concurrent.Future;
-<a class="jxr_linenumber" name="32" href="#32">32</a>  <strong class="jxr_keyword">import</strong> java.util.concurrent.SynchronousQueue;
+<a class="jxr_linenumber" name="32" href="#32">32</a>  <strong class="jxr_keyword">import</strong> java.util.concurrent.LinkedBlockingQueue;
 <a class="jxr_linenumber" name="33" href="#33">33</a>  <strong class="jxr_keyword">import</strong> java.util.concurrent.ThreadPoolExecutor;
 <a class="jxr_linenumber" name="34" href="#34">34</a>  <strong class="jxr_keyword">import</strong> java.util.concurrent.TimeUnit;
 <a class="jxr_linenumber" name="35" href="#35">35</a>  
@@ -123,243 +123,244 @@
 <a class="jxr_linenumber" name="113" href="#113">113</a>     <em class="jxr_comment">// per sink thread pool</em>
 <a class="jxr_linenumber" name="114" href="#114">114</a>     <strong class="jxr_keyword">this</strong>.maxThreads = <strong class="jxr_keyword">this</strong>.conf.getInt(HConstants.REPLICATION_SOURCE_MAXTHREADS_KEY,
 <a class="jxr_linenumber" name="115" href="#115">115</a>       HConstants.REPLICATION_SOURCE_MAXTHREADS_DEFAULT);
-<a class="jxr_linenumber" name="116" href="#116">116</a>     <strong class="jxr_keyword">this</strong>.exec = <strong class="jxr_keyword">new</strong> ThreadPoolExecutor(1, maxThreads, 60, TimeUnit.SECONDS,
-<a class="jxr_linenumber" name="117" href="#117">117</a>         <strong class="jxr_keyword">new</strong> SynchronousQueue&lt;Runnable&gt;());
-<a class="jxr_linenumber" name="118" href="#118">118</a> 
-<a class="jxr_linenumber" name="119" href="#119">119</a>     <strong class="jxr_keyword">this</strong>.replicationBulkLoadDataEnabled =
-<a class="jxr_linenumber" name="120" href="#120">120</a>         conf.getBoolean(HConstants.REPLICATION_BULKLOAD_ENABLE_KEY,
-<a class="jxr_linenumber" name="121" href="#121">121</a>           HConstants.REPLICATION_BULKLOAD_ENABLE_DEFAULT);
-<a class="jxr_linenumber" name="122" href="#122">122</a>     <strong class="jxr_keyword">if</strong> (<strong class="jxr_keyword">this</strong>.replicationBulkLoadDataEnabled) {
-<a class="jxr_linenumber" name="123" href="#123">123</a>       replicationClusterId = <strong class="jxr_keyword">this</strong>.conf.get(HConstants.REPLICATION_CLUSTER_ID);
-<a class="jxr_linenumber" name="124" href="#124">124</a>     }
-<a class="jxr_linenumber" name="125" href="#125">125</a>     <em class="jxr_comment">// Construct base namespace directory and hfile archive directory path</em>
-<a class="jxr_linenumber" name="126" href="#126">126</a>     Path rootDir = FSUtils.getRootDir(conf);
-<a class="jxr_linenumber" name="127" href="#127">127</a>     Path baseNSDir = <strong class="jxr_keyword">new</strong> Path(HConstants.BASE_NAMESPACE_DIR);
-<a class="jxr_linenumber" name="128" href="#128">128</a>     baseNamespaceDir = <strong class="jxr_keyword">new</strong> Path(rootDir, baseNSDir);
-<a class="jxr_linenumber" name="129" href="#129">129</a>     hfileArchiveDir = <strong class="jxr_keyword">new</strong> Path(rootDir, <strong class="jxr_keyword">new</strong> Path(HConstants.HFILE_ARCHIVE_DIRECTORY, baseNSDir));
-<a class="jxr_linenumber" name="130" href="#130">130</a>   }
-<a class="jxr_linenumber" name="131" href="#131">131</a> 
-<a class="jxr_linenumber" name="132" href="#132">132</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> decorateConf() {
-<a class="jxr_linenumber" name="133" href="#133">133</a>     String replicationCodec = <strong class="jxr_keyword">this</strong>.conf.get(HConstants.REPLICATION_CODEC_CONF_KEY);
-<a class="jxr_linenumber" name="134" href="#134">134</a>     <strong class="jxr_keyword">if</strong> (StringUtils.isNotEmpty(replicationCodec)) {
-<a class="jxr_linenumber" name="135" href="#135">135</a>       <strong class="jxr_keyword">this</strong>.conf.set(HConstants.RPC_CODEC_CONF_KEY, replicationCodec);
-<a class="jxr_linenumber" name="136" href="#136">136</a>     }
-<a class="jxr_linenumber" name="137" href="#137">137</a>   }
-<a class="jxr_linenumber" name="138" href="#138">138</a> 
-<a class="jxr_linenumber" name="139" href="#139">139</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> connectToPeers() {
-<a class="jxr_linenumber" name="140" href="#140">140</a>     getRegionServers();
-<a class="jxr_linenumber" name="141" href="#141">141</a> 
-<a class="jxr_linenumber" name="142" href="#142">142</a>     <strong class="jxr_keyword">int</strong> sleepMultiplier = 1;
-<a class="jxr_linenumber" name="143" href="#143">143</a> 
-<a class="jxr_linenumber" name="144" href="#144">144</a>     <em class="jxr_comment">// Connect to peer cluster first, unless we have to stop</em>
-<a class="jxr_linenumber" name="145" href="#145">145</a>     <strong class="jxr_keyword">while</strong> (<strong class="jxr_keyword">this</strong>.isRunning() &amp;&amp; replicationSinkMgr.getSinks().size() == 0) {
-<a class="jxr_linenumber" name="146" href="#146">146</a>       replicationSinkMgr.chooseSinks();
-<a class="jxr_linenumber" name="147" href="#147">147</a>       <strong class="jxr_keyword">if</strong> (<strong class="jxr_keyword">this</strong>.isRunning() &amp;&amp; replicationSinkMgr.getSinks().size() == 0) {
-<a class="jxr_linenumber" name="148" href="#148">148</a>         <strong class="jxr_keyword">if</strong> (sleepForRetries(<span class="jxr_string">"Waiting for peers"</span>, sleepMultiplier)) {
-<a class="jxr_linenumber" name="149" href="#149">149</a>           sleepMultiplier++;
-<a class="jxr_linenumber" name="150" href="#150">150</a>         }
-<a class="jxr_linenumber" name="151" href="#151">151</a>       }
-<a class="jxr_linenumber" name="152" href="#152">152</a>     }
-<a class="jxr_linenumber" name="153" href="#153">153</a>   }
-<a class="jxr_linenumber" name="154" href="#154">154</a> 
-<a class="jxr_linenumber" name="155" href="#155">155</a>   <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="156" href="#156">156</a> <em class="jxr_javadoccomment">   * Do the sleeping logic</em>
-<a class="jxr_linenumber" name="157" href="#157">157</a> <em class="jxr_javadoccomment">   * @param msg Why we sleep</em>
-<a class="jxr_linenumber" name="158" href="#158">158</a> <em class="jxr_javadoccomment">   * @param sleepMultiplier by how many times the default sleeping time is augmented</em>
-<a class="jxr_linenumber" name="159" href="#159">159</a> <em class="jxr_javadoccomment">   * @return True if &lt;code&gt;sleepMultiplier&lt;/code&gt; is &amp;lt; &lt;code&gt;maxRetriesMultiplier&lt;/code&gt;</em>
-<a class="jxr_linenumber" name="160" href="#160">160</a> <em class="jxr_javadoccomment">   */</em>
-<a class="jxr_linenumber" name="161" href="#161">161</a>   <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">boolean</strong> sleepForRetries(String msg, <strong class="jxr_keyword">int</strong> sleepMultiplier) {
-<a class="jxr_linenumber" name="162" href="#162">162</a>     <strong class="jxr_keyword">try</strong> {
-<a class="jxr_linenumber" name="163" href="#163">163</a>       <strong class="jxr_keyword">if</strong> (LOG.isTraceEnabled()) {
-<a class="jxr_linenumber" name="164" href="#164">164</a>         LOG.trace(msg + <span class="jxr_string">", sleeping "</span> + sleepForRetries + <span class="jxr_string">" times "</span> + sleepMultiplier);
-<a class="jxr_linenumber" name="165" href="#165">165</a>       }
-<a class="jxr_linenumber" name="166" href="#166">166</a>       Thread.sleep(<strong class="jxr_keyword">this</strong>.sleepForRetries * sleepMultiplier);
-<a class="jxr_linenumber" name="167" href="#167">167</a>     } <strong class="jxr_keyword">catch</strong> (InterruptedException e) {
-<a class="jxr_linenumber" name="168" href="#168">168</a>       LOG.debug(<span class="jxr_string">"Interrupted while sleeping between retries"</span>);
-<a class="jxr_linenumber" name="169" href="#169">169</a>     }
-<a class="jxr_linenumber" name="170" href="#170">170</a>     <strong class="jxr_keyword">return</strong> sleepMultiplier &lt; maxRetriesMultiplier;
-<a class="jxr_linenumber" name="171" href="#171">171</a>   }
-<a class="jxr_linenumber" name="172" href="#172">172</a> 
-<a class="jxr_linenumber" name="173" href="#173">173</a>   <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="174" href="#174">174</a> <em class="jxr_javadoccomment">   * Do the shipping logic</em>
-<a class="jxr_linenumber" name="175" href="#175">175</a> <em class="jxr_javadoccomment">   */</em>
-<a class="jxr_linenumber" name="176" href="#176">176</a>   @Override
-<a class="jxr_linenumber" name="177" href="#177">177</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">boolean</strong> replicate(<a href="../../../../../../org/apache/hadoop/hbase/replication/ReplicationEndpoint.html">ReplicateContext</a> replicateContext) {
-<a class="jxr_linenumber" name="178" href="#178">178</a>     CompletionService&lt;Integer&gt; pool = <strong class="jxr_keyword">new</strong> ExecutorCompletionService&lt;Integer&gt;(<strong class="jxr_keyword">this</strong>.exec);
-<a class="jxr_linenumber" name="179" href="#179">179</a>     List&lt;Entry&gt; entries = replicateContext.getEntries();
-<a class="jxr_linenumber" name="180" href="#180">180</a>     String walGroupId = replicateContext.getWalGroupId();
-<a class="jxr_linenumber" name="181" href="#181">181</a>     <strong class="jxr_keyword">int</strong> sleepMultiplier = 1;
-<a class="jxr_linenumber" name="182" href="#182">182</a> 
-<a class="jxr_linenumber" name="183" href="#183">183</a>     <strong class="jxr_keyword">if</strong> (!peersSelected &amp;&amp; <strong class="jxr_keyword">this</strong>.isRunning()) {
-<a class="jxr_linenumber" name="184" href="#184">184</a>       connectToPeers();
-<a class="jxr_linenumber" name="185" href="#185">185</a>       peersSelected = <strong class="jxr_keyword">true</strong>;
-<a class="jxr_linenumber" name="186" href="#186">186</a>     }
-<a class="jxr_linenumber" name="187" href="#187">187</a> 
-<a class="jxr_linenumber" name="188" href="#188">188</a>     <strong class="jxr_keyword">if</strong> (replicationSinkMgr.getSinks().size() == 0) {
-<a class="jxr_linenumber" name="189" href="#189">189</a>       <strong class="jxr_keyword">return</strong> false;
-<a class="jxr_linenumber" name="190" href="#190">190</a>     }
-<a class="jxr_linenumber" name="191" href="#191">191</a>     <em class="jxr_comment">// minimum of: configured threads, number of 100-waledit batches,</em>
-<a class="jxr_linenumber" name="192" href="#192">192</a>     <em class="jxr_comment">//  and number of current sinks</em>
-<a class="jxr_linenumber" name="193" href="#193">193</a>     <strong class="jxr_keyword">int</strong> n = Math.min(Math.min(<strong class="jxr_keyword">this</strong>.maxThreads, entries.size()/100+1),
-<a class="jxr_linenumber" name="194" href="#194">194</a>       replicationSinkMgr.getSinks().size());
-<a class="jxr_linenumber" name="195" href="#195">195</a>     List&lt;List&lt;Entry&gt;&gt; entryLists = <strong class="jxr_keyword">new</strong> ArrayList&lt;List&lt;Entry&gt;&gt;(n);
-<a class="jxr_linenumber" name="196" href="#196">196</a>     <strong class="jxr_keyword">if</strong> (n == 1) {
-<a class="jxr_linenumber" name="197" href="#197">197</a>       entryLists.add(entries);
-<a class="jxr_linenumber" name="198" href="#198">198</a>     } <strong class="jxr_keyword">else</strong> {
-<a class="jxr_linenumber" name="199" href="#199">199</a>       <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i=0; i&lt;n; i++) {
-<a class="jxr_linenumber" name="200" href="#200">200</a>         entryLists.add(<strong class="jxr_keyword">new</strong> ArrayList&lt;Entry&gt;(entries.size()/n+1));
-<a class="jxr_linenumber" name="201" href="#201">201</a>       }
-<a class="jxr_linenumber" name="202" href="#202">202</a>       <em class="jxr_comment">// now group by region</em>
-<a class="jxr_linenumber" name="203" href="#203">203</a>       <strong class="jxr_keyword">for</strong> (Entry e : entries) {
-<a class="jxr_linenumber" name="204" href="#204">204</a>         entryLists.get(Math.abs(Bytes.hashCode(e.getKey().getEncodedRegionName())%n)).add(e);
-<a class="jxr_linenumber" name="205" href="#205">205</a>       }
-<a class="jxr_linenumber" name="206" href="#206">206</a>     }
-<a class="jxr_linenumber" name="207" href="#207">207</a>     <strong class="jxr_keyword">while</strong> (<strong class="jxr_keyword">this</strong>.isRunning()) {
-<a class="jxr_linenumber" name="208" href="#208">208</a>       <strong class="jxr_keyword">if</strong> (!isPeerEnabled()) {
-<a class="jxr_linenumber" name="209" href="#209">209</a>         <strong class="jxr_keyword">if</strong> (sleepForRetries(<span class="jxr_string">"Replication is disabled"</span>, sleepMultiplier)) {
-<a class="jxr_linenumber" name="210" href="#210">210</a>           sleepMultiplier++;
-<a class="jxr_linenumber" name="211" href="#211">211</a>         }
-<a class="jxr_linenumber" name="212" href="#212">212</a>         <strong class="jxr_keyword">continue</strong>;
-<a class="jxr_linenumber" name="213" href="#213">213</a>       }
-<a class="jxr_linenumber" name="214" href="#214">214</a>       <strong class="jxr_keyword">try</strong> {
-<a class="jxr_linenumber" name="215" href="#215">215</a>         <strong class="jxr_keyword">if</strong> (LOG.isTraceEnabled()) {
-<a class="jxr_linenumber" name="216" href="#216">216</a>           LOG.trace(<span class="jxr_string">"Replicating "</span> + entries.size() +
-<a class="jxr_linenumber" name="217" href="#217">217</a>               <span class="jxr_string">" entries of total size "</span> + replicateContext.getSize());
-<a class="jxr_linenumber" name="218" href="#218">218</a>         }
-<a class="jxr_linenumber" name="219" href="#219">219</a> 
-<a class="jxr_linenumber" name="220" href="#220">220</a>         <strong class="jxr_keyword">int</strong> futures = 0;
-<a class="jxr_linenumber" name="221" href="#221">221</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i=0; i&lt;entryLists.size(); i++) {
-<a class="jxr_linenumber" name="222" href="#222">222</a>           <strong class="jxr_keyword">if</strong> (!entryLists.get(i).isEmpty()) {
-<a class="jxr_linenumber" name="223" href="#223">223</a>             <strong class="jxr_keyword">if</strong> (LOG.isTraceEnabled()) {
-<a class="jxr_linenumber" name="224" href="#224">224</a>               LOG.trace(<span class="jxr_string">"Submitting "</span> + entryLists.get(i).size() +
-<a class="jxr_linenumber" name="225" href="#225">225</a>                   <span class="jxr_string">" entries of total size "</span> + replicateContext.getSize());
-<a class="jxr_linenumber" name="226" href="#226">226</a>             }
-<a class="jxr_linenumber" name="227" href="#227">227</a>             <em class="jxr_comment">// RuntimeExceptions encountered here bubble up and are handled in ReplicationSource</em>
-<a class="jxr_linenumber" name="228" href="#228">228</a>             pool.submit(createReplicator(entryLists.get(i), i));
-<a class="jxr_linenumber" name="229" href="#229">229</a>             futures++;
-<a class="jxr_linenumber" name="230" href="#230">230</a>           }
-<a class="jxr_linenumber" name="231" href="#231">231</a>         }
-<a class="jxr_linenumber" name="232" href="#232">232</a>         IOException iox = <strong class="jxr_keyword">null</strong>;
-<a class="jxr_linenumber" name="233" href="#233">233</a> 
-<a class="jxr_linenumber" name="234" href="#234">234</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i=0; i&lt;futures; i++) {
-<a class="jxr_linenumber" name="235" href="#235">235</a>           <strong class="jxr_keyword">try</strong> {
-<a class="jxr_linenumber" name="236" href="#236">236</a>             <em class="jxr_comment">// wait for all futures, remove successful parts</em>
-<a class="jxr_linenumber" name="237" href="#237">237</a>             <em class="jxr_comment">// (only the remaining parts will be retried)</em>
-<a class="jxr_linenumber" name="238" href="#238">238</a>             Future&lt;Integer&gt; f = pool.take();
-<a class="jxr_linenumber" name="239" href="#239">239</a>             entryLists.set(f.get().intValue(), Collections.&lt;Entry&gt;emptyList());
-<a class="jxr_linenumber" name="240" href="#240">240</a>           } <strong class="jxr_keyword">catch</strong> (InterruptedException ie) {
-<a class="jxr_linenumber" name="241" href="#241">241</a>             iox =  <strong class="jxr_keyword">new</strong> IOException(ie);
-<a class="jxr_linenumber" name="242" href="#242">242</a>           } <strong class="jxr_keyword">catch</strong> (ExecutionException ee) {
-<a class="jxr_linenumber" name="243" href="#243">243</a>             <em class="jxr_comment">// cause must be an IOException</em>
-<a class="jxr_linenumber" name="244" href="#244">244</a>             iox = (IOException)ee.getCause();
-<a class="jxr_linenumber" name="245" href="#245">245</a>           }
-<a class="jxr_linenumber" name="246" href="#246">246</a>         }
-<a class="jxr_linenumber" name="247" href="#247">247</a>         <strong class="jxr_keyword">if</strong> (iox != <strong class="jxr_keyword">null</strong>) {
-<a class="jxr_linenumber" name="248" href="#248">248</a>           <em class="jxr_comment">// if we had any exceptions, try again</em>
-<a class="jxr_linenumber" name="249" href="#249">249</a>           <strong class="jxr_keyword">throw</strong> iox;
-<a class="jxr_linenumber" name="250" href="#250">250</a>         }
-<a class="jxr_linenumber" name="251" href="#251">251</a>         <em class="jxr_comment">// update metrics</em>
-<a class="jxr_linenumber" name="252" href="#252">252</a>         <strong class="jxr_keyword">this</strong>.metrics.setAgeOfLastShippedOp(entries.get(entries.size() - 1).getKey().getWriteTime(),
-<a class="jxr_linenumber" name="253" href="#253">253</a>           walGroupId);
-<a class="jxr_linenumber" name="254" href="#254">254</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">true</strong>;
-<a class="jxr_linenumber" name="255" href="#255">255</a> 
-<a class="jxr_linenumber" name="256" href="#256">256</a>       } <strong class="jxr_keyword">catch</strong> (IOException ioe) {
-<a class="jxr_linenumber" name="257" href="#257">257</a>         <em class="jxr_comment">// Didn't ship anything, but must still age the last time we did</em>
-<a class="jxr_linenumber" name="258" href="#258">258</a>         <strong class="jxr_keyword">this</strong>.metrics.refreshAgeOfLastShippedOp(walGroupId);
-<a class="jxr_linenumber" name="259" href="#259">259</a>         <strong class="jxr_keyword">if</strong> (ioe instanceof RemoteException) {
-<a class="jxr_linenumber" name="260" href="#260">260</a>           ioe = ((RemoteException) ioe).unwrapRemoteException();
-<a class="jxr_linenumber" name="261" href="#261">261</a>           LOG.warn(<span class="jxr_string">"Can't replicate because of an error on the remote cluster: "</span>, ioe);
-<a class="jxr_linenumber" name="262" href="#262">262</a>           <strong class="jxr_keyword">if</strong> (ioe instanceof TableNotFoundException) {
-<a class="jxr_linenumber" name="263" href="#263">263</a>             <strong class="jxr_keyword">if</strong> (sleepForRetries(<span class="jxr_string">"A table is missing in the peer cluster. "</span>
-<a class="jxr_linenumber" name="264" href="#264">264</a>                 + <span class="jxr_string">"Replication cannot proceed without losing data."</span>, sleepMultiplier)) {
-<a class="jxr_linenumber" name="265" href="#265">265</a>               sleepMultiplier++;
-<a class="jxr_linenumber" name="266" href="#266">266</a>             }
-<a class="jxr_linenumber" name="267" href="#267">267</a>           }
-<a class="jxr_linenumber" name="268" href="#268">268</a>         } <strong class="jxr_keyword">else</strong> {
-<a class="jxr_linenumber" name="269" href="#269">269</a>           <strong class="jxr_keyword">if</strong> (ioe instanceof SocketTimeoutException) {
-<a class="jxr_linenumber" name="270" href="#270">270</a>             <em class="jxr_comment">// This exception means we waited for more than 60s and nothing</em>
-<a class="jxr_linenumber" name="271" href="#271">271</a>             <em class="jxr_comment">// happened, the cluster is alive and calling it right away</em>
-<a class="jxr_linenumber" name="272" href="#272">272</a>             <em class="jxr_comment">// even for a test just makes things worse.</em>
-<a class="jxr_linenumber" name="273" href="#273">273</a>             sleepForRetries(<span class="jxr_string">"Encountered a SocketTimeoutException. Since the "</span> +
-<a class="jxr_linenumber" name="274" href="#274">274</a>               <span class="jxr_string">"call to the remote cluster timed out, which is usually "</span> +
-<a class="jxr_linenumber" name="275" href="#275">275</a>               <span class="jxr_string">"caused by a machine failure or a massive slowdown"</span>,
-<a class="jxr_linenumber" name="276" href="#276">276</a>               <strong class="jxr_keyword">this</strong>.socketTimeoutMultiplier);
-<a class="jxr_linenumber" name="277" href="#277">277</a>           } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (ioe instanceof ConnectException) {
-<a class="jxr_linenumber" name="278" href="#278">278</a>             LOG.warn(<span class="jxr_string">"Peer is unavailable, rechecking all sinks: "</span>, ioe);
-<a class="jxr_linenumber" name="279" href="#279">279</a>             replicationSinkMgr.chooseSinks();
-<a class="jxr_linenumber" name="280" href="#280">280</a>           } <strong class="jxr_keyword">else</strong> {
-<a class="jxr_linenumber" name="281" href="#281">281</a>             LOG.warn(<span class="jxr_string">"Can't replicate because of a local or network error: "</span>, ioe);
-<a class="jxr_linenumber" name="282" href="#282">282</a>           }
-<a class="jxr_linenumber" name="283" href="#283">283</a>         }
-<a class="jxr_linenumber" name="284" href="#284">284</a>         <strong class="jxr_keyword">if</strong> (sleepForRetries(<span class="jxr_string">"Since we are unable to replicate"</span>, sleepMultiplier)) {
-<a class="jxr_linenumber" name="285" href="#285">285</a>           sleepMultiplier++;
-<a class="jxr_linenumber" name="286" href="#286">286</a>         }
-<a class="jxr_linenumber" name="287" href="#287">287</a>       }
-<a class="jxr_linenumber" name="288" href="#288">288</a>     }
-<a class="jxr_linenumber" name="289" href="#289">289</a>     <strong class="jxr_keyword">return</strong> false; <em class="jxr_comment">// in case we exited before replicating</em>
-<a class="jxr_linenumber" name="290" href="#290">290</a>   }
-<a class="jxr_linenumber" name="291" href="#291">291</a> 
-<a class="jxr_linenumber" name="292" href="#292">292</a>   <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">boolean</strong> isPeerEnabled() {
-<a class="jxr_linenumber" name="293" href="#293">293</a>     <strong class="jxr_keyword">return</strong> ctx.getReplicationPeer().getPeerState() == PeerState.ENABLED;
-<a class="jxr_linenumber" name="294" href="#294">294</a>   }
-<a class="jxr_linenumber" name="295" href="#295">295</a> 
-<a class="jxr_linenumber" name="296" href="#296">296</a>   @Override
-<a class="jxr_linenumber" name="297" href="#297">297</a>   <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">void</strong> doStop() {
-<a class="jxr_linenumber" name="298" href="#298">298</a>     disconnect(); <em class="jxr_comment">//don't call super.doStop()</em>
-<a class="jxr_linenumber" name="299" href="#299">299</a>     <strong class="jxr_keyword">if</strong> (<strong class="jxr_keyword">this</strong>.conn != <strong class="jxr_keyword">null</strong>) {
-<a class="jxr_linenumber" name="300" href="#300">300</a>       <strong class="jxr_keyword">try</strong> {
-<a class="jxr_linenumber" name="301" href="#301">301</a>         <strong class="jxr_keyword">this</strong>.conn.close();
-<a class="jxr_linenumber" name="302" href="#302">302</a>         <strong class="jxr_keyword">this</strong>.conn = <strong class="jxr_keyword">null</strong>;
-<a class="jxr_linenumber" name="303" href="#303">303</a>       } <strong class="jxr_keyword">catch</strong> (IOException e) {
-<a class="jxr_linenumber" name="304" href="#304">304</a>         LOG.warn(<span class="jxr_string">"Failed to close the connection"</span>);
-<a class="jxr_linenumber" name="305" href="#305">305</a>       }
-<a class="jxr_linenumber" name="306" href="#306">306</a>     }
-<a class="jxr_linenumber" name="307" href="#307">307</a>     exec.shutdownNow();
-<a class="jxr_linenumber" name="308" href="#308">308</a>     notifyStopped();
-<a class="jxr_linenumber" name="309" href="#309">309</a>   }
-<a class="jxr_linenumber" name="310" href="#310">310</a> 
-<a class="jxr_linenumber" name="311" href="#311">311</a>   <em class="jxr_comment">// is this needed? Nobody else will call doStop() otherwise</em>
-<a class="jxr_linenumber" name="312" href="#312">312</a>   @Override
-<a class="jxr_linenumber" name="313" href="#313">313</a>   <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/hadoop/hbase/Coprocessor.html">State</a> stopAndWait() {
-<a class="jxr_linenumber" name="314" href="#314">314</a>     doStop();
-<a class="jxr_linenumber" name="315" href="#315">315</a>     <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">super</strong>.stopAndWait();
-<a class="jxr_linenumber" name="316" href="#316">316</a>   }
-<a class="jxr_linenumber" name="317" href="#317">317</a> 
-<a class="jxr_linenumber" name="318" href="#318">318</a>   @VisibleForTesting
-<a class="jxr_linenumber" name="319" href="#319">319</a>   <strong class="jxr_keyword">protected</strong> <a href="../../../../../../org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html">Replicator</a> createReplicator(List&lt;Entry&gt; entries, <strong class="jxr_keyword">int</strong> ordinal) {
-<a class="jxr_linenumber" name="320" href="#320">320</a>     <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html">Replicator</a>(entries, ordinal);
-<a class="jxr_linenumber" name="321" href="#321">321</a>   }
-<a class="jxr_linenumber" name="322" href="#322">322</a> 
-<a class="jxr_linenumber" name="323" href="#323">323</a>   @VisibleForTesting
-<a class="jxr_linenumber" name="324" href="#324">324</a>   <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../../../org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html">Replicator</a> <strong class="jxr_keyword">implements</strong> Callable&lt;Integer&gt; {
-<a class="jxr_linenumber" name="325" href="#325">325</a>     <strong class="jxr_keyword">private</strong> List&lt;Entry&gt; entries;
-<a class="jxr_linenumber" name="326" href="#326">326</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> ordinal;
-<a class="jxr_linenumber" name="327" href="#327">327</a>     <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html">Replicator</a>(List&lt;Entry&gt; entries, <strong class="jxr_keyword">int</strong> ordinal) {
-<a class="jxr_linenumber" name="328" href="#328">328</a>       <strong class="jxr_keyword">this</strong>.entries = entries;
-<a class="jxr_linenumber" name="329" href="#329">329</a>       <strong class="jxr_keyword">this</strong>.ordinal = ordinal;
-<a class="jxr_linenumber" name="330" href="#330">330</a>     }
-<a class="jxr_linenumber" name="331" href="#331">331</a> 
-<a class="jxr_linenumber" name="332" href="#332">332</a>     @Override
-<a class="jxr_linenumber" name="333" href="#333">333</a>     <strong class="jxr_keyword">public</strong> Integer call() <strong class="jxr_keyword">throws</strong> IOException {
-<a class="jxr_linenumber" name="334" href="#334">334</a>       <a href="../../../../../../org/apache/hadoop/hbase/replication/regionserver/ReplicationSinkManager.html">SinkPeer</a> sinkPeer = <strong class="jxr_keyword">null</strong>;
-<a class="jxr_linenumber" name="335" href="#335">335</a>       <strong class="jxr_keyword">try</strong> {
-<a class="jxr_linenumber" name="336" href="#336">336</a>         sinkPeer = replicationSinkMgr.getReplicationSink();
-<a class="jxr_linenumber" name="337" href="#337">337</a>         BlockingInterface rrs = sinkPeer.getRegionServer();
-<a class="jxr_linenumber" name="338" href="#338">338</a>         ReplicationProtbufUtil.replicateWALEntry(rrs, entries.toArray(<strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/hadoop/hbase/util/IdLock.html">Entry</a>[entries.size()]),
-<a class="jxr_linenumber" name="339" href="#339">339</a>           replicationClusterId, baseNamespaceDir, hfileArchiveDir);
-<a class="jxr_linenumber" name="340" href="#340">340</a>         replicationSinkMgr.reportSinkSuccess(sinkPeer);
-<a class="jxr_linenumber" name="341" href="#341">341</a>         <strong class="jxr_keyword">return</strong> ordinal;
-<a class="jxr_linenumber" name="342" href="#342">342</a> 
-<a class="jxr_linenumber" name="343" href="#343">343</a>       } <strong class="jxr_keyword">catch</strong> (IOException ioe) {
-<a class="jxr_linenumber" name="344" href="#344">344</a>         <strong class="jxr_keyword">if</strong> (sinkPeer != <strong class="jxr_keyword">null</strong>) {
-<a class="jxr_linenumber" name="345" href="#345">345</a>           replicationSinkMgr.reportBadSink(sinkPeer);
-<a class="jxr_linenumber" name="346" href="#346">346</a>         }
-<a class="jxr_linenumber" name="347" href="#347">347</a>         <strong class="jxr_keyword">throw</strong> ioe;
-<a class="jxr_linenumber" name="348" href="#348">348</a>       }
-<a class="jxr_linenumber" name="349" href="#349">349</a>     }
-<a class="jxr_linenumber" name="350" href="#350">350</a> 
-<a class="jxr_linenumber" name="351" href="#351">351</a>   }
-<a class="jxr_linenumber" name="352" href="#352">352</a> }
+<a class="jxr_linenumber" name="116" href="#116">116</a>     <strong class="jxr_keyword">this</strong>.exec = <strong class="jxr_keyword">new</strong> ThreadPoolExecutor(maxThreads, maxThreads, 60, TimeUnit.SECONDS,
+<a class="jxr_linenumber" name="117" href="#117">117</a>         <strong class="jxr_keyword">new</strong> LinkedBlockingQueue&lt;Runnable&gt;());
+<a class="jxr_linenumber" name="118" href="#118">118</a>     <strong class="jxr_keyword">this</strong>.exec.allowCoreThreadTimeOut(<strong class="jxr_keyword">true</strong>);
+<a class="jxr_linenumber" name="119" href="#119">119</a> 
+<a class="jxr_linenumber" name="120" href="#120">120</a>     <strong class="jxr_keyword">this</strong>.replicationBulkLoadDataEnabled =
+<a class="jxr_linenumber" name="121" href="#121">121</a>         conf.getBoolean(HConstants.REPLICATION_BULKLOAD_ENABLE_KEY,
+<a class="jxr_linenumber" name="122" href="#122">122</a>           HConstants.REPLICATION_BULKLOAD_ENABLE_DEFAULT);
+<a class="jxr_linenumber" name="123" href="#123">123</a>     <strong class="jxr_keyword">if</strong> (<strong class="jxr_keyword">this</strong>.replicationBulkLoadDataEnabled) {
+<a class="jxr_linenumber" name="124" href="#124">124</a>       replicationClusterId = <strong class="jxr_keyword">this</strong>.conf.get(HConstants.REPLICATION_CLUSTER_ID);
+<a class="jxr_linenumber" name="125" href="#125">125</a>     }
+<a class="jxr_linenumber" name="126" href="#126">126</a>     <em class="jxr_comment">// Construct base namespace directory and hfile archive directory path</em>
+<a class="jxr_linenumber" name="127" href="#127">127</a>     Path rootDir = FSUtils.getRootDir(conf);
+<a class="jxr_linenumber" name="128" href="#128">128</a>     Path baseNSDir = <strong class="jxr_keyword">new</strong> Path(HConstants.BASE_NAMESPACE_DIR);
+<a class="jxr_linenumber" name="129" href="#129">129</a>     baseNamespaceDir = <strong class="jxr_keyword">new</strong> Path(rootDir, baseNSDir);
+<a class="jxr_linenumber" name="130" href="#130">130</a>     hfileArchiveDir = <strong class="jxr_keyword">new</strong> Path(rootDir, <strong class="jxr_keyword">new</strong> Path(HConstants.HFILE_ARCHIVE_DIRECTORY, baseNSDir));
+<a class="jxr_linenumber" name="131" href="#131">131</a>   }
+<a class="jxr_linenumber" name="132" href="#132">132</a> 
+<a class="jxr_linenumber" name="133" href="#133">133</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> decorateConf() {
+<a class="jxr_linenumber" name="134" href="#134">134</a>     String replicationCodec = <strong class="jxr_keyword">this</strong>.conf.get(HConstants.REPLICATION_CODEC_CONF_KEY);
+<a class="jxr_linenumber" name="135" href="#135">135</a>     <strong class="jxr_keyword">if</strong> (StringUtils.isNotEmpty(replicationCodec)) {
+<a class="jxr_linenumber" name="136" href="#136">136</a>       <strong class="jxr_keyword">this</strong>.conf.set(HConstants.RPC_CODEC_CONF_KEY, replicationCodec);
+<a class="jxr_linenumber" name="137" href="#137">137</a>     }
+<a class="jxr_linenumber" name="138" href="#138">138</a>   }
+<a class="jxr_linenumber" name="139" href="#139">139</a> 
+<a class="jxr_linenumber" name="140" href="#140">140</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> connectToPeers() {
+<a class="jxr_linenumber" name="141" href="#141">141</a>     getRegionServers();
+<a class="jxr_linenumber" name="142" href="#142">142</a> 
+<a class="jxr_linenumber" name="143" href="#143">143</a>     <strong class="jxr_keyword">int</strong> sleepMultiplier = 1;
+<a class="jxr_linenumber" name="144" href="#144">144</a> 
+<a class="jxr_linenumber" name="145" href="#145">145</a>     <em class="jxr_comment">// Connect to peer cluster first, unless we have to stop</em>
+<a class="jxr_linenumber" name="146" href="#146">146</a>     <strong class="jxr_keyword">while</strong> (<strong class="jxr_keyword">this</strong>.isRunning() &amp;&amp; replicationSinkMgr.getSinks().size() == 0) {
+<a class="jxr_linenumber" name="147" href="#147">147</a>       replicationSinkMgr.chooseSinks();
+<a class="jxr_linenumber" name="148" href="#148">148</a>       <strong class="jxr_keyword">if</strong> (<strong class="jxr_keyword">this</strong>.isRunning() &amp;&amp; replicationSinkMgr.getSinks().size() == 0) {
+<a class="jxr_linenumber" name="149" href="#149">149</a>         <strong class="jxr_keyword">if</strong> (sleepForRetries(<span class="jxr_string">"Waiting for peers"</span>, sleepMultiplier)) {
+<a class="jxr_linenumber" name="150" href="#150">150</a>           sleepMultiplier++;
+<a class="jxr_linenumber" name="151" href="#151">151</a>         }
+<a class="jxr_linenumber" name="152" href="#152">152</a>       }
+<a class="jxr_linenumber" name="153" href="#153">153</a>     }
+<a class="jxr_linenumber" name="154" href="#154">154</a>   }
+<a class="jxr_linenumber" name="155" href="#155">155</a> 
+<a class="jxr_linenumber" name="156" href="#156">156</a>   <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="157" href="#157">157</a> <em class="jxr_javadoccomment">   * Do the sleeping logic</em>
+<a class="jxr_linenumber" name="158" href="#158">158</a> <em class="jxr_javadoccomment">   * @param msg Why we sleep</em>
+<a class="jxr_linenumber" name="159" href="#159">159</a> <em class="jxr_javadoccomment">   * @param sleepMultiplier by how many times the default sleeping time is augmented</em>
+<a class="jxr_linenumber" name="160" href="#160">160</a> <em class="jxr_javadoccomment">   * @return True if &lt;code&gt;sleepMultiplier&lt;/code&gt; is &amp;lt; &lt;code&gt;maxRetriesMultiplier&lt;/code&gt;</em>
+<a class="jxr_linenumber" name="161" href="#161">161</a> <em class="jxr_javadoccomment">   */</em>
+<a class="jxr_linenumber" name="162" href="#162">162</a>   <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">boolean</strong> sleepForRetries(String msg, <strong class="jxr_keyword">int</strong> sleepMultiplier) {
+<a class="jxr_linenumber" name="163" href="#163">163</a>     <strong class="jxr_keyword">try</strong> {
+<a class="jxr_linenumber" name="164" href="#164">164</a>       <strong class="jxr_keyword">if</strong> (LOG.isTraceEnabled()) {
+<a class="jxr_linenumber" name="165" href="#165">165</a>         LOG.trace(msg + <span class="jxr_string">", sleeping "</span> + sleepForRetries + <span class="jxr_string">" times "</span> + sleepMultiplier);
+<a class="jxr_linenumber" name="166" href="#166">166</a>       }
+<a class="jxr_linenumber" name="167" href="#167">167</a>       Thread.sleep(<strong class="jxr_keyword">this</strong>.sleepForRetries * sleepMultiplier);
+<a class="jxr_linenumber" name="168" href="#168">168</a>     } <strong class="jxr_keyword">catch</strong> (InterruptedException e) {
+<a class="jxr_linenumber" name="169" href="#169">169</a>       LOG.debug(<span class="jxr_string">"Interrupted while sleeping between retries"</span>);
+<a class="jxr_linenumber" name="170" href="#170">170</a>     }
+<a class="jxr_linenumber" name="171" href="#171">171</a>     <strong class="jxr_keyword">return</strong> sleepMultiplier &lt; maxRetriesMultiplier;
+<a class="jxr_linenumber" name="172" href="#172">172</a>   }
+<a class="jxr_linenumber" name="173" href="#173">173</a> 
+<a class="jxr_linenumber" name="174" href="#174">174</a>   <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="175" href="#175">175</a> <em class="jxr_javadoccomment">   * Do the shipping logic</em>
+<a class="jxr_linenumber" name="176" href="#176">176</a> <em class="jxr_javadoccomment">   */</em>
+<a class="jxr_linenumber" name="177" href="#177">177</a>   @Override
+<a class="jxr_linenumber" name="178" href="#178">178</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">boolean</strong> replicate(<a href="../../../../../../org/apache/hadoop/hbase/replication/ReplicationEndpoint.html">ReplicateContext</a> replicateContext) {
+<a class="jxr_linenumber" name="179" href="#179">179</a>     CompletionService&lt;Integer&gt; pool = <strong class="jxr_keyword">new</strong> ExecutorCompletionService&lt;Integer&gt;(<strong class="jxr_keyword">this</strong>.exec);
+<a class="jxr_linenumber" name="180" href="#180">180</a>     List&lt;Entry&gt; entries = replicateContext.getEntries();
+<a class="jxr_linenumber" name="181" href="#181">181</a>     String walGroupId = replicateContext.getWalGroupId();
+<a class="jxr_linenumber" name="182" href="#182">182</a>     <strong class="jxr_keyword">int</strong> sleepMultiplier = 1;
+<a class="jxr_linenumber" name="183" href="#183">183</a> 
+<a class="jxr_linenumber" name="184" href="#184">184</a>     <strong class="jxr_keyword">if</strong> (!peersSelected &amp;&amp; <strong class="jxr_keyword">this</strong>.isRunning()) {
+<a class="jxr_linenumber" name="185" href="#185">185</a>       connectToPeers();
+<a class="jxr_linenumber" name="186" href="#186">186</a>       peersSelected = <strong class="jxr_keyword">true</strong>;
+<a class="jxr_linenumber" name="187" href="#187">187</a>     }
+<a class="jxr_linenumber" name="188" href="#188">188</a> 
+<a class="jxr_linenumber" name="189" href="#189">189</a>     <strong class="jxr_keyword">if</strong> (replicationSinkMgr.getSinks().size() == 0) {
+<a class="jxr_linenumber" name="190" href="#190">190</a>       <strong class="jxr_keyword">return</strong> false;
+<a class="jxr_linenumber" name="191" href="#191">191</a>     }
+<a class="jxr_linenumber" name="192" href="#192">192</a>     <em class="jxr_comment">// minimum of: configured threads, number of 100-waledit batches,</em>
+<a class="jxr_linenumber" name="193" href="#193">193</a>     <em class="jxr_comment">//  and number of current sinks</em>
+<a class="jxr_linenumber" name="194" href="#194">194</a>     <strong class="jxr_keyword">int</strong> n = Math.min(Math.min(<strong class="jxr_keyword">this</strong>.maxThreads, entries.size()/100+1),
+<a class="jxr_linenumber" name="195" href="#195">195</a>       replicationSinkMgr.getSinks().size());
+<a class="jxr_linenumber" name="196" href="#196">196</a>     List&lt;List&lt;Entry&gt;&gt; entryLists = <strong class="jxr_keyword">new</strong> ArrayList&lt;List&lt;Entry&gt;&gt;(n);
+<a class="jxr_linenumber" name="197" href="#197">197</a>     <strong class="jxr_keyword">if</strong> (n == 1) {
+<a class="jxr_linenumber" name="198" href="#198">198</a>       entryLists.add(entries);
+<a class="jxr_linenumber" name="199" href="#199">199</a>     } <strong class="jxr_keyword">else</strong> {
+<a class="jxr_linenumber" name="200" href="#200">200</a>       <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i=0; i&lt;n; i++) {
+<a class="jxr_linenumber" name="201" href="#201">201</a>         entryLists.add(<strong class="jxr_keyword">new</strong> ArrayList&lt;Entry&gt;(entries.size()/n+1));
+<a class="jxr_linenumber" name="202" href="#202">202</a>       }
+<a class="jxr_linenumber" name="203" href="#203">203</a>       <em class="jxr_comment">// now group by region</em>
+<a class="jxr_linenumber" name="204" href="#204">204</a>       <strong class="jxr_keyword">for</strong> (Entry e : entries) {
+<a class="jxr_linenumber" name="205" href="#205">205</a>         entryLists.get(Math.abs(Bytes.hashCode(e.getKey().getEncodedRegionName())%n)).add(e);
+<a class="jxr_linenumber" name="206" href="#206">206</a>       }
+<a class="jxr_linenumber" name="207" href="#207">207</a>     }
+<a class="jxr_linenumber" name="208" href="#208">208</a>     <strong class="jxr_keyword">while</strong> (<strong class="jxr_keyword">this</strong>.isRunning()) {
+<a class="jxr_linenumber" name="209" href="#209">209</a>       <strong class="jxr_keyword">if</strong> (!isPeerEnabled()) {
+<a class="jxr_linenumber" name="210" href="#210">210</a>         <strong class="jxr_keyword">if</strong> (sleepForRetries(<span class="jxr_string">"Replication is disabled"</span>, sleepMultiplier)) {
+<a class="jxr_linenumber" name="211" href="#211">211</a>           sleepMultiplier++;
+<a class="jxr_linenumber" name="212" href="#212">212</a>         }
+<a class="jxr_linenumber" name="213" href="#213">213</a>         <strong class="jxr_keyword">continue</strong>;
+<a class="jxr_linenumber" name="214" href="#214">214</a>       }
+<a class="jxr_linenumber" name="215" href="#215">215</a>       <strong class="jxr_keyword">try</strong> {
+<a class="jxr_linenumber" name="216" href="#216">216</a>         <strong class="jxr_keyword">if</strong> (LOG.isTraceEnabled()) {
+<a class="jxr_linenumber" name="217" href="#217">217</a>           LOG.trace(<span class="jxr_string">"Replicating "</span> + entries.size() +
+<a class="jxr_linenumber" name="218" href="#218">218</a>               <span class="jxr_string">" entries of total size "</span> + replicateContext.getSize());
+<a class="jxr_linenumber" name="219" href="#219">219</a>         }
+<a class="jxr_linenumber" name="220" href="#220">220</a> 
+<a class="jxr_linenumber" name="221" href="#221">221</a>         <strong class="jxr_keyword">int</strong> futures = 0;
+<a class="jxr_linenumber" name="222" href="#222">222</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i=0; i&lt;entryLists.size(); i++) {
+<a class="jxr_linenumber" name="223" href="#223">223</a>           <strong class="jxr_keyword">if</strong> (!entryLists.get(i).isEmpty()) {
+<a class="jxr_linenumber" name="224" href="#224">224</a>             <strong class="jxr_keyword">if</strong> (LOG.isTraceEnabled()) {
+<a class="jxr_linenumber" name="225" href="#225">225</a>               LOG.trace(<span class="jxr_string">"Submitting "</span> + entryLists.get(i).size() +
+<a class="jxr_linenumber" name="226" href="#226">226</a>                   <span class="jxr_string">" entries of total size "</span> + replicateContext.getSize());
+<a class="jxr_linenumber" name="227" href="#227">227</a>             }
+<a class="jxr_linenumber" name="228" href="#228">228</a>             <em class="jxr_comment">// RuntimeExceptions encountered here bubble up and are handled in ReplicationSource</em>
+<a class="jxr_linenumber" name="229" href="#229">229</a>             pool.submit(createReplicator(entryLists.get(i), i));
+<a class="jxr_linenumber" name="230" href="#230">230</a>             futures++;
+<a class="jxr_linenumber" name="231" href="#231">231</a>           }
+<a class="jxr_linenumber" name="232" href="#232">232</a>         }
+<a class="jxr_linenumber" name="233" href="#233">233</a>         IOException iox = <strong class="jxr_keyword">null</strong>;
+<a class="jxr_linenumber" name="234" href="#234">234</a> 
+<a class="jxr_linenumber" name="235" href="#235">235</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i=0; i&lt;futures; i++) {
+<a class="jxr_linenumber" name="236" href="#236">236</a>           <strong class="jxr_keyword">try</strong> {
+<a class="jxr_linenumber" name="237" href="#237">237</a>             <em class="jxr_comment">// wait for all futures, remove successful parts</em>
+<a class="jxr_linenumber" name="238" href="#238">238</a>             <em class="jxr_comment">// (only the remaining parts will be retried)</em>
+<a class="jxr_linenumber" name="239" href="#239">239</a>             Future&lt;Integer&gt; f = pool.take();
+<a class="jxr_linenumber" name="240" href="#240">240</a>             entryLists.set(f.get().intValue(), Collections.&lt;Entry&gt;emptyList());
+<a class="jxr_linenumber" name="241" href="#241">241</a>           } <strong class="jxr_keyword">catch</strong> (InterruptedException ie) {
+<a class="jxr_linenumber" name="242" href="#242">242</a>             iox =  <strong class="jxr_keyword">new</strong> IOException(ie);
+<a class="jxr_linenumber" name="243" href="#243">243</a>           } <strong class="jxr_keyword">catch</strong> (ExecutionException ee) {
+<a class="jxr_linenumber" name="244" href="#244">244</a>             <em class="jxr_comment">// cause must be an IOException</em>
+<a class="jxr_linenumber" name="245" href="#245">245</a>             iox = (IOException)ee.getCause();
+<a class="jxr_linenumber" name="246" href="#246">246</a>           }
+<a class="jxr_linenumber" name="247" href="#247">247</a>         }
+<a class="jxr_linenumber" name="248" href="#248">248</a>         <strong class="jxr_keyword">if</strong> (iox != <strong class="jxr_keyword">null</strong>) {
+<a class="jxr_linenumber" name="249" href="#249">249</a>           <em class="jxr_comment">// if we had any exceptions, try again</em>
+<a class="jxr_linenumber" name="250" href="#250">250</a>           <strong class="jxr_keyword">throw</strong> iox;
+<a class="jxr_linenumber" name="251" href="#251">251</a>         }
+<a class="jxr_linenumber" name="252" href="#252">252</a>         <em class="jxr_comment">// update metrics</em>
+<a class="jxr_linenumber" name="253" href="#253">253</a>         <strong class="jxr_keyword">this</strong>.metrics.setAgeOfLastShippedOp(entries.get(entries.size() - 1).getKey().getWriteTime(),
+<a class="jxr_linenumber" name="254" href="#254">254</a>           walGroupId);
+<a class="jxr_linenumber" name="255" href="#255">255</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">true</strong>;
+<a class="jxr_linenumber" name="256" href="#256">256</a> 
+<a class="jxr_linenumber" name="257" href="#257">257</a>       } <strong class="jxr_keyword">catch</strong> (IOException ioe) {
+<a class="jxr_linenumber" name="258" href="#258">258</a>         <em class="jxr_comment">// Didn't ship anything, but must still age the last time we did</em>
+<a class="jxr_linenumber" name="259" href="#259">259</a>         <strong class="jxr_keyword">this</strong>.metrics.refreshAgeOfLastShippedOp(walGroupId);
+<a class="jxr_linenumber" name="260" href="#260">260</a>         <strong class="jxr_keyword">if</strong> (ioe instanceof RemoteException) {
+<a class="jxr_linenumber" name="261" href="#261">261</a>           ioe = ((RemoteException) ioe).unwrapRemoteException();
+<a class="jxr_linenumber" name="262" href="#262">262</a>           LOG.warn(<span class="jxr_string">"Can't replicate because of an error on the remote cluster: "</span>, ioe);
+<a class="jxr_linenumber" name="263" href="#263">263</a>           <strong class="jxr_keyword">if</strong> (ioe instanceof TableNotFoundException) {
+<a class="jxr_linenumber" name="264" href="#264">264</a>             <strong class="jxr_keyword">if</strong> (sleepForRetries(<span class="jxr_string">"A table is missing in the peer cluster. "</span>
+<a class="jxr_linenumber" name="265" href="#265">265</a>                 + <span class="jxr_string">"Replication cannot proceed without losing data."</span>, sleepMultiplier)) {
+<a class="jxr_linenumber" name="266" href="#266">266</a>               sleepMultiplier++;
+<a class="jxr_linenumber" name="267" href="#267">267</a>             }
+<a class="jxr_linenumber" name="268" href="#268">268</a>           }
+<a class="jxr_linenumber" name="269" href="#269">269</a>         } <strong class="jxr_keyword">else</strong> {
+<a class="jxr_linenumber" name="270" href="#270">270</a>           <strong class="jxr_keyword">if</strong> (ioe instanceof SocketTimeoutException) {
+<a class="jxr_linenumber" name="271" href="#271">271</a>             <em class="jxr_comment">// This exception means we waited for more than 60s and nothing</em>
+<a class="jxr_linenumber" name="272" href="#272">272</a>             <em class="jxr_comment">// happened, the cluster is alive and calling it right away</em>
+<a class="jxr_linenumber" name="273" href="#273">273</a>             <em class="jxr_comment">// even for a test just makes things worse.</em>
+<a class="jxr_linenumber" name="274" href="#274">274</a>             sleepForRetries(<span class="jxr_string">"Encountered a SocketTimeoutException. Since the "</span> +
+<a class="jxr_linenumber" name="275" href="#275">275</a>               <span class="jxr_string">"call to the remote cluster timed out, which is usually "</span> +
+<a class="jxr_linenumber" name="276" href="#276">276</a>               <span class="jxr_string">"caused by a machine failure or a massive slowdown"</span>,
+<a class="jxr_linenumber" name="277" href="#277">277</a>               <strong class="jxr_keyword">this</strong>.socketTimeoutMultiplier);
+<a class="jxr_linenumber" name="278" href="#278">278</a>           } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (ioe instanceof ConnectException) {
+<a class="jxr_linenumber" name="279" href="#279">279</a>             LOG.warn(<span class="jxr_string">"Peer is unavailable, rechecking all sinks: "</span>, ioe);
+<a class="jxr_linenumber" name="280" href="#280">280</a>             replicationSinkMgr.chooseSinks();
+<a class="jxr_linenumber" name="281" href="#281">281</a>           } <strong class="jxr_keyword">else</strong> {
+<a class="jxr_linenumber" name="282" href="#282">282</a>             LOG.warn(<span class="jxr_string">"Can't replicate because of a local or network error: "</span>, ioe);
+<a class="jxr_linenumber" name="283" href="#283">283</a>           }
+<a class="jxr_linenumber" name="284" href="#284">284</a>         }
+<a class="jxr_linenumber" name="285" href="#285">285</a>         <strong class="jxr_keyword">if</strong> (sleepForRetries(<span class="jxr_string">"Since we are unable to replicate"</span>, sleepMultiplier)) {
+<a class="jxr_linenumber" name="286" href="#286">286</a>           sleepMultiplier++;
+<a class="jxr_linenumber" name="287" href="#287">287</a>         }
+<a class="jxr_linenumber" name="288" href="#288">288</a>       }
+<a class="jxr_linenumber" name="289" href="#289">289</a>     }
+<a class="jxr_linenumber" name="290" href="#290">290</a>     <strong class="jxr_keyword">return</strong> false; <em class="jxr_comment">// in case we exited before replicating</em>
+<a class="jxr_linenumber" name="291" href="#291">291</a>   }
+<a class="jxr_linenumber" name="292" href="#292">292</a> 
+<a class="jxr_linenumber" name="293" href="#293">293</a>   <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">boolean</strong> isPeerEnabled() {
+<a class="jxr_linenumber" name="294" href="#294">294</a>     <strong class="jxr_keyword">return</strong> ctx.getReplicationPeer().getPeerState() == PeerState.ENABLED;
+<a class="jxr_linenumber" name="295" href="#295">295</a>   }
+<a class="jxr_linenumber" name="296" href="#296">296</a> 
+<a class="jxr_linenumber" name="297" href="#297">297</a>   @Override
+<a class="jxr_linenumber" name="298" href="#298">298</a>   <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">void</strong> doStop() {
+<a class="jxr_linenumber" name="299" href="#299">299</a>     disconnect(); <em class="jxr_comment">//don't call super.doStop()</em>
+<a class="jxr_linenumber" name="300" href="#300">300</a>     <strong class="jxr_keyword">if</strong> (<strong class="jxr_keyword">this</strong>.conn != <strong class="jxr_keyword">null</strong>) {
+<a class="jxr_linenumber" name="301" href="#301">301</a>       <strong class="jxr_keyword">try</strong> {
+<a class="jxr_linenumber" name="302" href="#302">302</a>         <strong class="jxr_keyword">this</strong>.conn.close();
+<a class="jxr_linenumber" name="303" href="#303">303</a>         <strong class="jxr_keyword">this</strong>.conn = <strong class="jxr_keyword">null</strong>;
+<a class="jxr_linenumber" name="304" href="#304">304</a>       } <strong class="jxr_keyword">catch</strong> (IOException e) {
+<a class="jxr_linenumber" name="305" href="#305">305</a>         LOG.warn(<span class="jxr_string">"Failed to close the connection"</span>);
+<a class="jxr_linenumber" name="306" href="#306">306</a>       }
+<a class="jxr_linenumber" name="307" href="#307">307</a>     }
+<a class="jxr_linenumber" name="308" href="#308">308</a>     exec.shutdownNow();
+<a class="jxr_linenumber" name="309" href="#309">309</a>     notifyStopped();
+<a class="jxr_linenumber" name="310" href="#310">310</a>   }
+<a class="jxr_linenumber" name="311" href="#311">311</a> 
+<a class="jxr_linenumber" name="312" href="#312">312</a>   <em class="jxr_comment">// is this needed? Nobody else will call doStop() otherwise</em>
+<a class="jxr_linenumber" name="313" href="#313">313</a>   @Override
+<a class="jxr_linenumber" name="314" href="#314">314</a>   <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/hadoop/hbase/Coprocessor.html">State</a> stopAndWait() {
+<a class="jxr_linenumber" name="315" href="#315">315</a>     doStop();
+<a class="jxr_linenumber" name="316" href="#316">316</a>     <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">super</strong>.stopAndWait();
+<a class="jxr_linenumber" name="317" href="#317">317</a>   }
+<a class="jxr_linenumber" name="318" href="#318">318</a> 
+<a class="jxr_linenumber" name="319" href="#319">319</a>   @VisibleForTesting
+<a class="jxr_linenumber" name="320" href="#320">320</a>   <strong class="jxr_keyword">protected</strong> <a href="../../../../../../org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html">Replicator</a> createReplicator(List&lt;Entry&gt; entries, <strong class="jxr_keyword">int</strong> ordinal) {
+<a class="jxr_linenumber" name="321" href="#321">321</a>     <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html">Replicator</a>(entries, ordinal);
+<a class="jxr_linenumber" name="322" href="#322">322</a>   }
+<a class="jxr_linenumber" name="323" href="#323">323</a> 
+<a class="jxr_linenumber" name="324" href="#324">324</a>   @VisibleForTesting
+<a class="jxr_linenumber" name="325" href="#325">325</a>   <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../../../org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html">Replicator</a> <strong class="jxr_keyword">implements</strong> Callable&lt;Integer&gt; {
+<a class="jxr_linenumber" name="326" href="#326">326</a>     <strong class="jxr_keyword">private</strong> List&lt;Entry&gt; entries;
+<a class="jxr_linenumber" name="327" href="#327">327</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">int</strong> ordinal;
+<a class="jxr_linenumber" name="328" href="#328">328</a>     <strong class="jxr_keyword">public</strong> <a href="../../../../../../org/apache/hadoop/hbase/replication/regionserver/HBaseInterClusterReplicationEndpoint.html">Replicator</a>(List&lt;Entry&gt; entries, <strong class="jxr_keyword">int</strong> ordinal) {
+<a class="jxr_linenumber" name="329" href="#329">329</a>       <strong class="jxr_keyword">this</strong>.entries = entries;
+<a class="jxr_linenumber" name="330" href="#330">330</a>       <strong class="jxr_keyword">this</strong>.ordinal = ordinal;
+<a class="jxr_linenumber" name="331" href="#331">331</a>     }
+<a class="jxr_linenumber" name="332" href="#332">332</a> 
+<a class="jxr_linenumber" name="333" href="#333">333</a>     @Override
+<a class="jxr_linenumber" name="334" href="#334">334</a>     <strong class="jxr_keyword">public</strong> Integer call() <strong class="jxr_keyword">throws</strong> IOException {
+<a class="jxr_linenumber" name="335" href="#335">335</a>       <a href="../../../../../../org/apache/hadoop/hbase/replication/regionserver/ReplicationSinkManager.html">SinkPeer</a> sinkPeer = <strong class="jxr_keyword">null</strong>;
+<a class="jxr_linenumber" name="336" href="#336">336</a>       <strong class="jxr_keyword">try</strong> {
+<a class="jxr_linenumber" name="337" href="#337">337</a>         sinkPeer = replicationSinkMgr.getReplicationSink();
+<a class="jxr_linenumber" name="338" href="#338">338</a>         BlockingInterface rrs = sinkPeer.getRegionServer();
+<a class="jxr_linenumber" name="339" href="#339">339</a>         ReplicationProtbufUtil.replicateWALEntry(rrs, entries.toArray(<strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/hadoop/hbase/util/IdLock.html">Entry</a>[entries.size()]),
+<a class="jxr_linenumber" name="340" href="#340">340</a>           replicationClusterId, baseNamespaceDir, hfileArchiveDir);
+<a class="jxr_linenumber" name="341" href="#341">341</a>         replicationSinkMgr.reportSinkSuccess(sinkPeer);
+<a class="jxr_linenumber" name="342" href="#342">342</a>         <strong class="jxr_keyword">return</strong> ordinal;
+<a class="jxr_linenumber" name="343" href="#343">343</a> 
+<a class="jxr_linenumber" name="344" href="#344">344</a>       } <strong class="jxr_keyword">catch</strong> (IOException ioe) {
+<a class="jxr_linenumber" name="345" href="#345">345</a>         <strong class="jxr_keyword">if</strong> (sinkPeer != <strong class="jxr_keyword">null</strong>) {
+<a class="jxr_linenumber" name="346" href="#346">346</a>           replicationSinkMgr.reportBadSink(sinkPeer);
+<a class="jxr_linenumber" name="347" href="#347">347</a>         }
+<a class="jxr_linenumber" name="348" href="#348">348</a>         <strong class="jxr_keyword">throw</strong> ioe;
+<a class="jxr_linenumber" name="349" href="#349">349</a>       }
+<a class="jxr_linenumber" name="350" href="#350">350</a>     }
+<a class="jxr_linenumber" name="351" href="#351">351</a> 
+<a class="jxr_linenumber" name="352" href="#352">352</a>   }
+<a class="jxr_linenumber" name="353" href="#353">353</a> }
 </pre>
 <hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body>
 </html>


Mime
View raw message