HBASE-20668 Avoid permission change if ExportSnapshot's copy fails

Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/74ef118e
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/74ef118e
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/74ef118e

Branch: refs/heads/HBASE-20331
Commit: 74ef118e9e2246c09280ebb7eb6552ef91bdd094
Parents: a11701e
Author: tedyu <[email protected]>
Authored: Fri Jun 1 14:34:51 2018 -0700
Committer: tedyu <[email protected]>
Committed: Fri Jun 1 14:34:51 2018 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/snapshot/ExportSnapshot.java   | 26 +++++++++++---------
 1 file changed, 15 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/74ef118e/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java
----------------------------------------------------------------------
diff --git 
a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java
 
b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java
index 4af7dfb..f75a479 100644
--- 
a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java
+++ 
b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java
@@ -1027,25 +1027,29 @@ public class ExportSnapshot extends AbstractHBaseTool 
implements Tool {
     // The snapshot references must be copied before the hfiles otherwise the 
cleaner
     // will remove them because they are unreferenced.
     List<Path> travesedPaths = new ArrayList<>();
+    boolean copySucceeded = false;
     try {
-      LOG.info("Copy Snapshot Manifest");
+      LOG.info("Copy Snapshot Manifest from " + snapshotDir + " to " + 
initialOutputSnapshotDir);
       travesedPaths =
           FSUtils.copyFilesParallel(inputFs, snapshotDir, outputFs, 
initialOutputSnapshotDir, conf,
               conf.getInt(CONF_COPY_MANIFEST_THREADS, 
DEFAULT_COPY_MANIFEST_THREADS));
+      copySucceeded = true;
     } catch (IOException e) {
       throw new ExportSnapshotException("Failed to copy the snapshot 
directory: from=" +
         snapshotDir + " to=" + initialOutputSnapshotDir, e);
     } finally {
-      if (filesUser != null || filesGroup != null) {
-        LOG.warn((filesUser == null ? "" : "Change the owner of " + 
needSetOwnerDir + " to "
-            + filesUser)
-            + (filesGroup == null ? "" : ", Change the group of " + 
needSetOwnerDir + " to "
-            + filesGroup));
-        setOwnerParallel(outputFs, filesUser, filesGroup, conf, travesedPaths);
-      }
-      if (filesMode > 0) {
-        LOG.warn("Change the permission of " + needSetOwnerDir + " to " + 
filesMode);
-        setPermissionParallel(outputFs, (short)filesMode, travesedPaths, conf);
+      if (copySucceeded) {
+        if (filesUser != null || filesGroup != null) {
+          LOG.warn((filesUser == null ? "" : "Change the owner of " + 
needSetOwnerDir + " to "
+              + filesUser)
+              + (filesGroup == null ? "" : ", Change the group of " + 
needSetOwnerDir + " to "
+                  + filesGroup));
+          setOwnerParallel(outputFs, filesUser, filesGroup, conf, 
travesedPaths);
+        }
+        if (filesMode > 0) {
+          LOG.warn("Change the permission of " + needSetOwnerDir + " to " + 
filesMode);
+          setPermissionParallel(outputFs, (short)filesMode, travesedPaths, 
conf);
+        }
       }
     }
 

Reply via email to