gvprathyusha6 commented on code in PR #8248:
URL: https://github.com/apache/hbase/pull/8248#discussion_r3475884984


##########
hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/MapreduceRestoreSnapshotHelper.java:
##########
@@ -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.
+ */
[email protected]
+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 {

Review Comment:
   If it is only adding these checks, why not remove the 
MapreduceRestoreSnapshotHelper, we can just send in the right Archiver itself 
know?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to