-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-29435 Add MapreduceRestoreSnapshotHelper.java to guard against accidental data loss #8248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SwaraliJoshi
wants to merge
4
commits into
apache:master
Choose a base branch
from
SwaraliJoshi:W-22336363-hbase-29435-limit-hfile-actions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2c76178
HBASE-29435 Prevent MapReduce jobs from operating on production HBase…
SwaraliJoshi e0017cb
Added MapreduceHfileArchiver.java to hbase-mapreduce module
SwaraliJoshi 102d0e6
HBASE-29435 Guard MapReduce snapshot restore via injectable archiver
SwaraliJoshi 6f1acc4
HBASE-29435 Address review feedback on MapReduce snapshot restore guard
SwaraliJoshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...educe/src/main/java/org/apache/hadoop/hbase/mapreduce/MapreduceRestoreSnapshotHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.hbase.mapreduce; | ||
|
|
||
| import java.io.IOException; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper; | ||
| import org.apache.hadoop.hbase.util.MapreduceHFileArchiver; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| /** | ||
| * MapReduce entry point for restoring a snapshot into a temporary directory for scanning. | ||
| * <p> | ||
| * This is a thin wrapper around {@link RestoreSnapshotHelper}: it adds a MapReduce-specific safety | ||
| * guard that prevents the restore directory from pointing at (or under) the live HBase root | ||
| * directory, then delegates the actual restore/clone to {@link RestoreSnapshotHelper}, injecting | ||
| * the MapReduce-local {@link MapreduceHFileArchiver} so that no core restore logic is duplicated | ||
| * here. | ||
| * <p> | ||
| * The extra guard matters because a misconfigured {@code restoreDir} under | ||
| * {@code hbase.rootdir/data} would let the MapReduce job archive (and ultimately delete) production | ||
| * HFiles. The server-side restore/clone procedures legitimately operate against the production root | ||
| * directory, so this stricter validation is layered only on the MapReduce path rather than in | ||
| * {@link RestoreSnapshotHelper} itself. See HBASE-29435. | ||
| */ | ||
| @InterfaceAudience.Private | ||
| public final class MapreduceRestoreSnapshotHelper { | ||
|
|
||
| private MapreduceRestoreSnapshotHelper() { | ||
| } | ||
|
|
||
| /** | ||
| * Copy the snapshot files for a snapshot scanner. | ||
| * <p> | ||
| * Rejects a {@code restoreDir} that equals or is nested under {@code rootDir} (compared as | ||
| * fully-qualified paths), and a {@code fs} that does not host {@code rootDir}, before delegating | ||
| * to {@link RestoreSnapshotHelper#copySnapshotForScanner}, which performs the restore using the | ||
| * MapReduce-local archiver. | ||
| */ | ||
| public static void copySnapshotForScanner(Configuration conf, FileSystem fs, Path rootDir, | ||
| Path restoreDir, String snapshotName) throws IOException { | ||
| // The provided filesystem must host the HBase root directory; otherwise the path comparison | ||
| // below is meaningless and a restore could archive files across filesystems (HBASE-29435). | ||
| FileSystem rootDirFs = rootDir.getFileSystem(conf); | ||
| if (!fs.getUri().equals(rootDirFs.getUri())) { | ||
| throw new IllegalArgumentException("BLOCKED: MapReduce restore filesystem " + fs.getUri() | ||
| + " does not match the HBase root directory filesystem " + rootDirFs.getUri() | ||
| + ". Use the HBase root filesystem for MR snapshot scanning."); | ||
| } | ||
| // Compare fully-qualified paths (scheme + authority + path) so that trailing slashes or | ||
| // authority differences cannot slip a production path past the guard. | ||
| String rootPath = fs.makeQualified(rootDir).toString(); | ||
| String restorePath = fs.makeQualified(restoreDir).toString(); | ||
| if (restorePath.equals(rootPath) || restorePath.startsWith(rootPath + "/")) { | ||
| throw new IllegalArgumentException( | ||
| "BLOCKED: MapReduce restore directory cannot be the HBase root directory or a sub " | ||
| + "directory of it. This could lead to accidental archival and permanent data loss if " | ||
| + "the path falls under " + rootDir + "/data/. Use a temporary directory outside of " | ||
| + "hbase.rootdir for MR snapshot scanning. RootDir: " + rootDir + ", restoreDir: " | ||
| + restoreDir); | ||
| } | ||
| RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, restoreDir, snapshotName, | ||
| new MapreduceHFileArchiver()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,6 +145,9 @@ private void compactRegion(final Path tableDir, final TableDescriptor htd, final | |
| private void compactStoreFiles(final Path tableDir, final TableDescriptor htd, | ||
| final RegionInfo hri, final String familyName, final boolean compactOnce, final boolean major) | ||
| throws IOException { | ||
| // CompactionTool intentionally compacts, archives, and (optionally) deletes store files in | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think this is needed here |
||
| // the operator-supplied production path. Unlike the MR snapshot-scanning path, it is exempt | ||
| // from the HBASE-29435 guard: archiving/deleting production data here is its purpose. | ||
| HStore store = getStore(conf, fs, tableDir, htd, hri, familyName); | ||
| LOG.info("Compact table=" + htd.getTableName() + " region=" + hri.getRegionNameAsString() | ||
| + " family=" + familyName); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is only adding these checks, why not remove the MapreduceRestoreSnapshotHelper, we can just send in the right Archiver itself know?