hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [14/51] [partial] hbase-site git commit: Published site at d2ba87509b8d193f58183beff4ab76c7edf47e11.
Date Thu, 18 Feb 2016 17:20:31 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/f32f549a/devapidocs/src-html/org/apache/hadoop/hbase/wal/WALSplitter.RegionServerWriter.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/wal/WALSplitter.RegionServerWriter.html b/devapidocs/src-html/org/apache/hadoop/hbase/wal/WALSplitter.RegionServerWriter.html
index 0597160..b444f46 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/wal/WALSplitter.RegionServerWriter.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/wal/WALSplitter.RegionServerWriter.html
@@ -184,2145 +184,2183 @@
 <span class="sourceLineNo">176</span>  // Min batch size when replay WAL edits<a name="line.176"></a>
 <span class="sourceLineNo">177</span>  private final int minBatchSize;<a name="line.177"></a>
 <span class="sourceLineNo">178</span><a name="line.178"></a>
-<span class="sourceLineNo">179</span>  WALSplitter(final WALFactory factory, Configuration conf, Path rootDir,<a name="line.179"></a>
-<span class="sourceLineNo">180</span>      FileSystem fs, LastSequenceId idChecker,<a name="line.180"></a>
-<span class="sourceLineNo">181</span>      CoordinatedStateManager csm, RecoveryMode mode) {<a name="line.181"></a>
-<span class="sourceLineNo">182</span>    this.conf = HBaseConfiguration.create(conf);<a name="line.182"></a>
-<span class="sourceLineNo">183</span>    String codecClassName = conf<a name="line.183"></a>
-<span class="sourceLineNo">184</span>        .get(WALCellCodec.WAL_CELL_CODEC_CLASS_KEY, WALCellCodec.class.getName());<a name="line.184"></a>
-<span class="sourceLineNo">185</span>    this.conf.set(HConstants.RPC_CODEC_CONF_KEY, codecClassName);<a name="line.185"></a>
-<span class="sourceLineNo">186</span>    this.rootDir = rootDir;<a name="line.186"></a>
-<span class="sourceLineNo">187</span>    this.fs = fs;<a name="line.187"></a>
-<span class="sourceLineNo">188</span>    this.sequenceIdChecker = idChecker;<a name="line.188"></a>
-<span class="sourceLineNo">189</span>    this.csm = (BaseCoordinatedStateManager)csm;<a name="line.189"></a>
-<span class="sourceLineNo">190</span>    this.walFactory = factory;<a name="line.190"></a>
-<span class="sourceLineNo">191</span>    this.controller = new PipelineController();<a name="line.191"></a>
-<span class="sourceLineNo">192</span><a name="line.192"></a>
-<span class="sourceLineNo">193</span>    entryBuffers = new EntryBuffers(controller,<a name="line.193"></a>
-<span class="sourceLineNo">194</span>        this.conf.getInt("hbase.regionserver.hlog.splitlog.buffersize",<a name="line.194"></a>
-<span class="sourceLineNo">195</span>            128*1024*1024));<a name="line.195"></a>
+<span class="sourceLineNo">179</span>  // the file being split currently<a name="line.179"></a>
+<span class="sourceLineNo">180</span>  private FileStatus fileBeingSplit;<a name="line.180"></a>
+<span class="sourceLineNo">181</span><a name="line.181"></a>
+<span class="sourceLineNo">182</span>  @VisibleForTesting<a name="line.182"></a>
+<span class="sourceLineNo">183</span>  WALSplitter(final WALFactory factory, Configuration conf, Path rootDir,<a name="line.183"></a>
+<span class="sourceLineNo">184</span>      FileSystem fs, LastSequenceId idChecker,<a name="line.184"></a>
+<span class="sourceLineNo">185</span>      CoordinatedStateManager csm, RecoveryMode mode) {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>    this.conf = HBaseConfiguration.create(conf);<a name="line.186"></a>
+<span class="sourceLineNo">187</span>    String codecClassName = conf<a name="line.187"></a>
+<span class="sourceLineNo">188</span>        .get(WALCellCodec.WAL_CELL_CODEC_CLASS_KEY, WALCellCodec.class.getName());<a name="line.188"></a>
+<span class="sourceLineNo">189</span>    this.conf.set(HConstants.RPC_CODEC_CONF_KEY, codecClassName);<a name="line.189"></a>
+<span class="sourceLineNo">190</span>    this.rootDir = rootDir;<a name="line.190"></a>
+<span class="sourceLineNo">191</span>    this.fs = fs;<a name="line.191"></a>
+<span class="sourceLineNo">192</span>    this.sequenceIdChecker = idChecker;<a name="line.192"></a>
+<span class="sourceLineNo">193</span>    this.csm = (BaseCoordinatedStateManager)csm;<a name="line.193"></a>
+<span class="sourceLineNo">194</span>    this.walFactory = factory;<a name="line.194"></a>
+<span class="sourceLineNo">195</span>    this.controller = new PipelineController();<a name="line.195"></a>
 <span class="sourceLineNo">196</span><a name="line.196"></a>
-<span class="sourceLineNo">197</span>    // a larger minBatchSize may slow down recovery because replay writer has to wait for<a name="line.197"></a>
-<span class="sourceLineNo">198</span>    // enough edits before replaying them<a name="line.198"></a>
-<span class="sourceLineNo">199</span>    this.minBatchSize = this.conf.getInt("hbase.regionserver.wal.logreplay.batch.size", 64);<a name="line.199"></a>
-<span class="sourceLineNo">200</span>    this.distributedLogReplay = (RecoveryMode.LOG_REPLAY == mode);<a name="line.200"></a>
-<span class="sourceLineNo">201</span><a name="line.201"></a>
-<span class="sourceLineNo">202</span>    this.numWriterThreads = this.conf.getInt("hbase.regionserver.hlog.splitlog.writer.threads", 3);<a name="line.202"></a>
-<span class="sourceLineNo">203</span>    if (csm != null &amp;&amp; this.distributedLogReplay) {<a name="line.203"></a>
-<span class="sourceLineNo">204</span>      outputSink = new LogReplayOutputSink(controller, entryBuffers, numWriterThreads);<a name="line.204"></a>
-<span class="sourceLineNo">205</span>    } else {<a name="line.205"></a>
-<span class="sourceLineNo">206</span>      if (this.distributedLogReplay) {<a name="line.206"></a>
-<span class="sourceLineNo">207</span>        LOG.info("ZooKeeperWatcher is passed in as NULL so disable distrubitedLogRepaly.");<a name="line.207"></a>
-<span class="sourceLineNo">208</span>      }<a name="line.208"></a>
-<span class="sourceLineNo">209</span>      this.distributedLogReplay = false;<a name="line.209"></a>
-<span class="sourceLineNo">210</span>      outputSink = new LogRecoveredEditsOutputSink(controller, entryBuffers, numWriterThreads);<a name="line.210"></a>
-<span class="sourceLineNo">211</span>    }<a name="line.211"></a>
-<span class="sourceLineNo">212</span><a name="line.212"></a>
-<span class="sourceLineNo">213</span>  }<a name="line.213"></a>
-<span class="sourceLineNo">214</span><a name="line.214"></a>
-<span class="sourceLineNo">215</span>  /**<a name="line.215"></a>
-<span class="sourceLineNo">216</span>   * Splits a WAL file into region's recovered-edits directory.<a name="line.216"></a>
-<span class="sourceLineNo">217</span>   * This is the main entry point for distributed log splitting from SplitLogWorker.<a name="line.217"></a>
-<span class="sourceLineNo">218</span>   * &lt;p&gt;<a name="line.218"></a>
-<span class="sourceLineNo">219</span>   * If the log file has N regions then N recovered.edits files will be produced.<a name="line.219"></a>
-<span class="sourceLineNo">220</span>   * &lt;p&gt;<a name="line.220"></a>
-<span class="sourceLineNo">221</span>   * @param rootDir<a name="line.221"></a>
-<span class="sourceLineNo">222</span>   * @param logfile<a name="line.222"></a>
-<span class="sourceLineNo">223</span>   * @param fs<a name="line.223"></a>
-<span class="sourceLineNo">224</span>   * @param conf<a name="line.224"></a>
-<span class="sourceLineNo">225</span>   * @param reporter<a name="line.225"></a>
-<span class="sourceLineNo">226</span>   * @param idChecker<a name="line.226"></a>
-<span class="sourceLineNo">227</span>   * @param cp coordination state manager<a name="line.227"></a>
-<span class="sourceLineNo">228</span>   * @return false if it is interrupted by the progress-able.<a name="line.228"></a>
-<span class="sourceLineNo">229</span>   * @throws IOException<a name="line.229"></a>
-<span class="sourceLineNo">230</span>   */<a name="line.230"></a>
-<span class="sourceLineNo">231</span>  public static boolean splitLogFile(Path rootDir, FileStatus logfile, FileSystem fs,<a name="line.231"></a>
-<span class="sourceLineNo">232</span>      Configuration conf, CancelableProgressable reporter, LastSequenceId idChecker,<a name="line.232"></a>
-<span class="sourceLineNo">233</span>      CoordinatedStateManager cp, RecoveryMode mode, final WALFactory factory) throws IOException {<a name="line.233"></a>
-<span class="sourceLineNo">234</span>    WALSplitter s = new WALSplitter(factory, conf, rootDir, fs, idChecker, cp, mode);<a name="line.234"></a>
-<span class="sourceLineNo">235</span>    return s.splitLogFile(logfile, reporter);<a name="line.235"></a>
-<span class="sourceLineNo">236</span>  }<a name="line.236"></a>
-<span class="sourceLineNo">237</span><a name="line.237"></a>
-<span class="sourceLineNo">238</span>  // A wrapper to split one log folder using the method used by distributed<a name="line.238"></a>
-<span class="sourceLineNo">239</span>  // log splitting. Used by tools and unit tests. It should be package private.<a name="line.239"></a>
-<span class="sourceLineNo">240</span>  // It is public only because TestWALObserver is in a different package,<a name="line.240"></a>
-<span class="sourceLineNo">241</span>  // which uses this method to do log splitting.<a name="line.241"></a>
-<span class="sourceLineNo">242</span>  @VisibleForTesting<a name="line.242"></a>
-<span class="sourceLineNo">243</span>  public static List&lt;Path&gt; split(Path rootDir, Path logDir, Path oldLogDir,<a name="line.243"></a>
-<span class="sourceLineNo">244</span>      FileSystem fs, Configuration conf, final WALFactory factory) throws IOException {<a name="line.244"></a>
-<span class="sourceLineNo">245</span>    final FileStatus[] logfiles = SplitLogManager.getFileList(conf,<a name="line.245"></a>
-<span class="sourceLineNo">246</span>        Collections.singletonList(logDir), null);<a name="line.246"></a>
-<span class="sourceLineNo">247</span>    List&lt;Path&gt; splits = new ArrayList&lt;Path&gt;();<a name="line.247"></a>
-<span class="sourceLineNo">248</span>    if (logfiles != null &amp;&amp; logfiles.length &gt; 0) {<a name="line.248"></a>
-<span class="sourceLineNo">249</span>      for (FileStatus logfile: logfiles) {<a name="line.249"></a>
-<span class="sourceLineNo">250</span>        WALSplitter s = new WALSplitter(factory, conf, rootDir, fs, null, null,<a name="line.250"></a>
-<span class="sourceLineNo">251</span>            RecoveryMode.LOG_SPLITTING);<a name="line.251"></a>
-<span class="sourceLineNo">252</span>        if (s.splitLogFile(logfile, null)) {<a name="line.252"></a>
-<span class="sourceLineNo">253</span>          finishSplitLogFile(rootDir, oldLogDir, logfile.getPath(), conf);<a name="line.253"></a>
-<span class="sourceLineNo">254</span>          if (s.outputSink.splits != null) {<a name="line.254"></a>
-<span class="sourceLineNo">255</span>            splits.addAll(s.outputSink.splits);<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>      }<a name="line.258"></a>
-<span class="sourceLineNo">259</span>    }<a name="line.259"></a>
-<span class="sourceLineNo">260</span>    if (!fs.delete(logDir, true)) {<a name="line.260"></a>
-<span class="sourceLineNo">261</span>      throw new IOException("Unable to delete src dir: " + logDir);<a name="line.261"></a>
-<span class="sourceLineNo">262</span>    }<a name="line.262"></a>
-<span class="sourceLineNo">263</span>    return splits;<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>  /**<a name="line.266"></a>
-<span class="sourceLineNo">267</span>   * log splitting implementation, splits one log file.<a name="line.267"></a>
-<span class="sourceLineNo">268</span>   * @param logfile should be an actual log file.<a name="line.268"></a>
-<span class="sourceLineNo">269</span>   */<a name="line.269"></a>
-<span class="sourceLineNo">270</span>  boolean splitLogFile(FileStatus logfile, CancelableProgressable reporter) throws IOException {<a name="line.270"></a>
-<span class="sourceLineNo">271</span>    Preconditions.checkState(status == null);<a name="line.271"></a>
-<span class="sourceLineNo">272</span>    Preconditions.checkArgument(logfile.isFile(),<a name="line.272"></a>
-<span class="sourceLineNo">273</span>        "passed in file status is for something other than a regular file.");<a name="line.273"></a>
-<span class="sourceLineNo">274</span>    boolean isCorrupted = false;<a name="line.274"></a>
-<span class="sourceLineNo">275</span>    boolean skipErrors = conf.getBoolean("hbase.hlog.split.skip.errors",<a name="line.275"></a>
-<span class="sourceLineNo">276</span>      SPLIT_SKIP_ERRORS_DEFAULT);<a name="line.276"></a>
-<span class="sourceLineNo">277</span>    int interval = conf.getInt("hbase.splitlog.report.interval.loglines", 1024);<a name="line.277"></a>
-<span class="sourceLineNo">278</span>    Path logPath = logfile.getPath();<a name="line.278"></a>
-<span class="sourceLineNo">279</span>    boolean outputSinkStarted = false;<a name="line.279"></a>
-<span class="sourceLineNo">280</span>    boolean progress_failed = false;<a name="line.280"></a>
-<span class="sourceLineNo">281</span>    int editsCount = 0;<a name="line.281"></a>
-<span class="sourceLineNo">282</span>    int editsSkipped = 0;<a name="line.282"></a>
-<span class="sourceLineNo">283</span><a name="line.283"></a>
-<span class="sourceLineNo">284</span>    status =<a name="line.284"></a>
-<span class="sourceLineNo">285</span>        TaskMonitor.get().createStatus(<a name="line.285"></a>
-<span class="sourceLineNo">286</span>          "Splitting log file " + logfile.getPath() + "into a temporary staging area.");<a name="line.286"></a>
-<span class="sourceLineNo">287</span>    Reader in = null;<a name="line.287"></a>
-<span class="sourceLineNo">288</span>    try {<a name="line.288"></a>
-<span class="sourceLineNo">289</span>      long logLength = logfile.getLen();<a name="line.289"></a>
-<span class="sourceLineNo">290</span>      LOG.info("Splitting wal: " + logPath + ", length=" + logLength);<a name="line.290"></a>
-<span class="sourceLineNo">291</span>      LOG.info("DistributedLogReplay = " + this.distributedLogReplay);<a name="line.291"></a>
-<span class="sourceLineNo">292</span>      status.setStatus("Opening log file");<a name="line.292"></a>
-<span class="sourceLineNo">293</span>      if (reporter != null &amp;&amp; !reporter.progress()) {<a name="line.293"></a>
-<span class="sourceLineNo">294</span>        progress_failed = true;<a name="line.294"></a>
-<span class="sourceLineNo">295</span>        return false;<a name="line.295"></a>
-<span class="sourceLineNo">296</span>      }<a name="line.296"></a>
-<span class="sourceLineNo">297</span>      try {<a name="line.297"></a>
-<span class="sourceLineNo">298</span>        in = getReader(logfile, skipErrors, reporter);<a name="line.298"></a>
-<span class="sourceLineNo">299</span>      } catch (CorruptedLogFileException e) {<a name="line.299"></a>
-<span class="sourceLineNo">300</span>        LOG.warn("Could not get reader, corrupted log file " + logPath, e);<a name="line.300"></a>
-<span class="sourceLineNo">301</span>        ZKSplitLog.markCorrupted(rootDir, logfile.getPath().getName(), fs);<a name="line.301"></a>
-<span class="sourceLineNo">302</span>        isCorrupted = true;<a name="line.302"></a>
-<span class="sourceLineNo">303</span>      }<a name="line.303"></a>
-<span class="sourceLineNo">304</span>      if (in == null) {<a name="line.304"></a>
-<span class="sourceLineNo">305</span>        LOG.warn("Nothing to split in log file " + logPath);<a name="line.305"></a>
-<span class="sourceLineNo">306</span>        return true;<a name="line.306"></a>
-<span class="sourceLineNo">307</span>      }<a name="line.307"></a>
-<span class="sourceLineNo">308</span>      int numOpenedFilesBeforeReporting = conf.getInt("hbase.splitlog.report.openedfiles", 3);<a name="line.308"></a>
-<span class="sourceLineNo">309</span>      int numOpenedFilesLastCheck = 0;<a name="line.309"></a>
-<span class="sourceLineNo">310</span>      outputSink.setReporter(reporter);<a name="line.310"></a>
-<span class="sourceLineNo">311</span>      outputSink.startWriterThreads();<a name="line.311"></a>
-<span class="sourceLineNo">312</span>      outputSinkStarted = true;<a name="line.312"></a>
-<span class="sourceLineNo">313</span>      Entry entry;<a name="line.313"></a>
-<span class="sourceLineNo">314</span>      Long lastFlushedSequenceId = -1L;<a name="line.314"></a>
-<span class="sourceLineNo">315</span>      ServerName serverName = DefaultWALProvider.getServerNameFromWALDirectoryName(logPath);<a name="line.315"></a>
-<span class="sourceLineNo">316</span>      failedServerName = (serverName == null) ? "" : serverName.getServerName();<a name="line.316"></a>
-<span class="sourceLineNo">317</span>      while ((entry = getNextLogLine(in, logPath, skipErrors)) != null) {<a name="line.317"></a>
-<span class="sourceLineNo">318</span>        byte[] region = entry.getKey().getEncodedRegionName();<a name="line.318"></a>
-<span class="sourceLineNo">319</span>        String encodedRegionNameAsStr = Bytes.toString(region);<a name="line.319"></a>
-<span class="sourceLineNo">320</span>        lastFlushedSequenceId = lastFlushedSequenceIds.get(encodedRegionNameAsStr);<a name="line.320"></a>
-<span class="sourceLineNo">321</span>        if (lastFlushedSequenceId == null) {<a name="line.321"></a>
-<span class="sourceLineNo">322</span>          if (this.distributedLogReplay) {<a name="line.322"></a>
-<span class="sourceLineNo">323</span>            RegionStoreSequenceIds ids =<a name="line.323"></a>
-<span class="sourceLineNo">324</span>                csm.getSplitLogWorkerCoordination().getRegionFlushedSequenceId(failedServerName,<a name="line.324"></a>
-<span class="sourceLineNo">325</span>                  encodedRegionNameAsStr);<a name="line.325"></a>
-<span class="sourceLineNo">326</span>            if (ids != null) {<a name="line.326"></a>
-<span class="sourceLineNo">327</span>              lastFlushedSequenceId = ids.getLastFlushedSequenceId();<a name="line.327"></a>
-<span class="sourceLineNo">328</span>              if (LOG.isDebugEnabled()) {<a name="line.328"></a>
-<span class="sourceLineNo">329</span>                LOG.debug("DLR Last flushed sequenceid for " + encodedRegionNameAsStr + ": " +<a name="line.329"></a>
-<span class="sourceLineNo">330</span>                  TextFormat.shortDebugString(ids));<a name="line.330"></a>
-<span class="sourceLineNo">331</span>              }<a name="line.331"></a>
-<span class="sourceLineNo">332</span>            }<a name="line.332"></a>
-<span class="sourceLineNo">333</span>          } else if (sequenceIdChecker != null) {<a name="line.333"></a>
-<span class="sourceLineNo">334</span>            RegionStoreSequenceIds ids = sequenceIdChecker.getLastSequenceId(region);<a name="line.334"></a>
-<span class="sourceLineNo">335</span>            Map&lt;byte[], Long&gt; maxSeqIdInStores = new TreeMap&lt;byte[], Long&gt;(Bytes.BYTES_COMPARATOR);<a name="line.335"></a>
-<span class="sourceLineNo">336</span>            for (StoreSequenceId storeSeqId : ids.getStoreSequenceIdList()) {<a name="line.336"></a>
-<span class="sourceLineNo">337</span>              maxSeqIdInStores.put(storeSeqId.getFamilyName().toByteArray(),<a name="line.337"></a>
-<span class="sourceLineNo">338</span>                storeSeqId.getSequenceId());<a name="line.338"></a>
-<span class="sourceLineNo">339</span>            }<a name="line.339"></a>
-<span class="sourceLineNo">340</span>            regionMaxSeqIdInStores.put(encodedRegionNameAsStr, maxSeqIdInStores);<a name="line.340"></a>
-<span class="sourceLineNo">341</span>            lastFlushedSequenceId = ids.getLastFlushedSequenceId();<a name="line.341"></a>
-<span class="sourceLineNo">342</span>            if (LOG.isDebugEnabled()) {<a name="line.342"></a>
-<span class="sourceLineNo">343</span>              LOG.debug("DLS Last flushed sequenceid for " + encodedRegionNameAsStr + ": " +<a name="line.343"></a>
-<span class="sourceLineNo">344</span>                  TextFormat.shortDebugString(ids));<a name="line.344"></a>
+<span class="sourceLineNo">197</span>    entryBuffers = new EntryBuffers(controller,<a name="line.197"></a>
+<span class="sourceLineNo">198</span>        this.conf.getInt("hbase.regionserver.hlog.splitlog.buffersize",<a name="line.198"></a>
+<span class="sourceLineNo">199</span>            128*1024*1024));<a name="line.199"></a>
+<span class="sourceLineNo">200</span><a name="line.200"></a>
+<span class="sourceLineNo">201</span>    // a larger minBatchSize may slow down recovery because replay writer has to wait for<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    // enough edits before replaying them<a name="line.202"></a>
+<span class="sourceLineNo">203</span>    this.minBatchSize = this.conf.getInt("hbase.regionserver.wal.logreplay.batch.size", 64);<a name="line.203"></a>
+<span class="sourceLineNo">204</span>    this.distributedLogReplay = (RecoveryMode.LOG_REPLAY == mode);<a name="line.204"></a>
+<span class="sourceLineNo">205</span><a name="line.205"></a>
+<span class="sourceLineNo">206</span>    this.numWriterThreads = this.conf.getInt("hbase.regionserver.hlog.splitlog.writer.threads", 3);<a name="line.206"></a>
+<span class="sourceLineNo">207</span>    if (csm != null &amp;&amp; this.distributedLogReplay) {<a name="line.207"></a>
+<span class="sourceLineNo">208</span>      outputSink = new LogReplayOutputSink(controller, entryBuffers, numWriterThreads);<a name="line.208"></a>
+<span class="sourceLineNo">209</span>    } else {<a name="line.209"></a>
+<span class="sourceLineNo">210</span>      if (this.distributedLogReplay) {<a name="line.210"></a>
+<span class="sourceLineNo">211</span>        LOG.info("ZooKeeperWatcher is passed in as NULL so disable distrubitedLogRepaly.");<a name="line.211"></a>
+<span class="sourceLineNo">212</span>      }<a name="line.212"></a>
+<span class="sourceLineNo">213</span>      this.distributedLogReplay = false;<a name="line.213"></a>
+<span class="sourceLineNo">214</span>      outputSink = new LogRecoveredEditsOutputSink(controller, entryBuffers, numWriterThreads);<a name="line.214"></a>
+<span class="sourceLineNo">215</span>    }<a name="line.215"></a>
+<span class="sourceLineNo">216</span><a name="line.216"></a>
+<span class="sourceLineNo">217</span>  }<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>   * Splits a WAL file into region's recovered-edits directory.<a name="line.220"></a>
+<span class="sourceLineNo">221</span>   * This is the main entry point for distributed log splitting from SplitLogWorker.<a name="line.221"></a>
+<span class="sourceLineNo">222</span>   * &lt;p&gt;<a name="line.222"></a>
+<span class="sourceLineNo">223</span>   * If the log file has N regions then N recovered.edits files will be produced.<a name="line.223"></a>
+<span class="sourceLineNo">224</span>   * &lt;p&gt;<a name="line.224"></a>
+<span class="sourceLineNo">225</span>   * @param rootDir<a name="line.225"></a>
+<span class="sourceLineNo">226</span>   * @param logfile<a name="line.226"></a>
+<span class="sourceLineNo">227</span>   * @param fs<a name="line.227"></a>
+<span class="sourceLineNo">228</span>   * @param conf<a name="line.228"></a>
+<span class="sourceLineNo">229</span>   * @param reporter<a name="line.229"></a>
+<span class="sourceLineNo">230</span>   * @param idChecker<a name="line.230"></a>
+<span class="sourceLineNo">231</span>   * @param cp coordination state manager<a name="line.231"></a>
+<span class="sourceLineNo">232</span>   * @return false if it is interrupted by the progress-able.<a name="line.232"></a>
+<span class="sourceLineNo">233</span>   * @throws IOException<a name="line.233"></a>
+<span class="sourceLineNo">234</span>   */<a name="line.234"></a>
+<span class="sourceLineNo">235</span>  public static boolean splitLogFile(Path rootDir, FileStatus logfile, FileSystem fs,<a name="line.235"></a>
+<span class="sourceLineNo">236</span>      Configuration conf, CancelableProgressable reporter, LastSequenceId idChecker,<a name="line.236"></a>
+<span class="sourceLineNo">237</span>      CoordinatedStateManager cp, RecoveryMode mode, final WALFactory factory) throws IOException {<a name="line.237"></a>
+<span class="sourceLineNo">238</span>    WALSplitter s = new WALSplitter(factory, conf, rootDir, fs, idChecker, cp, mode);<a name="line.238"></a>
+<span class="sourceLineNo">239</span>    return s.splitLogFile(logfile, reporter);<a name="line.239"></a>
+<span class="sourceLineNo">240</span>  }<a name="line.240"></a>
+<span class="sourceLineNo">241</span><a name="line.241"></a>
+<span class="sourceLineNo">242</span>  // A wrapper to split one log folder using the method used by distributed<a name="line.242"></a>
+<span class="sourceLineNo">243</span>  // log splitting. Used by tools and unit tests. It should be package private.<a name="line.243"></a>
+<span class="sourceLineNo">244</span>  // It is public only because TestWALObserver is in a different package,<a name="line.244"></a>
+<span class="sourceLineNo">245</span>  // which uses this method to do log splitting.<a name="line.245"></a>
+<span class="sourceLineNo">246</span>  @VisibleForTesting<a name="line.246"></a>
+<span class="sourceLineNo">247</span>  public static List&lt;Path&gt; split(Path rootDir, Path logDir, Path oldLogDir,<a name="line.247"></a>
+<span class="sourceLineNo">248</span>      FileSystem fs, Configuration conf, final WALFactory factory) throws IOException {<a name="line.248"></a>
+<span class="sourceLineNo">249</span>    final FileStatus[] logfiles = SplitLogManager.getFileList(conf,<a name="line.249"></a>
+<span class="sourceLineNo">250</span>        Collections.singletonList(logDir), null);<a name="line.250"></a>
+<span class="sourceLineNo">251</span>    List&lt;Path&gt; splits = new ArrayList&lt;Path&gt;();<a name="line.251"></a>
+<span class="sourceLineNo">252</span>    if (logfiles != null &amp;&amp; logfiles.length &gt; 0) {<a name="line.252"></a>
+<span class="sourceLineNo">253</span>      for (FileStatus logfile: logfiles) {<a name="line.253"></a>
+<span class="sourceLineNo">254</span>        WALSplitter s = new WALSplitter(factory, conf, rootDir, fs, null, null,<a name="line.254"></a>
+<span class="sourceLineNo">255</span>            RecoveryMode.LOG_SPLITTING);<a name="line.255"></a>
+<span class="sourceLineNo">256</span>        if (s.splitLogFile(logfile, null)) {<a name="line.256"></a>
+<span class="sourceLineNo">257</span>          finishSplitLogFile(rootDir, oldLogDir, logfile.getPath(), conf);<a name="line.257"></a>
+<span class="sourceLineNo">258</span>          if (s.outputSink.splits != null) {<a name="line.258"></a>
+<span class="sourceLineNo">259</span>            splits.addAll(s.outputSink.splits);<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>      }<a name="line.262"></a>
+<span class="sourceLineNo">263</span>    }<a name="line.263"></a>
+<span class="sourceLineNo">264</span>    if (!fs.delete(logDir, true)) {<a name="line.264"></a>
+<span class="sourceLineNo">265</span>      throw new IOException("Unable to delete src dir: " + logDir);<a name="line.265"></a>
+<span class="sourceLineNo">266</span>    }<a name="line.266"></a>
+<span class="sourceLineNo">267</span>    return splits;<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>  /**<a name="line.270"></a>
+<span class="sourceLineNo">271</span>   * log splitting implementation, splits one log file.<a name="line.271"></a>
+<span class="sourceLineNo">272</span>   * @param logfile should be an actual log file.<a name="line.272"></a>
+<span class="sourceLineNo">273</span>   */<a name="line.273"></a>
+<span class="sourceLineNo">274</span>  @VisibleForTesting<a name="line.274"></a>
+<span class="sourceLineNo">275</span>  boolean splitLogFile(FileStatus logfile, CancelableProgressable reporter) throws IOException {<a name="line.275"></a>
+<span class="sourceLineNo">276</span>    Preconditions.checkState(status == null);<a name="line.276"></a>
+<span class="sourceLineNo">277</span>    Preconditions.checkArgument(logfile.isFile(),<a name="line.277"></a>
+<span class="sourceLineNo">278</span>        "passed in file status is for something other than a regular file.");<a name="line.278"></a>
+<span class="sourceLineNo">279</span>    boolean isCorrupted = false;<a name="line.279"></a>
+<span class="sourceLineNo">280</span>    boolean skipErrors = conf.getBoolean("hbase.hlog.split.skip.errors",<a name="line.280"></a>
+<span class="sourceLineNo">281</span>      SPLIT_SKIP_ERRORS_DEFAULT);<a name="line.281"></a>
+<span class="sourceLineNo">282</span>    int interval = conf.getInt("hbase.splitlog.report.interval.loglines", 1024);<a name="line.282"></a>
+<span class="sourceLineNo">283</span>    Path logPath = logfile.getPath();<a name="line.283"></a>
+<span class="sourceLineNo">284</span>    boolean outputSinkStarted = false;<a name="line.284"></a>
+<span class="sourceLineNo">285</span>    boolean progress_failed = false;<a name="line.285"></a>
+<span class="sourceLineNo">286</span>    int editsCount = 0;<a name="line.286"></a>
+<span class="sourceLineNo">287</span>    int editsSkipped = 0;<a name="line.287"></a>
+<span class="sourceLineNo">288</span><a name="line.288"></a>
+<span class="sourceLineNo">289</span>    status =<a name="line.289"></a>
+<span class="sourceLineNo">290</span>        TaskMonitor.get().createStatus(<a name="line.290"></a>
+<span class="sourceLineNo">291</span>          "Splitting log file " + logfile.getPath() + "into a temporary staging area.");<a name="line.291"></a>
+<span class="sourceLineNo">292</span>    Reader in = null;<a name="line.292"></a>
+<span class="sourceLineNo">293</span>    this.fileBeingSplit = logfile;<a name="line.293"></a>
+<span class="sourceLineNo">294</span>    try {<a name="line.294"></a>
+<span class="sourceLineNo">295</span>      long logLength = logfile.getLen();<a name="line.295"></a>
+<span class="sourceLineNo">296</span>      LOG.info("Splitting wal: " + logPath + ", length=" + logLength);<a name="line.296"></a>
+<span class="sourceLineNo">297</span>      LOG.info("DistributedLogReplay = " + this.distributedLogReplay);<a name="line.297"></a>
+<span class="sourceLineNo">298</span>      status.setStatus("Opening log file");<a name="line.298"></a>
+<span class="sourceLineNo">299</span>      if (reporter != null &amp;&amp; !reporter.progress()) {<a name="line.299"></a>
+<span class="sourceLineNo">300</span>        progress_failed = true;<a name="line.300"></a>
+<span class="sourceLineNo">301</span>        return false;<a name="line.301"></a>
+<span class="sourceLineNo">302</span>      }<a name="line.302"></a>
+<span class="sourceLineNo">303</span>      try {<a name="line.303"></a>
+<span class="sourceLineNo">304</span>        in = getReader(logfile, skipErrors, reporter);<a name="line.304"></a>
+<span class="sourceLineNo">305</span>      } catch (CorruptedLogFileException e) {<a name="line.305"></a>
+<span class="sourceLineNo">306</span>        LOG.warn("Could not get reader, corrupted log file " + logPath, e);<a name="line.306"></a>
+<span class="sourceLineNo">307</span>        ZKSplitLog.markCorrupted(rootDir, logfile.getPath().getName(), fs);<a name="line.307"></a>
+<span class="sourceLineNo">308</span>        isCorrupted = true;<a name="line.308"></a>
+<span class="sourceLineNo">309</span>      }<a name="line.309"></a>
+<span class="sourceLineNo">310</span>      if (in == null) {<a name="line.310"></a>
+<span class="sourceLineNo">311</span>        LOG.warn("Nothing to split in log file " + logPath);<a name="line.311"></a>
+<span class="sourceLineNo">312</span>        return true;<a name="line.312"></a>
+<span class="sourceLineNo">313</span>      }<a name="line.313"></a>
+<span class="sourceLineNo">314</span>      int numOpenedFilesBeforeReporting = conf.getInt("hbase.splitlog.report.openedfiles", 3);<a name="line.314"></a>
+<span class="sourceLineNo">315</span>      int numOpenedFilesLastCheck = 0;<a name="line.315"></a>
+<span class="sourceLineNo">316</span>      outputSink.setReporter(reporter);<a name="line.316"></a>
+<span class="sourceLineNo">317</span>      outputSink.startWriterThreads();<a name="line.317"></a>
+<span class="sourceLineNo">318</span>      outputSinkStarted = true;<a name="line.318"></a>
+<span class="sourceLineNo">319</span>      Entry entry;<a name="line.319"></a>
+<span class="sourceLineNo">320</span>      Long lastFlushedSequenceId = -1L;<a name="line.320"></a>
+<span class="sourceLineNo">321</span>      ServerName serverName = DefaultWALProvider.getServerNameFromWALDirectoryName(logPath);<a name="line.321"></a>
+<span class="sourceLineNo">322</span>      failedServerName = (serverName == null) ? "" : serverName.getServerName();<a name="line.322"></a>
+<span class="sourceLineNo">323</span>      while ((entry = getNextLogLine(in, logPath, skipErrors)) != null) {<a name="line.323"></a>
+<span class="sourceLineNo">324</span>        byte[] region = entry.getKey().getEncodedRegionName();<a name="line.324"></a>
+<span class="sourceLineNo">325</span>        String encodedRegionNameAsStr = Bytes.toString(region);<a name="line.325"></a>
+<span class="sourceLineNo">326</span>        lastFlushedSequenceId = lastFlushedSequenceIds.get(encodedRegionNameAsStr);<a name="line.326"></a>
+<span class="sourceLineNo">327</span>        if (lastFlushedSequenceId == null) {<a name="line.327"></a>
+<span class="sourceLineNo">328</span>          if (this.distributedLogReplay) {<a name="line.328"></a>
+<span class="sourceLineNo">329</span>            RegionStoreSequenceIds ids =<a name="line.329"></a>
+<span class="sourceLineNo">330</span>                csm.getSplitLogWorkerCoordination().getRegionFlushedSequenceId(failedServerName,<a name="line.330"></a>
+<span class="sourceLineNo">331</span>                  encodedRegionNameAsStr);<a name="line.331"></a>
+<span class="sourceLineNo">332</span>            if (ids != null) {<a name="line.332"></a>
+<span class="sourceLineNo">333</span>              lastFlushedSequenceId = ids.getLastFlushedSequenceId();<a name="line.333"></a>
+<span class="sourceLineNo">334</span>              if (LOG.isDebugEnabled()) {<a name="line.334"></a>
+<span class="sourceLineNo">335</span>                LOG.debug("DLR Last flushed sequenceid for " + encodedRegionNameAsStr + ": " +<a name="line.335"></a>
+<span class="sourceLineNo">336</span>                  TextFormat.shortDebugString(ids));<a name="line.336"></a>
+<span class="sourceLineNo">337</span>              }<a name="line.337"></a>
+<span class="sourceLineNo">338</span>            }<a name="line.338"></a>
+<span class="sourceLineNo">339</span>          } else if (sequenceIdChecker != null) {<a name="line.339"></a>
+<span class="sourceLineNo">340</span>            RegionStoreSequenceIds ids = sequenceIdChecker.getLastSequenceId(region);<a name="line.340"></a>
+<span class="sourceLineNo">341</span>            Map&lt;byte[], Long&gt; maxSeqIdInStores = new TreeMap&lt;byte[], Long&gt;(Bytes.BYTES_COMPARATOR);<a name="line.341"></a>
+<span class="sourceLineNo">342</span>            for (StoreSequenceId storeSeqId : ids.getStoreSequenceIdList()) {<a name="line.342"></a>
+<span class="sourceLineNo">343</span>              maxSeqIdInStores.put(storeSeqId.getFamilyName().toByteArray(),<a name="line.343"></a>
+<span class="sourceLineNo">344</span>                storeSeqId.getSequenceId());<a name="line.344"></a>
 <span class="sourceLineNo">345</span>            }<a name="line.345"></a>
-<span class="sourceLineNo">346</span>          }<a name="line.346"></a>
-<span class="sourceLineNo">347</span>          if (lastFlushedSequenceId == null) {<a name="line.347"></a>
-<span class="sourceLineNo">348</span>            lastFlushedSequenceId = -1L;<a name="line.348"></a>
-<span class="sourceLineNo">349</span>          }<a name="line.349"></a>
-<span class="sourceLineNo">350</span>          lastFlushedSequenceIds.put(encodedRegionNameAsStr, lastFlushedSequenceId);<a name="line.350"></a>
-<span class="sourceLineNo">351</span>        }<a name="line.351"></a>
-<span class="sourceLineNo">352</span>        if (lastFlushedSequenceId &gt;= entry.getKey().getLogSeqNum()) {<a name="line.352"></a>
-<span class="sourceLineNo">353</span>          editsSkipped++;<a name="line.353"></a>
-<span class="sourceLineNo">354</span>          continue;<a name="line.354"></a>
-<span class="sourceLineNo">355</span>        }<a name="line.355"></a>
-<span class="sourceLineNo">356</span>        entryBuffers.appendEntry(entry);<a name="line.356"></a>
-<span class="sourceLineNo">357</span>        editsCount++;<a name="line.357"></a>
-<span class="sourceLineNo">358</span>        int moreWritersFromLastCheck = this.getNumOpenWriters() - numOpenedFilesLastCheck;<a name="line.358"></a>
-<span class="sourceLineNo">359</span>        // If sufficient edits have passed, check if we should report progress.<a name="line.359"></a>
-<span class="sourceLineNo">360</span>        if (editsCount % interval == 0<a name="line.360"></a>
-<span class="sourceLineNo">361</span>            || moreWritersFromLastCheck &gt; numOpenedFilesBeforeReporting) {<a name="line.361"></a>
-<span class="sourceLineNo">362</span>          numOpenedFilesLastCheck = this.getNumOpenWriters();<a name="line.362"></a>
-<span class="sourceLineNo">363</span>          String countsStr = (editsCount - (editsSkipped + outputSink.getSkippedEdits()))<a name="line.363"></a>
-<span class="sourceLineNo">364</span>              + " edits, skipped " + editsSkipped + " edits.";<a name="line.364"></a>
-<span class="sourceLineNo">365</span>          status.setStatus("Split " + countsStr);<a name="line.365"></a>
-<span class="sourceLineNo">366</span>          if (reporter != null &amp;&amp; !reporter.progress()) {<a name="line.366"></a>
-<span class="sourceLineNo">367</span>            progress_failed = true;<a name="line.367"></a>
-<span class="sourceLineNo">368</span>            return false;<a name="line.368"></a>
-<span class="sourceLineNo">369</span>          }<a name="line.369"></a>
-<span class="sourceLineNo">370</span>        }<a name="line.370"></a>
-<span class="sourceLineNo">371</span>      }<a name="line.371"></a>
-<span class="sourceLineNo">372</span>    } catch (InterruptedException ie) {<a name="line.372"></a>
-<span class="sourceLineNo">373</span>      IOException iie = new InterruptedIOException();<a name="line.373"></a>
-<span class="sourceLineNo">374</span>      iie.initCause(ie);<a name="line.374"></a>
-<span class="sourceLineNo">375</span>      throw iie;<a name="line.375"></a>
-<span class="sourceLineNo">376</span>    } catch (CorruptedLogFileException e) {<a name="line.376"></a>
-<span class="sourceLineNo">377</span>      LOG.warn("Could not parse, corrupted log file " + logPath, e);<a name="line.377"></a>
-<span class="sourceLineNo">378</span>      csm.getSplitLogWorkerCoordination().markCorrupted(rootDir,<a name="line.378"></a>
-<span class="sourceLineNo">379</span>        logfile.getPath().getName(), fs);<a name="line.379"></a>
-<span class="sourceLineNo">380</span>      isCorrupted = true;<a name="line.380"></a>
-<span class="sourceLineNo">381</span>    } catch (IOException e) {<a name="line.381"></a>
-<span class="sourceLineNo">382</span>      e = e instanceof RemoteException ? ((RemoteException) e).unwrapRemoteException() : e;<a name="line.382"></a>
-<span class="sourceLineNo">383</span>      throw e;<a name="line.383"></a>
-<span class="sourceLineNo">384</span>    } finally {<a name="line.384"></a>
-<span class="sourceLineNo">385</span>      LOG.debug("Finishing writing output logs and closing down.");<a name="line.385"></a>
-<span class="sourceLineNo">386</span>      try {<a name="line.386"></a>
-<span class="sourceLineNo">387</span>        if (null != in) {<a name="line.387"></a>
-<span class="sourceLineNo">388</span>          in.close();<a name="line.388"></a>
-<span class="sourceLineNo">389</span>        }<a name="line.389"></a>
-<span class="sourceLineNo">390</span>      } catch (IOException exception) {<a name="line.390"></a>
-<span class="sourceLineNo">391</span>        LOG.warn("Could not close wal reader: " + exception.getMessage());<a name="line.391"></a>
-<span class="sourceLineNo">392</span>        LOG.debug("exception details", exception);<a name="line.392"></a>
-<span class="sourceLineNo">393</span>      }<a name="line.393"></a>
-<span class="sourceLineNo">394</span>      try {<a name="line.394"></a>
-<span class="sourceLineNo">395</span>        if (outputSinkStarted) {<a name="line.395"></a>
-<span class="sourceLineNo">396</span>          // Set progress_failed to true as the immediate following statement will reset its value<a name="line.396"></a>
-<span class="sourceLineNo">397</span>          // when finishWritingAndClose() throws exception, progress_failed has the right value<a name="line.397"></a>
-<span class="sourceLineNo">398</span>          progress_failed = true;<a name="line.398"></a>
-<span class="sourceLineNo">399</span>          progress_failed = outputSink.finishWritingAndClose() == null;<a name="line.399"></a>
-<span class="sourceLineNo">400</span>        }<a name="line.400"></a>
-<span class="sourceLineNo">401</span>      } finally {<a name="line.401"></a>
-<span class="sourceLineNo">402</span>        String msg =<a name="line.402"></a>
-<span class="sourceLineNo">403</span>            "Processed " + editsCount + " edits across " + outputSink.getNumberOfRecoveredRegions()<a name="line.403"></a>
-<span class="sourceLineNo">404</span>                + " regions; edits skipped=" + editsSkipped + "; log file=" + logPath +<a name="line.404"></a>
-<span class="sourceLineNo">405</span>                ", length=" + logfile.getLen() + // See if length got updated post lease recovery<a name="line.405"></a>
-<span class="sourceLineNo">406</span>                ", corrupted=" + isCorrupted + ", progress failed=" + progress_failed;<a name="line.406"></a>
-<span class="sourceLineNo">407</span>        LOG.info(msg);<a name="line.407"></a>
-<span class="sourceLineNo">408</span>        status.markComplete(msg);<a name="line.408"></a>
-<span class="sourceLineNo">409</span>      }<a name="line.409"></a>
-<span class="sourceLineNo">410</span>    }<a name="line.410"></a>
-<span class="sourceLineNo">411</span>    return !progress_failed;<a name="line.411"></a>
-<span class="sourceLineNo">412</span>  }<a name="line.412"></a>
-<span class="sourceLineNo">413</span><a name="line.413"></a>
-<span class="sourceLineNo">414</span>  /**<a name="line.414"></a>
-<span class="sourceLineNo">415</span>   * Completes the work done by splitLogFile by archiving logs<a name="line.415"></a>
-<span class="sourceLineNo">416</span>   * &lt;p&gt;<a name="line.416"></a>
-<span class="sourceLineNo">417</span>   * It is invoked by SplitLogManager once it knows that one of the<a name="line.417"></a>
-<span class="sourceLineNo">418</span>   * SplitLogWorkers have completed the splitLogFile() part. If the master<a name="line.418"></a>
-<span class="sourceLineNo">419</span>   * crashes then this function might get called multiple times.<a name="line.419"></a>
-<span class="sourceLineNo">420</span>   * &lt;p&gt;<a name="line.420"></a>
-<span class="sourceLineNo">421</span>   * @param logfile<a name="line.421"></a>
-<span class="sourceLineNo">422</span>   * @param conf<a name="line.422"></a>
-<span class="sourceLineNo">423</span>   * @throws IOException<a name="line.423"></a>
-<span class="sourceLineNo">424</span>   */<a name="line.424"></a>
-<span class="sourceLineNo">425</span>  public static void finishSplitLogFile(String logfile,<a name="line.425"></a>
-<span class="sourceLineNo">426</span>      Configuration conf)  throws IOException {<a name="line.426"></a>
-<span class="sourceLineNo">427</span>    Path rootdir = FSUtils.getRootDir(conf);<a name="line.427"></a>
-<span class="sourceLineNo">428</span>    Path oldLogDir = new Path(rootdir, HConstants.HREGION_OLDLOGDIR_NAME);<a name="line.428"></a>
-<span class="sourceLineNo">429</span>    Path logPath;<a name="line.429"></a>
-<span class="sourceLineNo">430</span>    if (FSUtils.isStartingWithPath(rootdir, logfile)) {<a name="line.430"></a>
-<span class="sourceLineNo">431</span>      logPath = new Path(logfile);<a name="line.431"></a>
-<span class="sourceLineNo">432</span>    } else {<a name="line.432"></a>
-<span class="sourceLineNo">433</span>      logPath = new Path(rootdir, logfile);<a name="line.433"></a>
-<span class="sourceLineNo">434</span>    }<a name="line.434"></a>
-<span class="sourceLineNo">435</span>    finishSplitLogFile(rootdir, oldLogDir, logPath, conf);<a name="line.435"></a>
-<span class="sourceLineNo">436</span>  }<a name="line.436"></a>
-<span class="sourceLineNo">437</span><a name="line.437"></a>
-<span class="sourceLineNo">438</span>  static void finishSplitLogFile(Path rootdir, Path oldLogDir,<a name="line.438"></a>
-<span class="sourceLineNo">439</span>      Path logPath, Configuration conf) throws IOException {<a name="line.439"></a>
-<span class="sourceLineNo">440</span>    List&lt;Path&gt; processedLogs = new ArrayList&lt;Path&gt;();<a name="line.440"></a>
-<span class="sourceLineNo">441</span>    List&lt;Path&gt; corruptedLogs = new ArrayList&lt;Path&gt;();<a name="line.441"></a>
-<span class="sourceLineNo">442</span>    FileSystem fs;<a name="line.442"></a>
-<span class="sourceLineNo">443</span>    fs = rootdir.getFileSystem(conf);<a name="line.443"></a>
-<span class="sourceLineNo">444</span>    if (ZKSplitLog.isCorrupted(rootdir, logPath.getName(), fs)) {<a name="line.444"></a>
-<span class="sourceLineNo">445</span>      corruptedLogs.add(logPath);<a name="line.445"></a>
-<span class="sourceLineNo">446</span>    } else {<a name="line.446"></a>
-<span class="sourceLineNo">447</span>      processedLogs.add(logPath);<a name="line.447"></a>
-<span class="sourceLineNo">448</span>    }<a name="line.448"></a>
-<span class="sourceLineNo">449</span>    archiveLogs(corruptedLogs, processedLogs, oldLogDir, fs, conf);<a name="line.449"></a>
-<span class="sourceLineNo">450</span>    Path stagingDir = ZKSplitLog.getSplitLogDir(rootdir, logPath.getName());<a name="line.450"></a>
-<span class="sourceLineNo">451</span>    fs.delete(stagingDir, true);<a name="line.451"></a>
-<span class="sourceLineNo">452</span>  }<a name="line.452"></a>
-<span class="sourceLineNo">453</span><a name="line.453"></a>
-<span class="sourceLineNo">454</span>  /**<a name="line.454"></a>
-<span class="sourceLineNo">455</span>   * Moves processed logs to a oldLogDir after successful processing Moves<a name="line.455"></a>
-<span class="sourceLineNo">456</span>   * corrupted logs (any log that couldn't be successfully parsed to corruptDir<a name="line.456"></a>
-<span class="sourceLineNo">457</span>   * (.corrupt) for later investigation<a name="line.457"></a>
-<span class="sourceLineNo">458</span>   *<a name="line.458"></a>
-<span class="sourceLineNo">459</span>   * @param corruptedLogs<a name="line.459"></a>
-<span class="sourceLineNo">460</span>   * @param processedLogs<a name="line.460"></a>
-<span class="sourceLineNo">461</span>   * @param oldLogDir<a name="line.461"></a>
-<span class="sourceLineNo">462</span>   * @param fs<a name="line.462"></a>
-<span class="sourceLineNo">463</span>   * @param conf<a name="line.463"></a>
-<span class="sourceLineNo">464</span>   * @throws IOException<a name="line.464"></a>
-<span class="sourceLineNo">465</span>   */<a name="line.465"></a>
-<span class="sourceLineNo">466</span>  private static void archiveLogs(<a name="line.466"></a>
-<span class="sourceLineNo">467</span>      final List&lt;Path&gt; corruptedLogs,<a name="line.467"></a>
-<span class="sourceLineNo">468</span>      final List&lt;Path&gt; processedLogs, final Path oldLogDir,<a name="line.468"></a>
-<span class="sourceLineNo">469</span>      final FileSystem fs, final Configuration conf) throws IOException {<a name="line.469"></a>
-<span class="sourceLineNo">470</span>    final Path corruptDir = new Path(FSUtils.getRootDir(conf), conf.get(<a name="line.470"></a>
-<span class="sourceLineNo">471</span>        "hbase.regionserver.hlog.splitlog.corrupt.dir",  HConstants.CORRUPT_DIR_NAME));<a name="line.471"></a>
-<span class="sourceLineNo">472</span><a name="line.472"></a>
-<span class="sourceLineNo">473</span>    if (!fs.mkdirs(corruptDir)) {<a name="line.473"></a>
-<span class="sourceLineNo">474</span>      LOG.info("Unable to mkdir " + corruptDir);<a name="line.474"></a>
-<span class="sourceLineNo">475</span>    }<a name="line.475"></a>
-<span class="sourceLineNo">476</span>    fs.mkdirs(oldLogDir);<a name="line.476"></a>
-<span class="sourceLineNo">477</span><a name="line.477"></a>
-<span class="sourceLineNo">478</span>    // this method can get restarted or called multiple times for archiving<a name="line.478"></a>
-<span class="sourceLineNo">479</span>    // the same log files.<a name="line.479"></a>
-<span class="sourceLineNo">480</span>    for (Path corrupted : corruptedLogs) {<a name="line.480"></a>
-<span class="sourceLineNo">481</span>      Path p = new Path(corruptDir, corrupted.getName());<a name="line.481"></a>
-<span class="sourceLineNo">482</span>      if (fs.exists(corrupted)) {<a name="line.482"></a>
-<span class="sourceLineNo">483</span>        if (!fs.rename(corrupted, p)) {<a name="line.483"></a>
-<span class="sourceLineNo">484</span>          LOG.warn("Unable to move corrupted log " + corrupted + " to " + p);<a name="line.484"></a>
-<span class="sourceLineNo">485</span>        } else {<a name="line.485"></a>
-<span class="sourceLineNo">486</span>          LOG.warn("Moved corrupted log " + corrupted + " to " + p);<a name="line.486"></a>
-<span class="sourceLineNo">487</span>        }<a name="line.487"></a>
-<span class="sourceLineNo">488</span>      }<a name="line.488"></a>
-<span class="sourceLineNo">489</span>    }<a name="line.489"></a>
-<span class="sourceLineNo">490</span><a name="line.490"></a>
-<span class="sourceLineNo">491</span>    for (Path p : processedLogs) {<a name="line.491"></a>
-<span class="sourceLineNo">492</span>      Path newPath = FSHLog.getWALArchivePath(oldLogDir, p);<a name="line.492"></a>
-<span class="sourceLineNo">493</span>      if (fs.exists(p)) {<a name="line.493"></a>
-<span class="sourceLineNo">494</span>        if (!FSUtils.renameAndSetModifyTime(fs, p, newPath)) {<a name="line.494"></a>
-<span class="sourceLineNo">495</span>          LOG.warn("Unable to move  " + p + " to " + newPath);<a name="line.495"></a>
-<span class="sourceLineNo">496</span>        } else {<a name="line.496"></a>
-<span class="sourceLineNo">497</span>          LOG.info("Archived processed log " + p + " to " + newPath);<a name="line.497"></a>
-<span class="sourceLineNo">498</span>        }<a name="line.498"></a>
-<span class="sourceLineNo">499</span>      }<a name="line.499"></a>
-<span class="sourceLineNo">500</span>    }<a name="line.500"></a>
-<span class="sourceLineNo">501</span>  }<a name="line.501"></a>
-<span class="sourceLineNo">502</span><a name="line.502"></a>
-<span class="sourceLineNo">503</span>  /**<a name="line.503"></a>
-<span class="sourceLineNo">504</span>   * Path to a file under RECOVERED_EDITS_DIR directory of the region found in<a name="line.504"></a>
-<span class="sourceLineNo">505</span>   * &lt;code&gt;logEntry&lt;/code&gt; named for the sequenceid in the passed<a name="line.505"></a>
-<span class="sourceLineNo">506</span>   * &lt;code&gt;logEntry&lt;/code&gt;: e.g. /hbase/some_table/2323432434/recovered.edits/2332.<a name="line.506"></a>
-<span class="sourceLineNo">507</span>   * This method also ensures existence of RECOVERED_EDITS_DIR under the region<a name="line.507"></a>
-<span class="sourceLineNo">508</span>   * creating it if necessary.<a name="line.508"></a>
-<span class="sourceLineNo">509</span>   * @param fs<a name="line.509"></a>
-<span class="sourceLineNo">510</span>   * @param logEntry<a name="line.510"></a>
-<span class="sourceLineNo">511</span>   * @param rootDir HBase root dir.<a name="line.511"></a>
-<span class="sourceLineNo">512</span>   * @return Path to file into which to dump split log edits.<a name="line.512"></a>
-<span class="sourceLineNo">513</span>   * @throws IOException<a name="line.513"></a>
-<span class="sourceLineNo">514</span>   */<a name="line.514"></a>
-<span class="sourceLineNo">515</span>  @SuppressWarnings("deprecation")<a name="line.515"></a>
-<span class="sourceLineNo">516</span>  static Path getRegionSplitEditsPath(final FileSystem fs,<a name="line.516"></a>
-<span class="sourceLineNo">517</span>      final Entry logEntry, final Path rootDir, boolean isCreate)<a name="line.517"></a>
-<span class="sourceLineNo">518</span>  throws IOException {<a name="line.518"></a>
-<span class="sourceLineNo">519</span>    Path tableDir = FSUtils.getTableDir(rootDir, logEntry.getKey().getTablename());<a name="line.519"></a>
-<span class="sourceLineNo">520</span>    String encodedRegionName = Bytes.toString(logEntry.getKey().getEncodedRegionName());<a name="line.520"></a>
-<span class="sourceLineNo">521</span>    Path regiondir = HRegion.getRegionDir(tableDir, encodedRegionName);<a name="line.521"></a>
-<span class="sourceLineNo">522</span>    Path dir = getRegionDirRecoveredEditsDir(regiondir);<a name="line.522"></a>
-<span class="sourceLineNo">523</span><a name="line.523"></a>
-<span class="sourceLineNo">524</span>    if (!fs.exists(regiondir)) {<a name="line.524"></a>
-<span class="sourceLineNo">525</span>      LOG.info("This region's directory doesn't exist: "<a name="line.525"></a>
-<span class="sourceLineNo">526</span>          + regiondir.toString() + ". It is very likely that it was" +<a name="line.526"></a>
-<span class="sourceLineNo">527</span>          " already split so it's safe to discard those edits.");<a name="line.527"></a>
-<span class="sourceLineNo">528</span>      return null;<a name="line.528"></a>
-<span class="sourceLineNo">529</span>    }<a name="line.529"></a>
-<span class="sourceLineNo">530</span>    if (fs.exists(dir) &amp;&amp; fs.isFile(dir)) {<a name="line.530"></a>
-<span class="sourceLineNo">531</span>      Path tmp = new Path("/tmp");<a name="line.531"></a>
-<span class="sourceLineNo">532</span>      if (!fs.exists(tmp)) {<a name="line.532"></a>
-<span class="sourceLineNo">533</span>        fs.mkdirs(tmp);<a name="line.533"></a>
-<span class="sourceLineNo">534</span>      }<a name="line.534"></a>
-<span class="sourceLineNo">535</span>      tmp = new Path(tmp,<a name="line.535"></a>
-<span class="sourceLineNo">536</span>        HConstants.RECOVERED_EDITS_DIR + "_" + encodedRegionName);<a name="line.536"></a>
-<span class="sourceLineNo">537</span>      LOG.warn("Found existing old file: " + dir + ". It could be some "<a name="line.537"></a>
-<span class="sourceLineNo">538</span>        + "leftover of an old installation. It should be a folder instead. "<a name="line.538"></a>
-<span class="sourceLineNo">539</span>        + "So moving it to " + tmp);<a name="line.539"></a>
-<span class="sourceLineNo">540</span>      if (!fs.rename(dir, tmp)) {<a name="line.540"></a>
-<span class="sourceLineNo">541</span>        LOG.warn("Failed to sideline old file " + dir);<a name="line.541"></a>
-<span class="sourceLineNo">542</span>      }<a name="line.542"></a>
-<span class="sourceLineNo">543</span>    }<a name="line.543"></a>
-<span class="sourceLineNo">544</span><a name="line.544"></a>
-<span class="sourceLineNo">545</span>    if (isCreate &amp;&amp; !fs.exists(dir)) {<a name="line.545"></a>
-<span class="sourceLineNo">546</span>      if (!fs.mkdirs(dir)) LOG.warn("mkdir failed on " + dir);<a name="line.546"></a>
-<span class="sourceLineNo">547</span>    }<a name="line.547"></a>
-<span class="sourceLineNo">548</span>    // Append file name ends with RECOVERED_LOG_TMPFILE_SUFFIX to ensure<a name="line.548"></a>
-<span class="sourceLineNo">549</span>    // region's replayRecoveredEdits will not delete it<a name="line.549"></a>
-<span class="sourceLineNo">550</span>    String fileName = formatRecoveredEditsFileName(logEntry.getKey().getLogSeqNum());<a name="line.550"></a>
-<span class="sourceLineNo">551</span>    fileName = getTmpRecoveredEditsFileName(fileName);<a name="line.551"></a>
-<span class="sourceLineNo">552</span>    return new Path(dir, fileName);<a name="line.552"></a>
-<span class="sourceLineNo">553</span>  }<a name="line.553"></a>
-<span class="sourceLineNo">554</span><a name="line.554"></a>
-<span class="sourceLineNo">555</span>  static String getTmpRecoveredEditsFileName(String fileName) {<a name="line.555"></a>
-<span class="sourceLineNo">556</span>    return fileName + RECOVERED_LOG_TMPFILE_SUFFIX;<a name="line.556"></a>
-<span class="sourceLineNo">557</span>  }<a name="line.557"></a>
-<span class="sourceLineNo">558</span><a name="line.558"></a>
-<span class="sourceLineNo">559</span>  /**<a name="line.559"></a>
-<span class="sourceLineNo">560</span>   * Get the completed recovered edits file path, renaming it to be by last edit<a name="line.560"></a>
-<span class="sourceLineNo">561</span>   * in the file from its first edit. Then we could use the name to skip<a name="line.561"></a>
-<span class="sourceLineNo">562</span>   * recovered edits when doing {@link HRegion#replayRecoveredEditsIfAny}.<a name="line.562"></a>
-<span class="sourceLineNo">563</span>   * @param srcPath<a name="line.563"></a>
-<span class="sourceLineNo">564</span>   * @param maximumEditLogSeqNum<a name="line.564"></a>
-<span class="sourceLineNo">565</span>   * @return dstPath take file's last edit log seq num as the name<a name="line.565"></a>
-<span class="sourceLineNo">566</span>   */<a name="line.566"></a>
-<span class="sourceLineNo">567</span>  static Path getCompletedRecoveredEditsFilePath(Path srcPath,<a name="line.567"></a>
-<span class="sourceLineNo">568</span>      Long maximumEditLogSeqNum) {<a name="line.568"></a>
-<span class="sourceLineNo">569</span>    String fileName = formatRecoveredEditsFileName(maximumEditLogSeqNum);<a name="line.569"></a>
-<span class="sourceLineNo">570</span>    return new Path(srcPath.getParent(), fileName);<a name="line.570"></a>
-<span class="sourceLineNo">571</span>  }<a name="line.571"></a>
-<span class="sourceLineNo">572</span><a name="line.572"></a>
-<span class="sourceLineNo">573</span>  static String formatRecoveredEditsFileName(final long seqid) {<a name="line.573"></a>
-<span class="sourceLineNo">574</span>    return String.format("%019d", seqid);<a name="line.574"></a>
-<span class="sourceLineNo">575</span>  }<a name="line.575"></a>
-<span class="sourceLineNo">576</span><a name="line.576"></a>
-<span class="sourceLineNo">577</span>  private static final Pattern EDITFILES_NAME_PATTERN = Pattern.compile("-?[0-9]+");<a name="line.577"></a>
-<span class="sourceLineNo">578</span>  private static final String RECOVERED_LOG_TMPFILE_SUFFIX = ".temp";<a name="line.578"></a>
-<span class="sourceLineNo">579</span><a name="line.579"></a>
-<span class="sourceLineNo">580</span>  /**<a name="line.580"></a>
-<span class="sourceLineNo">581</span>   * @param regiondir<a name="line.581"></a>
-<span class="sourceLineNo">582</span>   *          This regions directory in the filesystem.<a name="line.582"></a>
-<span class="sourceLineNo">583</span>   * @return The directory that holds recovered edits files for the region<a name="line.583"></a>
-<span class="sourceLineNo">584</span>   *         &lt;code&gt;regiondir&lt;/code&gt;<a name="line.584"></a>
-<span class="sourceLineNo">585</span>   */<a name="line.585"></a>
-<span class="sourceLineNo">586</span>  public static Path getRegionDirRecoveredEditsDir(final Path regiondir) {<a name="line.586"></a>
-<span class="sourceLineNo">587</span>    return new Path(regiondir, HConstants.RECOVERED_EDITS_DIR);<a name="line.587"></a>
-<span class="sourceLineNo">588</span>  }<a name="line.588"></a>
-<span class="sourceLineNo">589</span><a name="line.589"></a>
-<span class="sourceLineNo">590</span>  /**<a name="line.590"></a>
-<span class="sourceLineNo">591</span>   * Returns sorted set of edit files made by splitter, excluding files<a name="line.591"></a>
-<span class="sourceLineNo">592</span>   * with '.temp' suffix.<a name="line.592"></a>
-<span class="sourceLineNo">593</span>   *<a name="line.593"></a>
-<span class="sourceLineNo">594</span>   * @param fs<a name="line.594"></a>
-<span class="sourceLineNo">595</span>   * @param regiondir<a name="line.595"></a>
-<span class="sourceLineNo">596</span>   * @return Files in passed &lt;code&gt;regiondir&lt;/code&gt; as a sorted set.<a name="line.596"></a>
-<span class="sourceLineNo">597</span>   * @throws IOException<a name="line.597"></a>
-<span class="sourceLineNo">598</span>   */<a name="line.598"></a>
-<span class="sourceLineNo">599</span>  public static NavigableSet&lt;Path&gt; getSplitEditFilesSorted(final FileSystem fs,<a name="line.599"></a>
-<span class="sourceLineNo">600</span>      final Path regiondir) throws IOException {<a name="line.600"></a>
-<span class="sourceLineNo">601</span>    NavigableSet&lt;Path&gt; filesSorted = new TreeSet&lt;Path&gt;();<a name="line.601"></a>
-<span class="sourceLineNo">602</span>    Path editsdir = getRegionDirRecoveredEditsDir(regiondir);<a name="line.602"></a>
-<span class="sourceLineNo">603</span>    if (!fs.exists(editsdir))<a name="line.603"></a>
-<span class="sourceLineNo">604</span>      return filesSorted;<a name="line.604"></a>
-<span class="sourceLineNo">605</span>    FileStatus[] files = FSUtils.listStatus(fs, editsdir, new PathFilter() {<a name="line.605"></a>
-<span class="sourceLineNo">606</span>      @Override<a name="line.606"></a>
-<span class="sourceLineNo">607</span>      public boolean accept(Path p) {<a name="line.607"></a>
-<span class="sourceLineNo">608</span>        boolean result = false;<a name="line.608"></a>
-<span class="sourceLineNo">609</span>        try {<a name="line.609"></a>
-<span class="sourceLineNo">610</span>          // Return files and only files that match the editfile names pattern.<a name="line.610"></a>
-<span class="sourceLineNo">611</span>          // There can be other files in this directory other than edit files.<a name="line.611"></a>
-<span class="sourceLineNo">612</span>          // In particular, on error, we'll move aside the bad edit file giving<a name="line.612"></a>
-<span class="sourceLineNo">613</span>          // it a timestamp suffix. See moveAsideBadEditsFile.<a name="line.613"></a>
-<span class="sourceLineNo">614</span>          Matcher m = EDITFILES_NAME_PATTERN.matcher(p.getName());<a name="line.614"></a>
-<span class="sourceLineNo">615</span>          result = fs.isFile(p) &amp;&amp; m.matches();<a name="line.615"></a>
-<span class="sourceLineNo">616</span>          // Skip the file whose name ends with RECOVERED_LOG_TMPFILE_SUFFIX,<a name="line.616"></a>
-<span class="sourceLineNo">617</span>          // because it means splitwal thread is writting this file.<a name="line.617"></a>
-<span class="sourceLineNo">618</span>          if (p.getName().endsWith(RECOVERED_LOG_TMPFILE_SUFFIX)) {<a name="line.618"></a>
-<span class="sourceLineNo">619</span>            result = false;<a name="line.619"></a>
-<span class="sourceLineNo">620</span>          }<a name="line.620"></a>
-<span class="sourceLineNo">621</span>          // Skip SeqId Files<a name="line.621"></a>
-<span class="sourceLineNo">622</span>          if (isSequenceIdFile(p)) {<a name="line.622"></a>
-<span class="sourceLineNo">623</span>            result = false;<a name="line.623"></a>
-<span class="sourceLineNo">624</span>          }<a name="line.624"></a>
-<span class="sourceLineNo">625</span>        } catch (IOException e) {<a name="line.625"></a>
-<span class="sourceLineNo">626</span>          LOG.warn("Failed isFile check on " + p);<a name="line.626"></a>
-<span class="sourceLineNo">627</span>        }<a name="line.627"></a>
-<span class="sourceLineNo">628</span>        return result;<a name="line.628"></a>
-<span class="sourceLineNo">629</span>      }<a name="line.629"></a>
-<span class="sourceLineNo">630</span>    });<a name="line.630"></a>
-<span class="sourceLineNo">631</span>    if (files == null) {<a name="line.631"></a>
-<span class="sourceLineNo">632</span>      return filesSorted;<a name="line.632"></a>
-<span class="sourceLineNo">633</span>    }<a name="line.633"></a>
-<span class="sourceLineNo">634</span>    for (FileStatus status : files) {<a name="line.634"></a>
-<span class="sourceLineNo">635</span>      filesSorted.add(status.getPath());<a name="line.635"></a>
-<span class="sourceLineNo">636</span>    }<a name="line.636"></a>
-<span class="sourceLineNo">637</span>    return filesSorted;<a name="line.637"></a>
-<span class="sourceLineNo">638</span>  }<a name="line.638"></a>
-<span class="sourceLineNo">639</span><a name="line.639"></a>
-<span class="sourceLineNo">640</span>  /**<a name="line.640"></a>
-<span class="sourceLineNo">641</span>   * Move aside a bad edits file.<a name="line.641"></a>
-<span class="sourceLineNo">642</span>   *<a name="line.642"></a>
-<span class="sourceLineNo">643</span>   * @param fs<a name="line.643"></a>
-<span class="sourceLineNo">644</span>   * @param edits<a name="line.644"></a>
-<span class="sourceLineNo">645</span>   *          Edits file to move aside.<a name="line.645"></a>
-<span class="sourceLineNo">646</span>   * @return The name of the moved aside file.<a name="line.646"></a>
-<span class="sourceLineNo">647</span>   * @throws IOException<a name="line.647"></a>
-<span class="sourceLineNo">648</span>   */<a name="line.648"></a>
-<span class="sourceLineNo">649</span>  public static Path moveAsideBadEditsFile(final FileSystem fs, final Path edits)<a name="line.649"></a>
-<span class="sourceLineNo">650</span>      throws IOException {<a name="line.650"></a>
-<span class="sourceLineNo">651</span>    Path moveAsideName = new Path(edits.getParent(), edits.getName() + "."<a name="line.651"></a>
-<span class="sourceLineNo">652</span>        + System.currentTimeMillis());<a name="line.652"></a>
-<span class="sourceLineNo">653</span>    if (!fs.rename(edits, moveAsideName)) {<a name="line.653"></a>
-<span class="sourceLineNo">654</span>      LOG.warn("Rename failed from " + edits + " to " + moveAsideName);<a name="line.654"></a>
-<span class="sourceLineNo">655</span>    }<a name="line.655"></a>
-<span class="sourceLineNo">656</span>    return moveAsideName;<a name="line.656"></a>
-<span class="sourceLineNo">657</span>  }<a name="line.657"></a>
-<span class="sourceLineNo">658</span><a name="line.658"></a>
-<span class="sourceLineNo">659</span>  private static final String SEQUENCE_ID_FILE_SUFFIX = ".seqid";<a name="line.659"></a>
-<span class="sourceLineNo">660</span>  private static final String OLD_SEQUENCE_ID_FILE_SUFFIX = "_seqid";<a name="line.660"></a>
-<span class="sourceLineNo">661</span>  private static final int SEQUENCE_ID_FILE_SUFFIX_LENGTH = SEQUENCE_ID_FILE_SUFFIX.length();<a name="line.661"></a>
-<span class="sourceLineNo">662</span><a name="line.662"></a>
-<span class="sourceLineNo">663</span>  /**<a name="line.663"></a>
-<span class="sourceLineNo">664</span>   * Is the given file a region open sequence id file.<a name="line.664"></a>
-<span class="sourceLineNo">665</span>   */<a name="line.665"></a>
-<span class="sourceLineNo">666</span>  @VisibleForTesting<a name="line.666"></a>
-<span class="sourceLineNo">667</span>  public static boolean isSequenceIdFile(final Path file) {<a name="line.667"></a>
-<span class="sourceLineNo">668</span>    return file.getName().endsWith(SEQUENCE_ID_FILE_SUFFIX)<a name="line.668"></a>
-<span class="sourceLineNo">669</span>        || file.getName().endsWith(OLD_SEQUENCE_ID_FILE_SUFFIX);<a name="line.669"></a>
-<span class="sourceLineNo">670</span>  }<a name="line.670"></a>
+<span class="sourceLineNo">346</span>            regionMaxSeqIdInStores.put(encodedRegionNameAsStr, maxSeqIdInStores);<a name="line.346"></a>
+<span class="sourceLineNo">347</span>            lastFlushedSequenceId = ids.getLastFlushedSequenceId();<a name="line.347"></a>
+<span class="sourceLineNo">348</span>            if (LOG.isDebugEnabled()) {<a name="line.348"></a>
+<span class="sourceLineNo">349</span>              LOG.debug("DLS Last flushed sequenceid for " + encodedRegionNameAsStr + ": " +<a name="line.349"></a>
+<span class="sourceLineNo">350</span>                  TextFormat.shortDebugString(ids));<a name="line.350"></a>
+<span class="sourceLineNo">351</span>            }<a name="line.351"></a>
+<span class="sourceLineNo">352</span>          }<a name="line.352"></a>
+<span class="sourceLineNo">353</span>          if (lastFlushedSequenceId == null) {<a name="line.353"></a>
+<span class="sourceLineNo">354</span>            lastFlushedSequenceId = -1L;<a name="line.354"></a>
+<span class="sourceLineNo">355</span>          }<a name="line.355"></a>
+<span class="sourceLineNo">356</span>          lastFlushedSequenceIds.put(encodedRegionNameAsStr, lastFlushedSequenceId);<a name="line.356"></a>
+<span class="sourceLineNo">357</span>        }<a name="line.357"></a>
+<span class="sourceLineNo">358</span>        if (lastFlushedSequenceId &gt;= entry.getKey().getSequenceId()) {<a name="line.358"></a>
+<span class="sourceLineNo">359</span>          editsSkipped++;<a name="line.359"></a>
+<span class="sourceLineNo">360</span>          continue;<a name="line.360"></a>
+<span class="sourceLineNo">361</span>        }<a name="line.361"></a>
+<span class="sourceLineNo">362</span>        entryBuffers.appendEntry(entry);<a name="line.362"></a>
+<span class="sourceLineNo">363</span>        editsCount++;<a name="line.363"></a>
+<span class="sourceLineNo">364</span>        int moreWritersFromLastCheck = this.getNumOpenWriters() - numOpenedFilesLastCheck;<a name="line.364"></a>
+<span class="sourceLineNo">365</span>        // If sufficient edits have passed, check if we should report progress.<a name="line.365"></a>
+<span class="sourceLineNo">366</span>        if (editsCount % interval == 0<a name="line.366"></a>
+<span class="sourceLineNo">367</span>            || moreWritersFromLastCheck &gt; numOpenedFilesBeforeReporting) {<a name="line.367"></a>
+<span class="sourceLineNo">368</span>          numOpenedFilesLastCheck = this.getNumOpenWriters();<a name="line.368"></a>
+<span class="sourceLineNo">369</span>          String countsStr = (editsCount - (editsSkipped + outputSink.getSkippedEdits()))<a name="line.369"></a>
+<span class="sourceLineNo">370</span>              + " edits, skipped " + editsSkipped + " edits.";<a name="line.370"></a>
+<span class="sourceLineNo">371</span>          status.setStatus("Split " + countsStr);<a name="line.371"></a>
+<span class="sourceLineNo">372</span>          if (reporter != null &amp;&amp; !reporter.progress()) {<a name="line.372"></a>
+<span class="sourceLineNo">373</span>            progress_failed = true;<a name="line.373"></a>
+<span class="sourceLineNo">374</span>            return false;<a name="line.374"></a>
+<span class="sourceLineNo">375</span>          }<a name="line.375"></a>
+<span class="sourceLineNo">376</span>        }<a name="line.376"></a>
+<span class="sourceLineNo">377</span>      }<a name="line.377"></a>
+<span class="sourceLineNo">378</span>    } catch (InterruptedException ie) {<a name="line.378"></a>
+<span class="sourceLineNo">379</span>      IOException iie = new InterruptedIOException();<a name="line.379"></a>
+<span class="sourceLineNo">380</span>      iie.initCause(ie);<a name="line.380"></a>
+<span class="sourceLineNo">381</span>      throw iie;<a name="line.381"></a>
+<span class="sourceLineNo">382</span>    } catch (CorruptedLogFileException e) {<a name="line.382"></a>
+<span class="sourceLineNo">383</span>      LOG.warn("Could not parse, corrupted log file " + logPath, e);<a name="line.383"></a>
+<span class="sourceLineNo">384</span>      csm.getSplitLogWorkerCoordination().markCorrupted(rootDir,<a name="line.384"></a>
+<span class="sourceLineNo">385</span>        logfile.getPath().getName(), fs);<a name="line.385"></a>
+<span class="sourceLineNo">386</span>      isCorrupted = true;<a name="line.386"></a>
+<span class="sourceLineNo">387</span>    } catch (IOException e) {<a name="line.387"></a>
+<span class="sourceLineNo">388</span>      e = e instanceof RemoteException ? ((RemoteException) e).unwrapRemoteException() : e;<a name="line.388"></a>
+<span class="sourceLineNo">389</span>      throw e;<a name="line.389"></a>
+<span class="sourceLineNo">390</span>    } finally {<a name="line.390"></a>
+<span class="sourceLineNo">391</span>      LOG.debug("Finishing writing output logs and closing down.");<a name="line.391"></a>
+<span class="sourceLineNo">392</span>      try {<a name="line.392"></a>
+<span class="sourceLineNo">393</span>        if (null != in) {<a name="line.393"></a>
+<span class="sourceLineNo">394</span>          in.close();<a name="line.394"></a>
+<span class="sourceLineNo">395</span>        }<a name="line.395"></a>
+<span class="sourceLineNo">396</span>      } catch (IOException exception) {<a name="line.396"></a>
+<span class="sourceLineNo">397</span>        LOG.warn("Could not close wal reader: " + exception.getMessage());<a name="line.397"></a>
+<span class="sourceLineNo">398</span>        LOG.debug("exception details", exception);<a name="line.398"></a>
+<span class="sourceLineNo">399</span>      }<a name="line.399"></a>
+<span class="sourceLineNo">400</span>      try {<a name="line.400"></a>
+<span class="sourceLineNo">401</span>        if (outputSinkStarted) {<a name="line.401"></a>
+<span class="sourceLineNo">402</span>          // Set progress_failed to true as the immediate following statement will reset its value<a name="line.402"></a>
+<span class="sourceLineNo">403</span>          // when finishWritingAndClose() throws exception, progress_failed has the right value<a name="line.403"></a>
+<span class="sourceLineNo">404</span>          progress_failed = true;<a name="line.404"></a>
+<span class="sourceLineNo">405</span>          progress_failed = outputSink.finishWritingAndClose() == null;<a name="line.405"></a>
+<span class="sourceLineNo">406</span>        }<a name="line.406"></a>
+<span class="sourceLineNo">407</span>      } finally {<a name="line.407"></a>
+<span class="sourceLineNo">408</span>        String msg =<a name="line.408"></a>
+<span class="sourceLineNo">409</span>            "Processed " + editsCount + " edits across " + outputSink.getNumberOfRecoveredRegions()<a name="line.409"></a>
+<span class="sourceLineNo">410</span>                + " regions; edits skipped=" + editsSkipped + "; log file=" + logPath +<a name="line.410"></a>
+<span class="sourceLineNo">411</span>                ", length=" + logfile.getLen() + // See if length got updated post lease recovery<a name="line.411"></a>
+<span class="sourceLineNo">412</span>                ", corrupted=" + isCorrupted + ", progress failed=" + progress_failed;<a name="line.412"></a>
+<span class="sourceLineNo">413</span>        LOG.info(msg);<a name="line.413"></a>
+<span class="sourceLineNo">414</span>        status.markComplete(msg);<a name="line.414"></a>
+<span class="sourceLineNo">415</span>      }<a name="line.415"></a>
+<span class="sourceLineNo">416</span>    }<a name="line.416"></a>
+<span class="sourceLineNo">417</span>    return !progress_failed;<a name="line.417"></a>
+<span class="sourceLineNo">418</span>  }<a name="line.418"></a>
+<span class="sourceLineNo">419</span><a name="line.419"></a>
+<span class="sourceLineNo">420</span>  /**<a name="line.420"></a>
+<span class="sourceLineNo">421</span>   * Completes the work done by splitLogFile by archiving logs<a name="line.421"></a>
+<span class="sourceLineNo">422</span>   * &lt;p&gt;<a name="line.422"></a>
+<span class="sourceLineNo">423</span>   * It is invoked by SplitLogManager once it knows that one of the<a name="line.423"></a>
+<span class="sourceLineNo">424</span>   * SplitLogWorkers have completed the splitLogFile() part. If the master<a name="line.424"></a>
+<span class="sourceLineNo">425</span>   * crashes then this function might get called multiple times.<a name="line.425"></a>
+<span class="sourceLineNo">426</span>   * &lt;p&gt;<a name="line.426"></a>
+<span class="sourceLineNo">427</span>   * @param logfile<a name="line.427"></a>
+<span class="sourceLineNo">428</span>   * @param conf<a name="line.428"></a>
+<span class="sourceLineNo">429</span>   * @throws IOException<a name="line.429"></a>
+<span class="sourceLineNo">430</span>   */<a name="line.430"></a>
+<span class="sourceLineNo">431</span>  public static void finishSplitLogFile(String logfile,<a name="line.431"></a>
+<span class="sourceLineNo">432</span>      Configuration conf)  throws IOException {<a name="line.432"></a>
+<span class="sourceLineNo">433</span>    Path rootdir = FSUtils.getRootDir(conf);<a name="line.433"></a>
+<span class="sourceLineNo">434</span>    Path oldLogDir = new Path(rootdir, HConstants.HREGION_OLDLOGDIR_NAME);<a name="line.434"></a>
+<span class="sourceLineNo">435</span>    Path logPath;<a name="line.435"></a>
+<span class="sourceLineNo">436</span>    if (FSUtils.isStartingWithPath(rootdir, logfile)) {<a name="line.436"></a>
+<span class="sourceLineNo">437</span>      logPath = new Path(logfile);<a name="line.437"></a>
+<span class="sourceLineNo">438</span>    } else {<a name="line.438"></a>
+<span class="sourceLineNo">439</span>      logPath = new Path(rootdir, logfile);<a name="line.439"></a>
+<span class="sourceLineNo">440</span>    }<a name="line.440"></a>
+<span class="sourceLineNo">441</span>    finishSplitLogFile(rootdir, oldLogDir, logPath, conf);<a name="line.441"></a>
+<span class="sourceLineNo">442</span>  }<a name="line.442"></a>
+<span class="sourceLineNo">443</span><a name="line.443"></a>
+<span class="sourceLineNo">444</span>  private static void finishSplitLogFile(Path rootdir, Path oldLogDir,<a name="line.444"></a>
+<span class="sourceLineNo">445</span>      Path logPath, Configuration conf) throws IOException {<a name="line.445"></a>
+<span class="sourceLineNo">446</span>    List&lt;Path&gt; processedLogs = new ArrayList&lt;Path&gt;();<a name="line.446"></a>
+<span class="sourceLineNo">447</span>    List&lt;Path&gt; corruptedLogs = new ArrayList&lt;Path&gt;();<a name="line.447"></a>
+<span class="sourceLineNo">448</span>    FileSystem fs;<a name="line.448"></a>
+<span class="sourceLineNo">449</span>    fs = rootdir.getFileSystem(conf);<a name="line.449"></a>
+<span class="sourceLineNo">450</span>    if (ZKSplitLog.isCorrupted(rootdir, logPath.getName(), fs)) {<a name="line.450"></a>
+<span class="sourceLineNo">451</span>      corruptedLogs.add(logPath);<a name="line.451"></a>
+<span class="sourceLineNo">452</span>    } else {<a name="line.452"></a>
+<span class="sourceLineNo">453</span>      processedLogs.add(logPath);<a name="line.453"></a>
+<span class="sourceLineNo">454</span>    }<a name="line.454"></a>
+<span class="sourceLineNo">455</span>    archiveLogs(corruptedLogs, processedLogs, oldLogDir, fs, conf);<a name="line.455"></a>
+<span class="sourceLineNo">456</span>    Path stagingDir = ZKSplitLog.getSplitLogDir(rootdir, logPath.getName());<a name="line.456"></a>
+<span class="sourceLineNo">457</span>    fs.delete(stagingDir, true);<a name="line.457"></a>
+<span class="sourceLineNo">458</span>  }<a name="line.458"></a>
+<span class="sourceLineNo">459</span><a name="line.459"></a>
+<span class="sourceLineNo">460</span>  /**<a name="line.460"></a>
+<span class="sourceLineNo">461</span>   * Moves processed logs to a oldLogDir after successful processing Moves<a name="line.461"></a>
+<span class="sourceLineNo">462</span>   * corrupted logs (any log that couldn't be successfully parsed to corruptDir<a name="line.462"></a>
+<span class="sourceLineNo">463</span>   * (.corrupt) for later investigation<a name="line.463"></a>
+<span class="sourceLineNo">464</span>   *<a name="line.464"></a>
+<span class="sourceLineNo">465</span>   * @param corruptedLogs<a name="line.465"></a>
+<span class="sourceLineNo">466</span>   * @param processedLogs<a name="line.466"></a>
+<span class="sourceLineNo">467</span>   * @param oldLogDir<a name="line.467"></a>
+<span class="sourceLineNo">468</span>   * @param fs<a name="line.468"></a>
+<span class="sourceLineNo">469</span>   * @param conf<a name="line.469"></a>
+<span class="sourceLineNo">470</span>   * @throws IOException<a name="line.470"></a>
+<span class="sourceLineNo">471</span>   */<a name="line.471"></a>
+<span class="sourceLineNo">472</span>  private static void archiveLogs(<a name="line.472"></a>
+<span class="sourceLineNo">473</span>      final List&lt;Path&gt; corruptedLogs,<a name="line.473"></a>
+<span class="sourceLineNo">474</span>      final List&lt;Path&gt; processedLogs, final Path oldLogDir,<a name="line.474"></a>
+<span class="sourceLineNo">475</span>      final FileSystem fs, final Configuration conf) throws IOException {<a name="line.475"></a>
+<span class="sourceLineNo">476</span>    final Path corruptDir = new Path(FSUtils.getRootDir(conf), conf.get(<a name="line.476"></a>
+<span class="sourceLineNo">477</span>        "hbase.regionserver.hlog.splitlog.corrupt.dir",  HConstants.CORRUPT_DIR_NAME));<a name="line.477"></a>
+<span class="sourceLineNo">478</span><a name="line.478"></a>
+<span class="sourceLineNo">479</span>    if (!fs.mkdirs(corruptDir)) {<a name="line.479"></a>
+<span class="sourceLineNo">480</span>      LOG.info("Unable to mkdir " + corruptDir);<a name="line.480"></a>
+<span class="sourceLineNo">481</span>    }<a name="line.481"></a>
+<span class="sourceLineNo">482</span>    fs.mkdirs(oldLogDir);<a name="line.482"></a>
+<span class="sourceLineNo">483</span><a name="line.483"></a>
+<span class="sourceLineNo">484</span>    // this method can get restarted or called multiple times for archiving<a name="line.484"></a>
+<span class="sourceLineNo">485</span>    // the same log files.<a name="line.485"></a>
+<span class="sourceLineNo">486</span>    for (Path corrupted : corruptedLogs) {<a name="line.486"></a>
+<span class="sourceLineNo">487</span>      Path p = new Path(corruptDir, corrupted.getName());<a name="line.487"></a>
+<span class="sourceLineNo">488</span>      if (fs.exists(corrupted)) {<a name="line.488"></a>
+<span class="sourceLineNo">489</span>        if (!fs.rename(corrupted, p)) {<a name="line.489"></a>
+<span class="sourceLineNo">490</span>          LOG.warn("Unable to move corrupted log " + corrupted + " to " + p);<a name="line.490"></a>
+<span class="sourceLineNo">491</span>        } else {<a name="line.491"></a>
+<span class="sourceLineNo">492</span>          LOG.warn("Moved corrupted log " + corrupted + " to " + p);<a name="line.492"></a>
+<span class="sourceLineNo">493</span>        }<a name="line.493"></a>
+<span class="sourceLineNo">494</span>      }<a name="line.494"></a>
+<span class="sourceLineNo">495</span>    }<a name="line.495"></a>
+<span class="sourceLineNo">496</span><a name="line.496"></a>
+<span class="sourceLineNo">497</span>    for (Path p : processedLogs) {<a name="line.497"></a>
+<span class="sourceLineNo">498</span>      Path newPath = FSHLog.getWALArchivePath(oldLogDir, p);<a name="line.498"></a>
+<span class="sourceLineNo">499</span>      if (fs.exists(p)) {<a name="line.499"></a>
+<span class="sourceLineNo">500</span>        if (!FSUtils.renameAndSetModifyTime(fs, p, newPath)) {<a name="line.500"></a>
+<span class="sourceLineNo">501</span>          LOG.warn("Unable to move  " + p + " to " + newPath);<a name="line.501"></a>
+<span class="sourceLineNo">502</span>        } else {<a name="line.502"></a>
+<span class="sourceLineNo">503</span>          LOG.info("Archived processed log " + p + " to " + newPath);<a name="line.503"></a>
+<span class="sourceLineNo">504</span>        }<a name="line.504"></a>
+<span class="sourceLineNo">505</span>      }<a name="line.505"></a>
+<span class="sourceLineNo">506</span>    }<a name="line.506"></a>
+<span class="sourceLineNo">507</span>  }<a name="line.507"></a>
+<span class="sourceLineNo">508</span><a name="line.508"></a>
+<span class="sourceLineNo">509</span>  /**<a name="line.509"></a>
+<span class="sourceLineNo">510</span>   * Path to a file under RECOVERED_EDITS_DIR directory of the region found in<a name="line.510"></a>
+<span class="sourceLineNo">511</span>   * &lt;code&gt;logEntry&lt;/code&gt; named for the sequenceid in the passed<a name="line.511"></a>
+<span class="sourceLineNo">512</span>   * &lt;code&gt;logEntry&lt;/code&gt;: e.g. /hbase/some_table/2323432434/recovered.edits/2332.<a name="line.512"></a>
+<span class="sourceLineNo">513</span>   * This method also ensures existence of RECOVERED_EDITS_DIR under the region<a name="line.513"></a>
+<span class="sourceLineNo">514</span>   * creating it if necessary.<a name="line.514"></a>
+<span class="sourceLineNo">515</span>   * @param fs<a name="line.515"></a>
+<span class="sourceLineNo">516</span>   * @param logEntry<a name="line.516"></a>
+<span class="sourceLineNo">517</span>   * @param rootDir HBase root dir.<a name="line.517"></a>
+<span class="sourceLineNo">518</span>   * @param fileBeingSplit the file being split currently. Used to generate tmp file name.<a name="line.518"></a>
+<span class="sourceLineNo">519</span>   * @return Path to file into which to dump split log edits.<a name="line.519"></a>
+<span class="sourceLineNo">520</span>   * @throws IOException<a name="line.520"></a>
+<span class="sourceLineNo">521</span>   */<a name="line.521"></a>
+<span class="sourceLineNo">522</span>  @SuppressWarnings("deprecation")<a name="line.522"></a>
+<span class="sourceLineNo">523</span>  private static Path getRegionSplitEditsPath(final FileSystem fs,<a name="line.523"></a>
+<span class="sourceLineNo">524</span>      final Entry logEntry, final Path rootDir, FileStatus fileBeingSplit)<a name="line.524"></a>
+<span class="sourceLineNo">525</span>  throws IOException {<a name="line.525"></a>
+<span class="sourceLineNo">526</span>    Path tableDir = FSUtils.getTableDir(rootDir, logEntry.getKey().getTablename());<a name="line.526"></a>
+<span class="sourceLineNo">527</span>    String encodedRegionName = Bytes.toString(logEntry.getKey().getEncodedRegionName());<a name="line.527"></a>
+<span class="sourceLineNo">528</span>    Path regiondir = HRegion.getRegionDir(tableDir, encodedRegionName);<a name="line.528"></a>
+<span class="sourceLineNo">529</span>    Path dir = getRegionDirRecoveredEditsDir(regiondir);<a name="line.529"></a>
+<span class="sourceLineNo">530</span><a name="line.530"></a>
+<span class="sourceLineNo">531</span>    if (!fs.exists(regiondir)) {<a name="line.531"></a>
+<span class="sourceLineNo">532</span>      LOG.info("This region's directory doesn't exist: "<a name="line.532"></a>
+<span class="sourceLineNo">533</span>          + regiondir.toString() + ". It is very likely that it was" +<a name="line.533"></a>
+<span class="sourceLineNo">534</span>          " already split so it's safe to discard those edits.");<a name="line.534"></a>
+<span class="sourceLineNo">535</span>      return null;<a name="line.535"></a>
+<span class="sourceLineNo">536</span>    }<a name="line.536"></a>
+<span class="sourceLineNo">537</span>    if (fs.exists(dir) &amp;&amp; fs.isFile(dir)) {<a name="line.537"></a>
+<span class="sourceLineNo">538</span>      Path tmp = new Path("/tmp");<a name="line.538"></a>
+<span class="sourceLineNo">539</span>      if (!fs.exists(tmp)) {<a name="line.539"></a>
+<span class="sourceLineNo">540</span>        fs.mkdirs(tmp);<a name="line.540"></a>
+<span class="sourceLineNo">541</span>      }<a name="line.541"></a>
+<span class="sourceLineNo">542</span>      tmp = new Path(tmp,<a name="line.542"></a>
+<span class="sourceLineNo">543</span>        HConstants.RECOVERED_EDITS_DIR + "_" + encodedRegionName);<a name="line.543"></a>
+<span class="sourceLineNo">544</span>      LOG.warn("Found existing old file: " + dir + ". It could be some "<a name="line.544"></a>
+<span class="sourceLineNo">545</span>        + "leftover of an old installation. It should be a folder instead. "<a name="line.545"></a>
+<span class="sourceLineNo">546</span>        + "So moving it to " + tmp);<a name="line.546"></a>
+<span class="sourceLineNo">547</span>      if (!fs.rename(dir, tmp)) {<a name="line.547"></a>
+<span class="sourceLineNo">548</span>        LOG.warn("Failed to sideline old file " + dir);<a name="line.548"></a>
+<span class="sourceLineNo">549</span>      }<a name="line.549"></a>
+<span class="sourceLineNo">550</span>    }<a name="line.550"></a>
+<span class="sourceLineNo">551</span><a name="line.551"></a>
+<span class="sourceLineNo">552</span>    if (!fs.exists(dir) &amp;

<TRUNCATED>

Mime
View raw message