Skip to content

Commit

Permalink
HBASE-26720 ExportSnapshot should validate the source snapshot before…
Browse files Browse the repository at this point in the history
… copying files (#4216)

Signed-off-by: Andrew Purtell <apurtell@apache.org>
Signed-off-by: Xiaolin Ha <haxiaolin@apache.org>
  • Loading branch information
xicm authored and sunhelly committed Mar 16, 2022
1 parent 4ff63f6 commit 4f3decd
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ static final class Options {
"Do not verify checksum, use name+length only.");
static final Option NO_TARGET_VERIFY = new Option(null, "no-target-verify", false,
"Do not verify the integrity of the exported snapshot.");
static final Option NO_SOURCE_VERIFY = new Option(null, "no-source-verify", false,
"Do not verify the source of the snapshot.");
static final Option OVERWRITE = new Option(null, "overwrite", false,
"Rewrite the snapshot manifest if already exists.");
static final Option CHUSER = new Option(null, "chuser", true,
Expand Down Expand Up @@ -903,6 +905,7 @@ private void setPermissionParallel(final FileSystem outputFs, final short filesM
}

private boolean verifyTarget = true;
private boolean verifySource = true;
private boolean verifyChecksum = true;
private String snapshotName = null;
private String targetName = null;
Expand Down Expand Up @@ -934,6 +937,7 @@ protected void processOptions(CommandLine cmd) {
// And verifyChecksum and verifyTarget with values read from old args in processOldArgs(...).
verifyChecksum = !cmd.hasOption(Options.NO_CHECKSUM_VERIFY.getLongOpt());
verifyTarget = !cmd.hasOption(Options.NO_TARGET_VERIFY.getLongOpt());
verifySource = !cmd.hasOption(Options.NO_SOURCE_VERIFY.getLongOpt());
}

/**
Expand Down Expand Up @@ -984,6 +988,13 @@ public int doWork() throws IOException {
LOG.debug("outputFs={}, outputRoot={}, skipTmp={}, initialOutputSnapshotDir={}",
outputFs, outputRoot.toString(), skipTmp, initialOutputSnapshotDir);

// Verify snapshot source before copying files
if (verifySource) {
LOG.info("Verify snapshot source, inputFs={}, inputRoot={}, snapshotDir={}.",
inputFs.getUri(), inputRoot, snapshotDir);
verifySnapshot(srcConf, inputFs, inputRoot, snapshotDir);
}

// Find the necessary directory which need to change owner and group
Path needSetOwnerDir = SnapshotDescriptionUtils.getSnapshotRootDir(outputRoot);
if (outputFs.exists(needSetOwnerDir)) {
Expand Down Expand Up @@ -1134,6 +1145,7 @@ protected void printUsage() {
addOption(Options.TARGET_NAME);
addOption(Options.NO_CHECKSUM_VERIFY);
addOption(Options.NO_TARGET_VERIFY);
addOption(Options.NO_SOURCE_VERIFY);
addOption(Options.OVERWRITE);
addOption(Options.CHUSER);
addOption(Options.CHGROUP);
Expand Down

0 comments on commit 4f3decd

Please sign in to comment.