hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [32/47] hbase-site git commit: Published site at .
Date Sat, 13 Jan 2018 15:32:21 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/554d61c6/devapidocs/src-html/org/apache/hadoop/hbase/backup/impl/IncrementalTableBackupClient.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/backup/impl/IncrementalTableBackupClient.html b/devapidocs/src-html/org/apache/hadoop/hbase/backup/impl/IncrementalTableBackupClient.html
index 6d840bd..75e3c2b 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/backup/impl/IncrementalTableBackupClient.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/backup/impl/IncrementalTableBackupClient.html
@@ -80,44 +80,44 @@
 <span class="sourceLineNo">072</span>  }<a name="line.72"></a>
 <span class="sourceLineNo">073</span><a name="line.73"></a>
 <span class="sourceLineNo">074</span>  protected List&lt;String&gt; filterMissingFiles(List&lt;String&gt; incrBackupFileList) throws IOException {<a name="line.74"></a>
-<span class="sourceLineNo">075</span>    FileSystem fs = FileSystem.get(conf);<a name="line.75"></a>
-<span class="sourceLineNo">076</span>    List&lt;String&gt; list = new ArrayList&lt;String&gt;();<a name="line.76"></a>
-<span class="sourceLineNo">077</span>    for (String file : incrBackupFileList) {<a name="line.77"></a>
-<span class="sourceLineNo">078</span>      Path p = new Path(file);<a name="line.78"></a>
-<span class="sourceLineNo">079</span>      if (fs.exists(p) || isActiveWalPath(p)) {<a name="line.79"></a>
-<span class="sourceLineNo">080</span>        list.add(file);<a name="line.80"></a>
-<span class="sourceLineNo">081</span>      } else {<a name="line.81"></a>
-<span class="sourceLineNo">082</span>        LOG.warn("Can't find file: " + file);<a name="line.82"></a>
-<span class="sourceLineNo">083</span>      }<a name="line.83"></a>
-<span class="sourceLineNo">084</span>    }<a name="line.84"></a>
-<span class="sourceLineNo">085</span>    return list;<a name="line.85"></a>
-<span class="sourceLineNo">086</span>  }<a name="line.86"></a>
-<span class="sourceLineNo">087</span><a name="line.87"></a>
-<span class="sourceLineNo">088</span>  /**<a name="line.88"></a>
-<span class="sourceLineNo">089</span>   * Check if a given path is belongs to active WAL directory<a name="line.89"></a>
-<span class="sourceLineNo">090</span>   * @param p path<a name="line.90"></a>
-<span class="sourceLineNo">091</span>   * @return true, if yes<a name="line.91"></a>
-<span class="sourceLineNo">092</span>   */<a name="line.92"></a>
-<span class="sourceLineNo">093</span>  protected boolean isActiveWalPath(Path p) {<a name="line.93"></a>
-<span class="sourceLineNo">094</span>    return !AbstractFSWALProvider.isArchivedLogFile(p);<a name="line.94"></a>
-<span class="sourceLineNo">095</span>  }<a name="line.95"></a>
-<span class="sourceLineNo">096</span><a name="line.96"></a>
-<span class="sourceLineNo">097</span>  protected static int getIndex(TableName tbl, List&lt;TableName&gt; sTableList) {<a name="line.97"></a>
-<span class="sourceLineNo">098</span>    if (sTableList == null) return 0;<a name="line.98"></a>
-<span class="sourceLineNo">099</span>    for (int i = 0; i &lt; sTableList.size(); i++) {<a name="line.99"></a>
-<span class="sourceLineNo">100</span>      if (tbl.equals(sTableList.get(i))) {<a name="line.100"></a>
-<span class="sourceLineNo">101</span>        return i;<a name="line.101"></a>
-<span class="sourceLineNo">102</span>      }<a name="line.102"></a>
-<span class="sourceLineNo">103</span>    }<a name="line.103"></a>
-<span class="sourceLineNo">104</span>    return -1;<a name="line.104"></a>
-<span class="sourceLineNo">105</span>  }<a name="line.105"></a>
-<span class="sourceLineNo">106</span><a name="line.106"></a>
-<span class="sourceLineNo">107</span>  /*<a name="line.107"></a>
-<span class="sourceLineNo">108</span>   * Reads bulk load records from backup table, iterates through the records and forms the paths<a name="line.108"></a>
-<span class="sourceLineNo">109</span>   * for bulk loaded hfiles. Copies the bulk loaded hfiles to backup destination<a name="line.109"></a>
-<span class="sourceLineNo">110</span>   * @param sTableList list of tables to be backed up<a name="line.110"></a>
-<span class="sourceLineNo">111</span>   * @return map of table to List of files<a name="line.111"></a>
-<span class="sourceLineNo">112</span>   */<a name="line.112"></a>
+<span class="sourceLineNo">075</span>    List&lt;String&gt; list = new ArrayList&lt;String&gt;();<a name="line.75"></a>
+<span class="sourceLineNo">076</span>    for (String file : incrBackupFileList) {<a name="line.76"></a>
+<span class="sourceLineNo">077</span>      Path p = new Path(file);<a name="line.77"></a>
+<span class="sourceLineNo">078</span>      if (fs.exists(p) || isActiveWalPath(p)) {<a name="line.78"></a>
+<span class="sourceLineNo">079</span>        list.add(file);<a name="line.79"></a>
+<span class="sourceLineNo">080</span>      } else {<a name="line.80"></a>
+<span class="sourceLineNo">081</span>        LOG.warn("Can't find file: " + file);<a name="line.81"></a>
+<span class="sourceLineNo">082</span>      }<a name="line.82"></a>
+<span class="sourceLineNo">083</span>    }<a name="line.83"></a>
+<span class="sourceLineNo">084</span>    return list;<a name="line.84"></a>
+<span class="sourceLineNo">085</span>  }<a name="line.85"></a>
+<span class="sourceLineNo">086</span><a name="line.86"></a>
+<span class="sourceLineNo">087</span>  /**<a name="line.87"></a>
+<span class="sourceLineNo">088</span>   * Check if a given path is belongs to active WAL directory<a name="line.88"></a>
+<span class="sourceLineNo">089</span>   * @param p path<a name="line.89"></a>
+<span class="sourceLineNo">090</span>   * @return true, if yes<a name="line.90"></a>
+<span class="sourceLineNo">091</span>   */<a name="line.91"></a>
+<span class="sourceLineNo">092</span>  protected boolean isActiveWalPath(Path p) {<a name="line.92"></a>
+<span class="sourceLineNo">093</span>    return !AbstractFSWALProvider.isArchivedLogFile(p);<a name="line.93"></a>
+<span class="sourceLineNo">094</span>  }<a name="line.94"></a>
+<span class="sourceLineNo">095</span><a name="line.95"></a>
+<span class="sourceLineNo">096</span>  protected static int getIndex(TableName tbl, List&lt;TableName&gt; sTableList) {<a name="line.96"></a>
+<span class="sourceLineNo">097</span>    if (sTableList == null) return 0;<a name="line.97"></a>
+<span class="sourceLineNo">098</span>    for (int i = 0; i &lt; sTableList.size(); i++) {<a name="line.98"></a>
+<span class="sourceLineNo">099</span>      if (tbl.equals(sTableList.get(i))) {<a name="line.99"></a>
+<span class="sourceLineNo">100</span>        return i;<a name="line.100"></a>
+<span class="sourceLineNo">101</span>      }<a name="line.101"></a>
+<span class="sourceLineNo">102</span>    }<a name="line.102"></a>
+<span class="sourceLineNo">103</span>    return -1;<a name="line.103"></a>
+<span class="sourceLineNo">104</span>  }<a name="line.104"></a>
+<span class="sourceLineNo">105</span><a name="line.105"></a>
+<span class="sourceLineNo">106</span>  /*<a name="line.106"></a>
+<span class="sourceLineNo">107</span>   * Reads bulk load records from backup table, iterates through the records and forms the paths<a name="line.107"></a>
+<span class="sourceLineNo">108</span>   * for bulk loaded hfiles. Copies the bulk loaded hfiles to backup destination<a name="line.108"></a>
+<span class="sourceLineNo">109</span>   * @param sTableList list of tables to be backed up<a name="line.109"></a>
+<span class="sourceLineNo">110</span>   * @return map of table to List of files<a name="line.110"></a>
+<span class="sourceLineNo">111</span>   */<a name="line.111"></a>
+<span class="sourceLineNo">112</span>  @SuppressWarnings("unchecked")<a name="line.112"></a>
 <span class="sourceLineNo">113</span>  protected Map&lt;byte[], List&lt;Path&gt;&gt;[] handleBulkLoad(List&lt;TableName&gt; sTableList) throws IOException {<a name="line.113"></a>
 <span class="sourceLineNo">114</span>    Map&lt;byte[], List&lt;Path&gt;&gt;[] mapForSrc = new Map[sTableList.size()];<a name="line.114"></a>
 <span class="sourceLineNo">115</span>    List&lt;String&gt; activeFiles = new ArrayList&lt;String&gt;();<a name="line.115"></a>
@@ -125,15 +125,15 @@
 <span class="sourceLineNo">117</span>    Pair&lt;Map&lt;TableName, Map&lt;String, Map&lt;String, List&lt;Pair&lt;String, Boolean&gt;&gt;&gt;&gt;&gt;, List&lt;byte[]&gt;&gt; pair =<a name="line.117"></a>
 <span class="sourceLineNo">118</span>    backupManager.readBulkloadRows(sTableList);<a name="line.118"></a>
 <span class="sourceLineNo">119</span>    Map&lt;TableName, Map&lt;String, Map&lt;String, List&lt;Pair&lt;String, Boolean&gt;&gt;&gt;&gt;&gt; map = pair.getFirst();<a name="line.119"></a>
-<span class="sourceLineNo">120</span>    FileSystem fs = FileSystem.get(conf);<a name="line.120"></a>
-<span class="sourceLineNo">121</span>    FileSystem tgtFs;<a name="line.121"></a>
-<span class="sourceLineNo">122</span>    try {<a name="line.122"></a>
-<span class="sourceLineNo">123</span>      tgtFs = FileSystem.get(new URI(backupInfo.getBackupRootDir()), conf);<a name="line.123"></a>
-<span class="sourceLineNo">124</span>    } catch (URISyntaxException use) {<a name="line.124"></a>
-<span class="sourceLineNo">125</span>      throw new IOException("Unable to get FileSystem", use);<a name="line.125"></a>
-<span class="sourceLineNo">126</span>    }<a name="line.126"></a>
-<span class="sourceLineNo">127</span>    Path rootdir = FSUtils.getRootDir(conf);<a name="line.127"></a>
-<span class="sourceLineNo">128</span>    Path tgtRoot = new Path(new Path(backupInfo.getBackupRootDir()), backupId);<a name="line.128"></a>
+<span class="sourceLineNo">120</span>    FileSystem tgtFs;<a name="line.120"></a>
+<span class="sourceLineNo">121</span>    try {<a name="line.121"></a>
+<span class="sourceLineNo">122</span>      tgtFs = FileSystem.get(new URI(backupInfo.getBackupRootDir()), conf);<a name="line.122"></a>
+<span class="sourceLineNo">123</span>    } catch (URISyntaxException use) {<a name="line.123"></a>
+<span class="sourceLineNo">124</span>      throw new IOException("Unable to get FileSystem", use);<a name="line.124"></a>
+<span class="sourceLineNo">125</span>    }<a name="line.125"></a>
+<span class="sourceLineNo">126</span>    Path rootdir = FSUtils.getRootDir(conf);<a name="line.126"></a>
+<span class="sourceLineNo">127</span>    Path tgtRoot = new Path(new Path(backupInfo.getBackupRootDir()), backupId);<a name="line.127"></a>
+<span class="sourceLineNo">128</span><a name="line.128"></a>
 <span class="sourceLineNo">129</span>    for (Map.Entry&lt;TableName, Map&lt;String, Map&lt;String, List&lt;Pair&lt;String, Boolean&gt;&gt;&gt;&gt;&gt; tblEntry :<a name="line.129"></a>
 <span class="sourceLineNo">130</span>      map.entrySet()) {<a name="line.130"></a>
 <span class="sourceLineNo">131</span>      TableName srcTable = tblEntry.getKey();<a name="line.131"></a>
@@ -200,216 +200,255 @@
 <span class="sourceLineNo">192</span>    }<a name="line.192"></a>
 <span class="sourceLineNo">193</span><a name="line.193"></a>
 <span class="sourceLineNo">194</span>    copyBulkLoadedFiles(activeFiles, archiveFiles);<a name="line.194"></a>
-<span class="sourceLineNo">195</span><a name="line.195"></a>
-<span class="sourceLineNo">196</span>    backupManager.writeBulkLoadedFiles(sTableList, mapForSrc);<a name="line.196"></a>
-<span class="sourceLineNo">197</span>    backupManager.removeBulkLoadedRows(sTableList, pair.getSecond());<a name="line.197"></a>
-<span class="sourceLineNo">198</span>    return mapForSrc;<a name="line.198"></a>
-<span class="sourceLineNo">199</span>  }<a name="line.199"></a>
-<span class="sourceLineNo">200</span><a name="line.200"></a>
-<span class="sourceLineNo">201</span>  private void copyBulkLoadedFiles(List&lt;String&gt; activeFiles, List&lt;String&gt; archiveFiles)<a name="line.201"></a>
-<span class="sourceLineNo">202</span>    throws IOException<a name="line.202"></a>
-<span class="sourceLineNo">203</span>  {<a name="line.203"></a>
-<span class="sourceLineNo">204</span><a name="line.204"></a>
-<span class="sourceLineNo">205</span>    try {<a name="line.205"></a>
-<span class="sourceLineNo">206</span>      // Enable special mode of BackupDistCp<a name="line.206"></a>
-<span class="sourceLineNo">207</span>      conf.setInt(MapReduceBackupCopyJob.NUMBER_OF_LEVELS_TO_PRESERVE_KEY, 5);<a name="line.207"></a>
-<span class="sourceLineNo">208</span>      // Copy active files<a name="line.208"></a>
-<span class="sourceLineNo">209</span>      String tgtDest = backupInfo.getBackupRootDir() + Path.SEPARATOR + backupInfo.getBackupId();<a name="line.209"></a>
-<span class="sourceLineNo">210</span>      if (activeFiles.size() &gt; 0) {<a name="line.210"></a>
+<span class="sourceLineNo">195</span>    backupManager.deleteBulkLoadedRows(pair.getSecond());<a name="line.195"></a>
+<span class="sourceLineNo">196</span>    return mapForSrc;<a name="line.196"></a>
+<span class="sourceLineNo">197</span>  }<a name="line.197"></a>
+<span class="sourceLineNo">198</span><a name="line.198"></a>
+<span class="sourceLineNo">199</span>  private void copyBulkLoadedFiles(List&lt;String&gt; activeFiles, List&lt;String&gt; archiveFiles)<a name="line.199"></a>
+<span class="sourceLineNo">200</span>      throws IOException {<a name="line.200"></a>
+<span class="sourceLineNo">201</span><a name="line.201"></a>
+<span class="sourceLineNo">202</span>    try {<a name="line.202"></a>
+<span class="sourceLineNo">203</span>      // Enable special mode of BackupDistCp<a name="line.203"></a>
+<span class="sourceLineNo">204</span>      conf.setInt(MapReduceBackupCopyJob.NUMBER_OF_LEVELS_TO_PRESERVE_KEY, 5);<a name="line.204"></a>
+<span class="sourceLineNo">205</span>      // Copy active files<a name="line.205"></a>
+<span class="sourceLineNo">206</span>      String tgtDest = backupInfo.getBackupRootDir() + Path.SEPARATOR + backupInfo.getBackupId();<a name="line.206"></a>
+<span class="sourceLineNo">207</span>      int attempt = 1;<a name="line.207"></a>
+<span class="sourceLineNo">208</span>      while (activeFiles.size() &gt; 0) {<a name="line.208"></a>
+<span class="sourceLineNo">209</span>        LOG.info("Copy "+ activeFiles.size() +<a name="line.209"></a>
+<span class="sourceLineNo">210</span>          " active bulk loaded files. Attempt ="+ (attempt++));<a name="line.210"></a>
 <span class="sourceLineNo">211</span>        String[] toCopy = new String[activeFiles.size()];<a name="line.211"></a>
 <span class="sourceLineNo">212</span>        activeFiles.toArray(toCopy);<a name="line.212"></a>
-<span class="sourceLineNo">213</span>        incrementalCopyHFiles(toCopy, tgtDest);<a name="line.213"></a>
-<span class="sourceLineNo">214</span>      }<a name="line.214"></a>
-<span class="sourceLineNo">215</span>      if (archiveFiles.size() &gt; 0) {<a name="line.215"></a>
-<span class="sourceLineNo">216</span>        String[] toCopy = new String[archiveFiles.size()];<a name="line.216"></a>
-<span class="sourceLineNo">217</span>        archiveFiles.toArray(toCopy);<a name="line.217"></a>
-<span class="sourceLineNo">218</span>        incrementalCopyHFiles(toCopy, tgtDest);<a name="line.218"></a>
-<span class="sourceLineNo">219</span>      }<a name="line.219"></a>
-<span class="sourceLineNo">220</span>    } finally {<a name="line.220"></a>
-<span class="sourceLineNo">221</span>      // Disable special mode of BackupDistCp<a name="line.221"></a>
-<span class="sourceLineNo">222</span>      conf.unset(MapReduceBackupCopyJob.NUMBER_OF_LEVELS_TO_PRESERVE_KEY);<a name="line.222"></a>
-<span class="sourceLineNo">223</span>    }<a name="line.223"></a>
-<span class="sourceLineNo">224</span><a name="line.224"></a>
-<span class="sourceLineNo">225</span>  }<a name="line.225"></a>
-<span class="sourceLineNo">226</span><a name="line.226"></a>
-<span class="sourceLineNo">227</span>  @Override<a name="line.227"></a>
-<span class="sourceLineNo">228</span>  public void execute() throws IOException {<a name="line.228"></a>
-<span class="sourceLineNo">229</span><a name="line.229"></a>
-<span class="sourceLineNo">230</span>    try {<a name="line.230"></a>
-<span class="sourceLineNo">231</span>      // case PREPARE_INCREMENTAL:<a name="line.231"></a>
-<span class="sourceLineNo">232</span>      beginBackup(backupManager, backupInfo);<a name="line.232"></a>
-<span class="sourceLineNo">233</span>      backupInfo.setPhase(BackupPhase.PREPARE_INCREMENTAL);<a name="line.233"></a>
-<span class="sourceLineNo">234</span>      LOG.debug("For incremental backup, current table set is "<a name="line.234"></a>
-<span class="sourceLineNo">235</span>          + backupManager.getIncrementalBackupTableSet());<a name="line.235"></a>
-<span class="sourceLineNo">236</span>      newTimestamps =<a name="line.236"></a>
-<span class="sourceLineNo">237</span>          ((IncrementalBackupManager) backupManager).getIncrBackupLogFileMap();<a name="line.237"></a>
-<span class="sourceLineNo">238</span>    } catch (Exception e) {<a name="line.238"></a>
-<span class="sourceLineNo">239</span>      // fail the overall backup and return<a name="line.239"></a>
-<span class="sourceLineNo">240</span>      failBackup(conn, backupInfo, backupManager, e, "Unexpected Exception : ",<a name="line.240"></a>
-<span class="sourceLineNo">241</span>        BackupType.INCREMENTAL, conf);<a name="line.241"></a>
-<span class="sourceLineNo">242</span>      throw new IOException(e);<a name="line.242"></a>
-<span class="sourceLineNo">243</span>    }<a name="line.243"></a>
-<span class="sourceLineNo">244</span><a name="line.244"></a>
-<span class="sourceLineNo">245</span>    // case INCREMENTAL_COPY:<a name="line.245"></a>
-<span class="sourceLineNo">246</span>    try {<a name="line.246"></a>
-<span class="sourceLineNo">247</span>      // copy out the table and region info files for each table<a name="line.247"></a>
-<span class="sourceLineNo">248</span>      BackupUtils.copyTableRegionInfo(conn, backupInfo, conf);<a name="line.248"></a>
-<span class="sourceLineNo">249</span>      // convert WAL to HFiles and copy them to .tmp under BACKUP_ROOT<a name="line.249"></a>
-<span class="sourceLineNo">250</span>      convertWALsToHFiles();<a name="line.250"></a>
-<span class="sourceLineNo">251</span>      incrementalCopyHFiles(new String[] {getBulkOutputDir().toString()}, backupInfo.getBackupRootDir());<a name="line.251"></a>
-<span class="sourceLineNo">252</span>      // Save list of WAL files copied<a name="line.252"></a>
-<span class="sourceLineNo">253</span>      backupManager.recordWALFiles(backupInfo.getIncrBackupFileList());<a name="line.253"></a>
-<span class="sourceLineNo">254</span>    } catch (Exception e) {<a name="line.254"></a>
-<span class="sourceLineNo">255</span>      String msg = "Unexpected exception in incremental-backup: incremental copy " + backupId;<a name="line.255"></a>
-<span class="sourceLineNo">256</span>      // fail the overall backup and return<a name="line.256"></a>
-<span class="sourceLineNo">257</span>      failBackup(conn, backupInfo, backupManager, e, msg, BackupType.INCREMENTAL, conf);<a name="line.257"></a>
-<span class="sourceLineNo">258</span>      throw new IOException(e);<a name="line.258"></a>
-<span class="sourceLineNo">259</span>    }<a name="line.259"></a>
-<span class="sourceLineNo">260</span>    // case INCR_BACKUP_COMPLETE:<a name="line.260"></a>
-<span class="sourceLineNo">261</span>    // set overall backup status: complete. Here we make sure to complete the backup.<a name="line.261"></a>
-<span class="sourceLineNo">262</span>    // After this checkpoint, even if entering cancel process, will let the backup finished<a name="line.262"></a>
-<span class="sourceLineNo">263</span>    try {<a name="line.263"></a>
-<span class="sourceLineNo">264</span>      // Set the previousTimestampMap which is before this current log roll to the manifest.<a name="line.264"></a>
-<span class="sourceLineNo">265</span>      HashMap&lt;TableName, HashMap&lt;String, Long&gt;&gt; previousTimestampMap =<a name="line.265"></a>
-<span class="sourceLineNo">266</span>          backupManager.readLogTimestampMap();<a name="line.266"></a>
-<span class="sourceLineNo">267</span>      backupInfo.setIncrTimestampMap(previousTimestampMap);<a name="line.267"></a>
-<span class="sourceLineNo">268</span><a name="line.268"></a>
-<span class="sourceLineNo">269</span>      // The table list in backupInfo is good for both full backup and incremental backup.<a name="line.269"></a>
-<span class="sourceLineNo">270</span>      // For incremental backup, it contains the incremental backup table set.<a name="line.270"></a>
-<span class="sourceLineNo">271</span>      backupManager.writeRegionServerLogTimestamp(backupInfo.getTables(), newTimestamps);<a name="line.271"></a>
-<span class="sourceLineNo">272</span><a name="line.272"></a>
-<span class="sourceLineNo">273</span>      HashMap&lt;TableName, HashMap&lt;String, Long&gt;&gt; newTableSetTimestampMap =<a name="line.273"></a>
-<span class="sourceLineNo">274</span>          backupManager.readLogTimestampMap();<a name="line.274"></a>
-<span class="sourceLineNo">275</span><a name="line.275"></a>
-<span class="sourceLineNo">276</span>      Long newStartCode =<a name="line.276"></a>
-<span class="sourceLineNo">277</span>          BackupUtils.getMinValue(BackupUtils.getRSLogTimestampMins(newTableSetTimestampMap));<a name="line.277"></a>
-<span class="sourceLineNo">278</span>      backupManager.writeBackupStartCode(newStartCode);<a name="line.278"></a>
-<span class="sourceLineNo">279</span><a name="line.279"></a>
-<span class="sourceLineNo">280</span>      handleBulkLoad(backupInfo.getTableNames());<a name="line.280"></a>
-<span class="sourceLineNo">281</span>      // backup complete<a name="line.281"></a>
-<span class="sourceLineNo">282</span>      completeBackup(conn, backupInfo, backupManager, BackupType.INCREMENTAL, conf);<a name="line.282"></a>
-<span class="sourceLineNo">283</span><a name="line.283"></a>
-<span class="sourceLineNo">284</span>    } catch (IOException e) {<a name="line.284"></a>
-<span class="sourceLineNo">285</span>      failBackup(conn, backupInfo, backupManager, e, "Unexpected Exception : ",<a name="line.285"></a>
-<span class="sourceLineNo">286</span>        BackupType.INCREMENTAL, conf);<a name="line.286"></a>
-<span class="sourceLineNo">287</span>      throw new IOException(e);<a name="line.287"></a>
-<span class="sourceLineNo">288</span>    }<a name="line.288"></a>
-<span class="sourceLineNo">289</span>  }<a name="line.289"></a>
-<span class="sourceLineNo">290</span><a name="line.290"></a>
-<span class="sourceLineNo">291</span>  protected void incrementalCopyHFiles(String[] files, String backupDest) throws IOException {<a name="line.291"></a>
-<span class="sourceLineNo">292</span><a name="line.292"></a>
-<span class="sourceLineNo">293</span>    try {<a name="line.293"></a>
-<span class="sourceLineNo">294</span>      LOG.debug("Incremental copy HFiles is starting. dest="+backupDest);<a name="line.294"></a>
-<span class="sourceLineNo">295</span>      // set overall backup phase: incremental_copy<a name="line.295"></a>
-<span class="sourceLineNo">296</span>      backupInfo.setPhase(BackupPhase.INCREMENTAL_COPY);<a name="line.296"></a>
-<span class="sourceLineNo">297</span>      // get incremental backup file list and prepare parms for DistCp<a name="line.297"></a>
-<span class="sourceLineNo">298</span>      String[] strArr = new String[files.length + 1];<a name="line.298"></a>
-<span class="sourceLineNo">299</span>      System.arraycopy(files, 0, strArr, 0, files.length);<a name="line.299"></a>
-<span class="sourceLineNo">300</span>      strArr[strArr.length - 1] = backupDest;<a name="line.300"></a>
-<span class="sourceLineNo">301</span><a name="line.301"></a>
-<span class="sourceLineNo">302</span>      String jobname = "Incremental_Backup-HFileCopy-" + backupInfo.getBackupId();<a name="line.302"></a>
-<span class="sourceLineNo">303</span>      if (LOG.isDebugEnabled()) {<a name="line.303"></a>
-<span class="sourceLineNo">304</span>        LOG.debug("Setting incremental copy HFiles job name to : " + jobname);<a name="line.304"></a>
-<span class="sourceLineNo">305</span>      }<a name="line.305"></a>
-<span class="sourceLineNo">306</span>      conf.set(JOB_NAME_CONF_KEY, jobname);<a name="line.306"></a>
-<span class="sourceLineNo">307</span><a name="line.307"></a>
-<span class="sourceLineNo">308</span>      BackupCopyJob copyService = BackupRestoreFactory.getBackupCopyJob(conf);<a name="line.308"></a>
-<span class="sourceLineNo">309</span>      int res = copyService.copy(backupInfo, backupManager, conf, BackupType.INCREMENTAL, strArr);<a name="line.309"></a>
-<span class="sourceLineNo">310</span>      if (res != 0) {<a name="line.310"></a>
-<span class="sourceLineNo">311</span>        LOG.error("Copy incremental HFile files failed with return code: " + res + ".");<a name="line.311"></a>
-<span class="sourceLineNo">312</span>        throw new IOException("Failed copy from " + StringUtils.join(files, ',')<a name="line.312"></a>
-<span class="sourceLineNo">313</span>            + " to " + backupDest);<a name="line.313"></a>
-<span class="sourceLineNo">314</span>      }<a name="line.314"></a>
-<span class="sourceLineNo">315</span>      LOG.debug("Incremental copy HFiles from " + StringUtils.join(files, ',')<a name="line.315"></a>
-<span class="sourceLineNo">316</span>          + " to " + backupDest + " finished.");<a name="line.316"></a>
-<span class="sourceLineNo">317</span>    } finally {<a name="line.317"></a>
-<span class="sourceLineNo">318</span>      deleteBulkLoadDirectory();<a name="line.318"></a>
-<span class="sourceLineNo">319</span>    }<a name="line.319"></a>
-<span class="sourceLineNo">320</span>  }<a name="line.320"></a>
-<span class="sourceLineNo">321</span><a name="line.321"></a>
-<span class="sourceLineNo">322</span>  protected void deleteBulkLoadDirectory() throws IOException {<a name="line.322"></a>
-<span class="sourceLineNo">323</span>    // delete original bulk load directory on method exit<a name="line.323"></a>
-<span class="sourceLineNo">324</span>    Path path = getBulkOutputDir();<a name="line.324"></a>
-<span class="sourceLineNo">325</span>    FileSystem fs = FileSystem.get(conf);<a name="line.325"></a>
-<span class="sourceLineNo">326</span>    boolean result = fs.delete(path, true);<a name="line.326"></a>
-<span class="sourceLineNo">327</span>    if (!result) {<a name="line.327"></a>
-<span class="sourceLineNo">328</span>      LOG.warn("Could not delete " + path);<a name="line.328"></a>
-<span class="sourceLineNo">329</span>    }<a name="line.329"></a>
+<span class="sourceLineNo">213</span>        // Active file can be archived during copy operation,<a name="line.213"></a>
+<span class="sourceLineNo">214</span>        // we need to handle this properly<a name="line.214"></a>
+<span class="sourceLineNo">215</span>        try {<a name="line.215"></a>
+<span class="sourceLineNo">216</span>          incrementalCopyHFiles(toCopy, tgtDest);<a name="line.216"></a>
+<span class="sourceLineNo">217</span>          break;<a name="line.217"></a>
+<span class="sourceLineNo">218</span>        } catch (IOException e) {<a name="line.218"></a>
+<span class="sourceLineNo">219</span>          // Check if some files got archived<a name="line.219"></a>
+<span class="sourceLineNo">220</span>          // Update active and archived lists<a name="line.220"></a>
+<span class="sourceLineNo">221</span>          // When file is being moved from active to archive<a name="line.221"></a>
+<span class="sourceLineNo">222</span>          // directory, the number of active files decreases<a name="line.222"></a>
+<span class="sourceLineNo">223</span><a name="line.223"></a>
+<span class="sourceLineNo">224</span>          int numOfActive = activeFiles.size();<a name="line.224"></a>
+<span class="sourceLineNo">225</span>          updateFileLists(activeFiles, archiveFiles);<a name="line.225"></a>
+<span class="sourceLineNo">226</span>          if (activeFiles.size() &lt; numOfActive) {<a name="line.226"></a>
+<span class="sourceLineNo">227</span>            continue;<a name="line.227"></a>
+<span class="sourceLineNo">228</span>          }<a name="line.228"></a>
+<span class="sourceLineNo">229</span>          // if not - throw exception<a name="line.229"></a>
+<span class="sourceLineNo">230</span>          throw e;<a name="line.230"></a>
+<span class="sourceLineNo">231</span>        }<a name="line.231"></a>
+<span class="sourceLineNo">232</span>      }<a name="line.232"></a>
+<span class="sourceLineNo">233</span>      // If incremental copy will fail for archived files<a name="line.233"></a>
+<span class="sourceLineNo">234</span>      // we will have partially loaded files in backup destination (only files from active data<a name="line.234"></a>
+<span class="sourceLineNo">235</span>      // directory). It is OK, because the backup will marked as FAILED and data will be cleaned up<a name="line.235"></a>
+<span class="sourceLineNo">236</span>      if (archiveFiles.size() &gt; 0) {<a name="line.236"></a>
+<span class="sourceLineNo">237</span>        String[] toCopy = new String[archiveFiles.size()];<a name="line.237"></a>
+<span class="sourceLineNo">238</span>        archiveFiles.toArray(toCopy);<a name="line.238"></a>
+<span class="sourceLineNo">239</span>        incrementalCopyHFiles(toCopy, tgtDest);<a name="line.239"></a>
+<span class="sourceLineNo">240</span>      }<a name="line.240"></a>
+<span class="sourceLineNo">241</span>    } finally {<a name="line.241"></a>
+<span class="sourceLineNo">242</span>      // Disable special mode of BackupDistCp<a name="line.242"></a>
+<span class="sourceLineNo">243</span>      conf.unset(MapReduceBackupCopyJob.NUMBER_OF_LEVELS_TO_PRESERVE_KEY);<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    }<a name="line.244"></a>
+<span class="sourceLineNo">245</span><a name="line.245"></a>
+<span class="sourceLineNo">246</span>  }<a name="line.246"></a>
+<span class="sourceLineNo">247</span><a name="line.247"></a>
+<span class="sourceLineNo">248</span>  private void updateFileLists(List&lt;String&gt; activeFiles, List&lt;String&gt; archiveFiles)<a name="line.248"></a>
+<span class="sourceLineNo">249</span>      throws IOException {<a name="line.249"></a>
+<span class="sourceLineNo">250</span>    List&lt;String&gt; newlyArchived = new ArrayList&lt;String&gt;();<a name="line.250"></a>
+<span class="sourceLineNo">251</span><a name="line.251"></a>
+<span class="sourceLineNo">252</span>    for (String spath : activeFiles) {<a name="line.252"></a>
+<span class="sourceLineNo">253</span>      if (!fs.exists(new Path(spath))) {<a name="line.253"></a>
+<span class="sourceLineNo">254</span>        newlyArchived.add(spath);<a name="line.254"></a>
+<span class="sourceLineNo">255</span>      }<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>    if (newlyArchived.size() &gt; 0) {<a name="line.258"></a>
+<span class="sourceLineNo">259</span>      activeFiles.removeAll(newlyArchived);<a name="line.259"></a>
+<span class="sourceLineNo">260</span>      archiveFiles.addAll(newlyArchived);<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>    LOG.debug(newlyArchived.size() + " files have been archived.");<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>  @Override<a name="line.267"></a>
+<span class="sourceLineNo">268</span>  public void execute() throws IOException {<a name="line.268"></a>
+<span class="sourceLineNo">269</span><a name="line.269"></a>
+<span class="sourceLineNo">270</span>    try {<a name="line.270"></a>
+<span class="sourceLineNo">271</span>      // case PREPARE_INCREMENTAL:<a name="line.271"></a>
+<span class="sourceLineNo">272</span>      beginBackup(backupManager, backupInfo);<a name="line.272"></a>
+<span class="sourceLineNo">273</span>      backupInfo.setPhase(BackupPhase.PREPARE_INCREMENTAL);<a name="line.273"></a>
+<span class="sourceLineNo">274</span>      LOG.debug("For incremental backup, current table set is "<a name="line.274"></a>
+<span class="sourceLineNo">275</span>          + backupManager.getIncrementalBackupTableSet());<a name="line.275"></a>
+<span class="sourceLineNo">276</span>      newTimestamps =<a name="line.276"></a>
+<span class="sourceLineNo">277</span>          ((IncrementalBackupManager) backupManager).getIncrBackupLogFileMap();<a name="line.277"></a>
+<span class="sourceLineNo">278</span>    } catch (Exception e) {<a name="line.278"></a>
+<span class="sourceLineNo">279</span>      // fail the overall backup and return<a name="line.279"></a>
+<span class="sourceLineNo">280</span>      failBackup(conn, backupInfo, backupManager, e, "Unexpected Exception : ",<a name="line.280"></a>
+<span class="sourceLineNo">281</span>        BackupType.INCREMENTAL, conf);<a name="line.281"></a>
+<span class="sourceLineNo">282</span>      throw new IOException(e);<a name="line.282"></a>
+<span class="sourceLineNo">283</span>    }<a name="line.283"></a>
+<span class="sourceLineNo">284</span><a name="line.284"></a>
+<span class="sourceLineNo">285</span>    // case INCREMENTAL_COPY:<a name="line.285"></a>
+<span class="sourceLineNo">286</span>    try {<a name="line.286"></a>
+<span class="sourceLineNo">287</span>      // copy out the table and region info files for each table<a name="line.287"></a>
+<span class="sourceLineNo">288</span>      BackupUtils.copyTableRegionInfo(conn, backupInfo, conf);<a name="line.288"></a>
+<span class="sourceLineNo">289</span>      // convert WAL to HFiles and copy them to .tmp under BACKUP_ROOT<a name="line.289"></a>
+<span class="sourceLineNo">290</span>      convertWALsToHFiles();<a name="line.290"></a>
+<span class="sourceLineNo">291</span>      incrementalCopyHFiles(new String[] {getBulkOutputDir().toString()}, backupInfo.getBackupRootDir());<a name="line.291"></a>
+<span class="sourceLineNo">292</span>      // Save list of WAL files copied<a name="line.292"></a>
+<span class="sourceLineNo">293</span>      backupManager.recordWALFiles(backupInfo.getIncrBackupFileList());<a name="line.293"></a>
+<span class="sourceLineNo">294</span>    } catch (Exception e) {<a name="line.294"></a>
+<span class="sourceLineNo">295</span>      String msg = "Unexpected exception in incremental-backup: incremental copy " + backupId;<a name="line.295"></a>
+<span class="sourceLineNo">296</span>      // fail the overall backup and return<a name="line.296"></a>
+<span class="sourceLineNo">297</span>      failBackup(conn, backupInfo, backupManager, e, msg, BackupType.INCREMENTAL, conf);<a name="line.297"></a>
+<span class="sourceLineNo">298</span>      throw new IOException(e);<a name="line.298"></a>
+<span class="sourceLineNo">299</span>    }<a name="line.299"></a>
+<span class="sourceLineNo">300</span>    // case INCR_BACKUP_COMPLETE:<a name="line.300"></a>
+<span class="sourceLineNo">301</span>    // set overall backup status: complete. Here we make sure to complete the backup.<a name="line.301"></a>
+<span class="sourceLineNo">302</span>    // After this checkpoint, even if entering cancel process, will let the backup finished<a name="line.302"></a>
+<span class="sourceLineNo">303</span>    try {<a name="line.303"></a>
+<span class="sourceLineNo">304</span>      // Set the previousTimestampMap which is before this current log roll to the manifest.<a name="line.304"></a>
+<span class="sourceLineNo">305</span>      HashMap&lt;TableName, HashMap&lt;String, Long&gt;&gt; previousTimestampMap =<a name="line.305"></a>
+<span class="sourceLineNo">306</span>          backupManager.readLogTimestampMap();<a name="line.306"></a>
+<span class="sourceLineNo">307</span>      backupInfo.setIncrTimestampMap(previousTimestampMap);<a name="line.307"></a>
+<span class="sourceLineNo">308</span><a name="line.308"></a>
+<span class="sourceLineNo">309</span>      // The table list in backupInfo is good for both full backup and incremental backup.<a name="line.309"></a>
+<span class="sourceLineNo">310</span>      // For incremental backup, it contains the incremental backup table set.<a name="line.310"></a>
+<span class="sourceLineNo">311</span>      backupManager.writeRegionServerLogTimestamp(backupInfo.getTables(), newTimestamps);<a name="line.311"></a>
+<span class="sourceLineNo">312</span><a name="line.312"></a>
+<span class="sourceLineNo">313</span>      HashMap&lt;TableName, HashMap&lt;String, Long&gt;&gt; newTableSetTimestampMap =<a name="line.313"></a>
+<span class="sourceLineNo">314</span>          backupManager.readLogTimestampMap();<a name="line.314"></a>
+<span class="sourceLineNo">315</span><a name="line.315"></a>
+<span class="sourceLineNo">316</span>      Long newStartCode =<a name="line.316"></a>
+<span class="sourceLineNo">317</span>          BackupUtils.getMinValue(BackupUtils.getRSLogTimestampMins(newTableSetTimestampMap));<a name="line.317"></a>
+<span class="sourceLineNo">318</span>      backupManager.writeBackupStartCode(newStartCode);<a name="line.318"></a>
+<span class="sourceLineNo">319</span><a name="line.319"></a>
+<span class="sourceLineNo">320</span>      handleBulkLoad(backupInfo.getTableNames());<a name="line.320"></a>
+<span class="sourceLineNo">321</span>      // backup complete<a name="line.321"></a>
+<span class="sourceLineNo">322</span>      completeBackup(conn, backupInfo, backupManager, BackupType.INCREMENTAL, conf);<a name="line.322"></a>
+<span class="sourceLineNo">323</span><a name="line.323"></a>
+<span class="sourceLineNo">324</span>    } catch (IOException e) {<a name="line.324"></a>
+<span class="sourceLineNo">325</span>      failBackup(conn, backupInfo, backupManager, e, "Unexpected Exception : ",<a name="line.325"></a>
+<span class="sourceLineNo">326</span>        BackupType.INCREMENTAL, conf);<a name="line.326"></a>
+<span class="sourceLineNo">327</span>      throw new IOException(e);<a name="line.327"></a>
+<span class="sourceLineNo">328</span>    }<a name="line.328"></a>
+<span class="sourceLineNo">329</span>  }<a name="line.329"></a>
 <span class="sourceLineNo">330</span><a name="line.330"></a>
-<span class="sourceLineNo">331</span>  }<a name="line.331"></a>
+<span class="sourceLineNo">331</span>  protected void incrementalCopyHFiles(String[] files, String backupDest) throws IOException {<a name="line.331"></a>
 <span class="sourceLineNo">332</span><a name="line.332"></a>
-<span class="sourceLineNo">333</span>  protected void convertWALsToHFiles() throws IOException {<a name="line.333"></a>
-<span class="sourceLineNo">334</span>    // get incremental backup file list and prepare parameters for DistCp<a name="line.334"></a>
-<span class="sourceLineNo">335</span>    List&lt;String&gt; incrBackupFileList = backupInfo.getIncrBackupFileList();<a name="line.335"></a>
-<span class="sourceLineNo">336</span>    // Get list of tables in incremental backup set<a name="line.336"></a>
-<span class="sourceLineNo">337</span>    Set&lt;TableName&gt; tableSet = backupManager.getIncrementalBackupTableSet();<a name="line.337"></a>
-<span class="sourceLineNo">338</span>    // filter missing files out (they have been copied by previous backups)<a name="line.338"></a>
-<span class="sourceLineNo">339</span>    incrBackupFileList = filterMissingFiles(incrBackupFileList);<a name="line.339"></a>
-<span class="sourceLineNo">340</span>    for (TableName table : tableSet) {<a name="line.340"></a>
-<span class="sourceLineNo">341</span>      // Check if table exists<a name="line.341"></a>
-<span class="sourceLineNo">342</span>      if (tableExists(table, conn)) {<a name="line.342"></a>
-<span class="sourceLineNo">343</span>        walToHFiles(incrBackupFileList, table);<a name="line.343"></a>
-<span class="sourceLineNo">344</span>      } else {<a name="line.344"></a>
-<span class="sourceLineNo">345</span>        LOG.warn("Table " + table + " does not exists. Skipping in WAL converter");<a name="line.345"></a>
-<span class="sourceLineNo">346</span>      }<a name="line.346"></a>
-<span class="sourceLineNo">347</span>    }<a name="line.347"></a>
-<span class="sourceLineNo">348</span>  }<a name="line.348"></a>
-<span class="sourceLineNo">349</span><a name="line.349"></a>
-<span class="sourceLineNo">350</span><a name="line.350"></a>
-<span class="sourceLineNo">351</span>  protected boolean tableExists(TableName table, Connection conn) throws IOException {<a name="line.351"></a>
-<span class="sourceLineNo">352</span>    try (Admin admin = conn.getAdmin()) {<a name="line.352"></a>
-<span class="sourceLineNo">353</span>      return admin.tableExists(table);<a name="line.353"></a>
-<span class="sourceLineNo">354</span>    }<a name="line.354"></a>
-<span class="sourceLineNo">355</span>  }<a name="line.355"></a>
-<span class="sourceLineNo">356</span><a name="line.356"></a>
-<span class="sourceLineNo">357</span>  protected void walToHFiles(List&lt;String&gt; dirPaths, TableName tableName) throws IOException {<a name="line.357"></a>
-<span class="sourceLineNo">358</span><a name="line.358"></a>
-<span class="sourceLineNo">359</span>    Tool player = new WALPlayer();<a name="line.359"></a>
-<span class="sourceLineNo">360</span><a name="line.360"></a>
-<span class="sourceLineNo">361</span>    // Player reads all files in arbitrary directory structure and creates<a name="line.361"></a>
-<span class="sourceLineNo">362</span>    // a Map task for each file. We use ';' as separator<a name="line.362"></a>
-<span class="sourceLineNo">363</span>    // because WAL file names contains ','<a name="line.363"></a>
-<span class="sourceLineNo">364</span>    String dirs = StringUtils.join(dirPaths, ';');<a name="line.364"></a>
-<span class="sourceLineNo">365</span>    String jobname = "Incremental_Backup-" + backupId + "-" + tableName.getNameAsString();<a name="line.365"></a>
-<span class="sourceLineNo">366</span><a name="line.366"></a>
-<span class="sourceLineNo">367</span>    Path bulkOutputPath = getBulkOutputDirForTable(tableName);<a name="line.367"></a>
-<span class="sourceLineNo">368</span>    conf.set(WALPlayer.BULK_OUTPUT_CONF_KEY, bulkOutputPath.toString());<a name="line.368"></a>
-<span class="sourceLineNo">369</span>    conf.set(WALPlayer.INPUT_FILES_SEPARATOR_KEY, ";");<a name="line.369"></a>
-<span class="sourceLineNo">370</span>    conf.set(JOB_NAME_CONF_KEY, jobname);<a name="line.370"></a>
-<span class="sourceLineNo">371</span>    String[] playerArgs = { dirs, tableName.getNameAsString() };<a name="line.371"></a>
-<span class="sourceLineNo">372</span><a name="line.372"></a>
-<span class="sourceLineNo">373</span>    try {<a name="line.373"></a>
-<span class="sourceLineNo">374</span>      player.setConf(conf);<a name="line.374"></a>
-<span class="sourceLineNo">375</span>      int result = player.run(playerArgs);<a name="line.375"></a>
-<span class="sourceLineNo">376</span>      if(result != 0) {<a name="line.376"></a>
-<span class="sourceLineNo">377</span>        throw new IOException("WAL Player failed");<a name="line.377"></a>
-<span class="sourceLineNo">378</span>      }<a name="line.378"></a>
-<span class="sourceLineNo">379</span>      conf.unset(WALPlayer.INPUT_FILES_SEPARATOR_KEY);<a name="line.379"></a>
-<span class="sourceLineNo">380</span>      conf.unset(JOB_NAME_CONF_KEY);<a name="line.380"></a>
-<span class="sourceLineNo">381</span>    } catch (IOException e) {<a name="line.381"></a>
-<span class="sourceLineNo">382</span>      throw e;<a name="line.382"></a>
-<span class="sourceLineNo">383</span>    } catch (Exception ee) {<a name="line.383"></a>
-<span class="sourceLineNo">384</span>      throw new IOException("Can not convert from directory " + dirs<a name="line.384"></a>
-<span class="sourceLineNo">385</span>          + " (check Hadoop, HBase and WALPlayer M/R job logs) ", ee);<a name="line.385"></a>
+<span class="sourceLineNo">333</span>    try {<a name="line.333"></a>
+<span class="sourceLineNo">334</span>      LOG.debug("Incremental copy HFiles is starting. dest="+backupDest);<a name="line.334"></a>
+<span class="sourceLineNo">335</span>      // set overall backup phase: incremental_copy<a name="line.335"></a>
+<span class="sourceLineNo">336</span>      backupInfo.setPhase(BackupPhase.INCREMENTAL_COPY);<a name="line.336"></a>
+<span class="sourceLineNo">337</span>      // get incremental backup file list and prepare parms for DistCp<a name="line.337"></a>
+<span class="sourceLineNo">338</span>      String[] strArr = new String[files.length + 1];<a name="line.338"></a>
+<span class="sourceLineNo">339</span>      System.arraycopy(files, 0, strArr, 0, files.length);<a name="line.339"></a>
+<span class="sourceLineNo">340</span>      strArr[strArr.length - 1] = backupDest;<a name="line.340"></a>
+<span class="sourceLineNo">341</span><a name="line.341"></a>
+<span class="sourceLineNo">342</span>      String jobname = "Incremental_Backup-HFileCopy-" + backupInfo.getBackupId();<a name="line.342"></a>
+<span class="sourceLineNo">343</span>      if (LOG.isDebugEnabled()) {<a name="line.343"></a>
+<span class="sourceLineNo">344</span>        LOG.debug("Setting incremental copy HFiles job name to : " + jobname);<a name="line.344"></a>
+<span class="sourceLineNo">345</span>      }<a name="line.345"></a>
+<span class="sourceLineNo">346</span>      conf.set(JOB_NAME_CONF_KEY, jobname);<a name="line.346"></a>
+<span class="sourceLineNo">347</span><a name="line.347"></a>
+<span class="sourceLineNo">348</span>      BackupCopyJob copyService = BackupRestoreFactory.getBackupCopyJob(conf);<a name="line.348"></a>
+<span class="sourceLineNo">349</span>      int res = copyService.copy(backupInfo, backupManager, conf, BackupType.INCREMENTAL, strArr);<a name="line.349"></a>
+<span class="sourceLineNo">350</span>      if (res != 0) {<a name="line.350"></a>
+<span class="sourceLineNo">351</span>        LOG.error("Copy incremental HFile files failed with return code: " + res + ".");<a name="line.351"></a>
+<span class="sourceLineNo">352</span>        throw new IOException("Failed copy from " + StringUtils.join(files, ',')<a name="line.352"></a>
+<span class="sourceLineNo">353</span>            + " to " + backupDest);<a name="line.353"></a>
+<span class="sourceLineNo">354</span>      }<a name="line.354"></a>
+<span class="sourceLineNo">355</span>      LOG.debug("Incremental copy HFiles from " + StringUtils.join(files, ',')<a name="line.355"></a>
+<span class="sourceLineNo">356</span>          + " to " + backupDest + " finished.");<a name="line.356"></a>
+<span class="sourceLineNo">357</span>    } finally {<a name="line.357"></a>
+<span class="sourceLineNo">358</span>      deleteBulkLoadDirectory();<a name="line.358"></a>
+<span class="sourceLineNo">359</span>    }<a name="line.359"></a>
+<span class="sourceLineNo">360</span>  }<a name="line.360"></a>
+<span class="sourceLineNo">361</span><a name="line.361"></a>
+<span class="sourceLineNo">362</span>  protected void deleteBulkLoadDirectory() throws IOException {<a name="line.362"></a>
+<span class="sourceLineNo">363</span>    // delete original bulk load directory on method exit<a name="line.363"></a>
+<span class="sourceLineNo">364</span>    Path path = getBulkOutputDir();<a name="line.364"></a>
+<span class="sourceLineNo">365</span>    boolean result = fs.delete(path, true);<a name="line.365"></a>
+<span class="sourceLineNo">366</span>    if (!result) {<a name="line.366"></a>
+<span class="sourceLineNo">367</span>      LOG.warn("Could not delete " + path);<a name="line.367"></a>
+<span class="sourceLineNo">368</span>    }<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>  protected void convertWALsToHFiles() throws IOException {<a name="line.372"></a>
+<span class="sourceLineNo">373</span>    // get incremental backup file list and prepare parameters for DistCp<a name="line.373"></a>
+<span class="sourceLineNo">374</span>    List&lt;String&gt; incrBackupFileList = backupInfo.getIncrBackupFileList();<a name="line.374"></a>
+<span class="sourceLineNo">375</span>    // Get list of tables in incremental backup set<a name="line.375"></a>
+<span class="sourceLineNo">376</span>    Set&lt;TableName&gt; tableSet = backupManager.getIncrementalBackupTableSet();<a name="line.376"></a>
+<span class="sourceLineNo">377</span>    // filter missing files out (they have been copied by previous backups)<a name="line.377"></a>
+<span class="sourceLineNo">378</span>    incrBackupFileList = filterMissingFiles(incrBackupFileList);<a name="line.378"></a>
+<span class="sourceLineNo">379</span>    for (TableName table : tableSet) {<a name="line.379"></a>
+<span class="sourceLineNo">380</span>      // Check if table exists<a name="line.380"></a>
+<span class="sourceLineNo">381</span>      if (tableExists(table, conn)) {<a name="line.381"></a>
+<span class="sourceLineNo">382</span>        walToHFiles(incrBackupFileList, table);<a name="line.382"></a>
+<span class="sourceLineNo">383</span>      } else {<a name="line.383"></a>
+<span class="sourceLineNo">384</span>        LOG.warn("Table " + table + " does not exists. Skipping in WAL converter");<a name="line.384"></a>
+<span class="sourceLineNo">385</span>      }<a name="line.385"></a>
 <span class="sourceLineNo">386</span>    }<a name="line.386"></a>
 <span class="sourceLineNo">387</span>  }<a name="line.387"></a>
 <span class="sourceLineNo">388</span><a name="line.388"></a>
-<span class="sourceLineNo">389</span>  protected Path getBulkOutputDirForTable(TableName table) {<a name="line.389"></a>
-<span class="sourceLineNo">390</span>    Path tablePath = getBulkOutputDir();<a name="line.390"></a>
-<span class="sourceLineNo">391</span>    tablePath = new Path(tablePath, table.getNamespaceAsString());<a name="line.391"></a>
-<span class="sourceLineNo">392</span>    tablePath = new Path(tablePath, table.getQualifierAsString());<a name="line.392"></a>
-<span class="sourceLineNo">393</span>    return new Path(tablePath, "data");<a name="line.393"></a>
+<span class="sourceLineNo">389</span><a name="line.389"></a>
+<span class="sourceLineNo">390</span>  protected boolean tableExists(TableName table, Connection conn) throws IOException {<a name="line.390"></a>
+<span class="sourceLineNo">391</span>    try (Admin admin = conn.getAdmin()) {<a name="line.391"></a>
+<span class="sourceLineNo">392</span>      return admin.tableExists(table);<a name="line.392"></a>
+<span class="sourceLineNo">393</span>    }<a name="line.393"></a>
 <span class="sourceLineNo">394</span>  }<a name="line.394"></a>
 <span class="sourceLineNo">395</span><a name="line.395"></a>
-<span class="sourceLineNo">396</span>  protected Path getBulkOutputDir() {<a name="line.396"></a>
-<span class="sourceLineNo">397</span>    String backupId = backupInfo.getBackupId();<a name="line.397"></a>
-<span class="sourceLineNo">398</span>    Path path = new Path(backupInfo.getBackupRootDir());<a name="line.398"></a>
-<span class="sourceLineNo">399</span>    path = new Path(path, ".tmp");<a name="line.399"></a>
-<span class="sourceLineNo">400</span>    path = new Path(path, backupId);<a name="line.400"></a>
-<span class="sourceLineNo">401</span>    return path;<a name="line.401"></a>
-<span class="sourceLineNo">402</span>  }<a name="line.402"></a>
-<span class="sourceLineNo">403</span><a name="line.403"></a>
-<span class="sourceLineNo">404</span>}<a name="line.404"></a>
+<span class="sourceLineNo">396</span>  protected void walToHFiles(List&lt;String&gt; dirPaths, TableName tableName) throws IOException {<a name="line.396"></a>
+<span class="sourceLineNo">397</span><a name="line.397"></a>
+<span class="sourceLineNo">398</span>    Tool player = new WALPlayer();<a name="line.398"></a>
+<span class="sourceLineNo">399</span><a name="line.399"></a>
+<span class="sourceLineNo">400</span>    // Player reads all files in arbitrary directory structure and creates<a name="line.400"></a>
+<span class="sourceLineNo">401</span>    // a Map task for each file. We use ';' as separator<a name="line.401"></a>
+<span class="sourceLineNo">402</span>    // because WAL file names contains ','<a name="line.402"></a>
+<span class="sourceLineNo">403</span>    String dirs = StringUtils.join(dirPaths, ';');<a name="line.403"></a>
+<span class="sourceLineNo">404</span>    String jobname = "Incremental_Backup-" + backupId + "-" + tableName.getNameAsString();<a name="line.404"></a>
+<span class="sourceLineNo">405</span><a name="line.405"></a>
+<span class="sourceLineNo">406</span>    Path bulkOutputPath = getBulkOutputDirForTable(tableName);<a name="line.406"></a>
+<span class="sourceLineNo">407</span>    conf.set(WALPlayer.BULK_OUTPUT_CONF_KEY, bulkOutputPath.toString());<a name="line.407"></a>
+<span class="sourceLineNo">408</span>    conf.set(WALPlayer.INPUT_FILES_SEPARATOR_KEY, ";");<a name="line.408"></a>
+<span class="sourceLineNo">409</span>    conf.set(JOB_NAME_CONF_KEY, jobname);<a name="line.409"></a>
+<span class="sourceLineNo">410</span>    String[] playerArgs = { dirs, tableName.getNameAsString() };<a name="line.410"></a>
+<span class="sourceLineNo">411</span><a name="line.411"></a>
+<span class="sourceLineNo">412</span>    try {<a name="line.412"></a>
+<span class="sourceLineNo">413</span>      player.setConf(conf);<a name="line.413"></a>
+<span class="sourceLineNo">414</span>      int result = player.run(playerArgs);<a name="line.414"></a>
+<span class="sourceLineNo">415</span>      if(result != 0) {<a name="line.415"></a>
+<span class="sourceLineNo">416</span>        throw new IOException("WAL Player failed");<a name="line.416"></a>
+<span class="sourceLineNo">417</span>      }<a name="line.417"></a>
+<span class="sourceLineNo">418</span>      conf.unset(WALPlayer.INPUT_FILES_SEPARATOR_KEY);<a name="line.418"></a>
+<span class="sourceLineNo">419</span>      conf.unset(JOB_NAME_CONF_KEY);<a name="line.419"></a>
+<span class="sourceLineNo">420</span>    } catch (IOException e) {<a name="line.420"></a>
+<span class="sourceLineNo">421</span>      throw e;<a name="line.421"></a>
+<span class="sourceLineNo">422</span>    } catch (Exception ee) {<a name="line.422"></a>
+<span class="sourceLineNo">423</span>      throw new IOException("Can not convert from directory " + dirs<a name="line.423"></a>
+<span class="sourceLineNo">424</span>          + " (check Hadoop, HBase and WALPlayer M/R job logs) ", ee);<a name="line.424"></a>
+<span class="sourceLineNo">425</span>    }<a name="line.425"></a>
+<span class="sourceLineNo">426</span>  }<a name="line.426"></a>
+<span class="sourceLineNo">427</span><a name="line.427"></a>
+<span class="sourceLineNo">428</span>  protected Path getBulkOutputDirForTable(TableName table) {<a name="line.428"></a>
+<span class="sourceLineNo">429</span>    Path tablePath = getBulkOutputDir();<a name="line.429"></a>
+<span class="sourceLineNo">430</span>    tablePath = new Path(tablePath, table.getNamespaceAsString());<a name="line.430"></a>
+<span class="sourceLineNo">431</span>    tablePath = new Path(tablePath, table.getQualifierAsString());<a name="line.431"></a>
+<span class="sourceLineNo">432</span>    return new Path(tablePath, "data");<a name="line.432"></a>
+<span class="sourceLineNo">433</span>  }<a name="line.433"></a>
+<span class="sourceLineNo">434</span><a name="line.434"></a>
+<span class="sourceLineNo">435</span>  protected Path getBulkOutputDir() {<a name="line.435"></a>
+<span class="sourceLineNo">436</span>    String backupId = backupInfo.getBackupId();<a name="line.436"></a>
+<span class="sourceLineNo">437</span>    Path path = new Path(backupInfo.getBackupRootDir());<a name="line.437"></a>
+<span class="sourceLineNo">438</span>    path = new Path(path, ".tmp");<a name="line.438"></a>
+<span class="sourceLineNo">439</span>    path = new Path(path, backupId);<a name="line.439"></a>
+<span class="sourceLineNo">440</span>    return path;<a name="line.440"></a>
+<span class="sourceLineNo">441</span>  }<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>
 
 
 


Mime
View raw message