Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3906718711 for ; Wed, 16 Sep 2015 20:07:07 +0000 (UTC) Received: (qmail 56322 invoked by uid 500); 16 Sep 2015 20:07:07 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 56283 invoked by uid 500); 16 Sep 2015 20:07:07 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 56271 invoked by uid 99); 16 Sep 2015 20:07:06 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Sep 2015 20:07:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B473AE0243; Wed, 16 Sep 2015 20:07:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tedyu@apache.org To: commits@hbase.apache.org Message-Id: <8a0c8714b31a4279971cfd088170a6ba@git.apache.org> X-Mailer: ASF-Git Admin Mailer 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 +0000 (UTC) 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 Authored: Wed Sep 16 13:06:58 2015 -0700 Committer: tedyu 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);