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/288ea316 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/288ea316 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/288ea316 Branch: refs/heads/branch-1.1 Commit: 288ea316be7039c9361ffba7061d6a68154e633c Parents: f4cbf77 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:14:54 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/288ea316/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 9d0f760..bf4810f 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 @@ -932,6 +932,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) { @@ -969,15 +982,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