You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by mb...@apache.org on 2016/10/25 21:17:23 UTC

[3/4] hbase git commit: HBASE-16939 ExportSnapshot: set owner and permission on right directory

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

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


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

Branch: refs/heads/branch-1.2
Commit: 6542d651bf4c612f9e1e7b328dbea07eca1a5ae0
Parents: 7f10379
Author: Guanghao Zhang <zg...@gmail.com>
Authored: Tue Oct 25 10:36:55 2016 +0800
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Tue Oct 25 14:13:49 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/6542d651/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 f1c833e..ff5632d 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
@@ -944,6 +944,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) {
@@ -981,15 +994,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