hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-13250 chown of ExportSnapshot does not cover all path and files (He Liangliang)
Date Wed, 16 Sep 2015 20:07:06 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.1 ddf2d4b06 -> a1f45c1c4


HBASE-13250 chown of ExportSnapshot does not cover all path and files (He Liangliang)


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

Branch: refs/heads/branch-1.1
Commit: a1f45c1c43dfda4b044f948d4de5089662aa306b
Parents: ddf2d4b
Author: tedyu <yuzhihong@gmail.com>
Authored: Wed Sep 16 13:06:58 2015 -0700
Committer: tedyu <yuzhihong@gmail.com>
Committed: Wed Sep 16 13:06:58 2015 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/snapshot/ExportSnapshot.java   | 37 +++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/a1f45c1c/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 5021c74..e1c0b52 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
@@ -271,7 +271,7 @@ public class ExportSnapshot extends Configured implements Tool {
         context.getCounter(Counter.BYTES_EXPECTED).increment(inputStat.getLen());
 
         // Ensure that the output folder is there and copy the file
-        outputFs.mkdirs(outputPath.getParent());
+        createOutputPath(outputPath.getParent());
         FSDataOutputStream out = outputFs.create(outputPath, true);
         try {
           copyData(context, inputStat.getPath(), in, outputPath, out, inputStat.getLen());
@@ -289,6 +289,23 @@ public class ExportSnapshot extends Configured implements Tool {
     }
 
     /**
+     * Create the output folder and optionally set ownership.
+     */
+    private void createOutputPath(final Path path) throws IOException {
+      if (filesUser == null && filesGroup == null) {
+        outputFs.mkdirs(path);
+      } else {
+        Path parent = path.getParent();
+        if (!outputFs.exists(parent) && !parent.isRoot()) {
+          createOutputPath(parent);
+        }
+        outputFs.mkdirs(path);
+        // override the owner when non-null user/group is specified
+        outputFs.setOwner(path, filesUser, filesGroup);
+      }
+    }
+
+    /**
      * Try to Preserve the files attribute selected by the user copying them from the source
file
      * This is only required when you are exporting as a different user than "hbase" or on
a system
      * that doesn't have the "hbase" user.
@@ -794,6 +811,21 @@ public class ExportSnapshot extends Configured implements Tool {
   }
 
   /**
+   * Set path ownership.
+   */
+  private void setOwner(final FileSystem fs, final Path path, final String user,
+      final String group, final boolean recursive) throws IOException {
+    if (user != null || group != null) {
+      if (recursive && fs.isDirectory(path)) {
+        for (FileStatus child : fs.listStatus(path)) {
+          setOwner(fs, child.getPath(), user, group, recursive);
+        }
+      }
+      fs.setOwner(path, user, group);
+    }
+  }
+
+  /**
    * Execute the export snapshot by copying the snapshot metadata, hfiles and wals.
    * @return 0 on success, and != 0 upon failure.
    */
@@ -916,6 +948,9 @@ public class ExportSnapshot extends Configured implements Tool {
     try {
       LOG.info("Copy Snapshot Manifest");
       FileUtil.copy(inputFs, snapshotDir, outputFs, initialOutputSnapshotDir, false, false,
conf);
+      if (filesUser != null || filesGroup != null) {
+        setOwner(outputFs, snapshotTmpDir, filesUser, filesGroup, true);
+      }
     } catch (IOException e) {
       throw new ExportSnapshotException("Failed to copy the snapshot directory: from=" +
         snapshotDir + " to=" + initialOutputSnapshotDir, e);


Mime
View raw message