HBASE-16939 ExportSnapshot: set owner and permission on right directory

Signed-off-by: Matteo Bertozzi <matteo.berto...@cloudera.com>


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

Branch: refs/heads/branch-1
Commit: 4edd8a63d2afa57a1c7029b2d6badeede8855097
Parents: ae502a9
Author: Guanghao Zhang <zghao...@gmail.com>
Authored: Tue Oct 25 10:36:55 2016 +0800
Committer: Matteo Bertozzi <matteo.berto...@cloudera.com>
Committed: Tue Oct 25 14:11:59 2016 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/snapshot/ExportSnapshot.java   | 29 ++++++++++++++++----
 1 file changed, 24 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/4edd8a63/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java
index 35ce2d7..89dcd37 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java
@@ -930,6 +930,19 @@ public class ExportSnapshot extends Configured implements 
Tool {
     Path outputSnapshotDir = 
SnapshotDescriptionUtils.getCompletedSnapshotDir(targetName, outputRoot);
     Path initialOutputSnapshotDir = skipTmp ? outputSnapshotDir : 
snapshotTmpDir;
 
+    // Find the necessary directory which need to change owner and group
+    Path needSetOwnerDir = 
SnapshotDescriptionUtils.getSnapshotRootDir(outputRoot);
+    if (outputFs.exists(needSetOwnerDir)) {
+      if (skipTmp) {
+        needSetOwnerDir = outputSnapshotDir;
+      } else {
+        needSetOwnerDir = 
SnapshotDescriptionUtils.getWorkingSnapshotDir(outputRoot);
+        if (outputFs.exists(needSetOwnerDir)) {
+          needSetOwnerDir = snapshotTmpDir;
+        }
+      }
+    }
+
     // Check if the snapshot already exists
     if (outputFs.exists(outputSnapshotDir)) {
       if (overwrite) {
@@ -967,15 +980,21 @@ public class ExportSnapshot extends Configured implements 
Tool {
     try {
       LOG.info("Copy Snapshot Manifest");
       FileUtil.copy(inputFs, snapshotDir, outputFs, initialOutputSnapshotDir, 
false, false, conf);
+    } catch (IOException e) {
+      throw new ExportSnapshotException("Failed to copy the snapshot 
directory: from=" +
+        snapshotDir + " to=" + initialOutputSnapshotDir, e);
+    } finally {
       if (filesUser != null || filesGroup != null) {
-        setOwner(outputFs, snapshotTmpDir, filesUser, filesGroup, true);
+        LOG.warn((filesUser == null ? "" : "Change the owner of " + 
needSetOwnerDir + " to "
+            + filesUser)
+            + (filesGroup == null ? "" : ", Change the group of " + 
needSetOwnerDir + " to "
+            + filesGroup));
+        setOwner(outputFs, needSetOwnerDir, filesUser, filesGroup, true);
       }
       if (filesMode > 0) {
-        setPermission(outputFs, snapshotTmpDir, (short)filesMode, true);
+        LOG.warn("Change the permission of " + needSetOwnerDir + " to " + 
filesMode);
+        setPermission(outputFs, needSetOwnerDir, (short)filesMode, true);
       }
-    } catch (IOException e) {
-      throw new ExportSnapshotException("Failed to copy the snapshot 
directory: from=" +
-        snapshotDir + " to=" + initialOutputSnapshotDir, e);
     }
 
     // Write a new .snapshotinfo if the target name is different from the 
source name

Reply via email to