jojochuang commented on code in PR #11017:
URL: https://github.com/apache/ozone/pull/11017#discussion_r3781602138


##########
hadoop-ozone/cli-repair/src/main/java/org/apache/hadoop/ozone/repair/om/DownloadOMDB.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.ozone.repair.om;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_DB_CHECKPOINT_USE_INODE_BASED_KEY;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import org.apache.commons.io.FileUtils;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.utils.db.DBCheckpoint;
+import org.apache.hadoop.ozone.OmUtils;
+import org.apache.hadoop.ozone.om.helpers.OMNodeDetails;
+import org.apache.hadoop.ozone.om.ratis_snapshot.OmRatisSnapshotProvider;
+import org.apache.hadoop.ozone.repair.RepairTool;
+import picocli.CommandLine;
+
+/**
+ * Tool to download and construct OM DB using follower bootstrap flow.
+ */
[email protected](
+    name = "download",
+    description = "Downloads and constructs om.db from an OM node using the 
same checkpoint transfer flow as follower bootstrap.",
+    mixinStandardHelpOptions = true,
+    versionProvider = HddsVersionProvider.class
+)
+public class DownloadOMDB extends RepairTool {
+
+  @CommandLine.Option(
+      names = {"--service-id", "--om-service-id"},
+      description = "Ozone Manager Service ID",
+      required = false
+  )
+  private String omServiceId;
+
+  @CommandLine.Option(
+      names = {"--node-id"},
+      description = "Node ID of the OM to download om.db from. Required when 
OM HA is configured.",
+      required = false
+  )
+  private String nodeId;
+
+  @CommandLine.Option(
+      names = {"--output-dir"},
+      description = "Path where the constructed om.db directory will be 
written.",
+      required = true
+  )
+  private Path outputDir;
+
+  @CommandLine.Option(
+      names = {"--overwrite"},
+      description = "Overwrite output directory if it already exists."
+  )
+  private boolean overwrite;
+
+  @Override
+  public void execute() throws Exception {
+    OzoneConfiguration conf = getOzoneConf();
+
+    if (nodeId == null && OmUtils.isServiceIdsDefined(conf)) {
+      error("This is an HA OM cluster; specify --node-id to select which OM to 
download from.");
+      return;
+    }
+
+    OMNodeDetails omNodeDetails =
+        OMNodeDetails.getOMNodeDetailsFromConf(conf, omServiceId, nodeId);
+    if (omNodeDetails == null) {
+      error("Couldn't determine OM node from the given service-id: %s and 
node-id: %s.",
+          omServiceId, nodeId);
+      return;
+    }
+
+    if (Files.exists(outputDir)) {
+      if (!overwrite) {
+        error("Output directory already exists: %s. Use --overwrite to replace 
it.",
+            outputDir.toAbsolutePath());
+        return;
+      }
+      FileUtils.forceDelete(outputDir.toFile());
+    }
+    Path parent = outputDir.toAbsolutePath().getParent();
+    if (parent != null) {
+      Files.createDirectories(parent);
+    }
+
+    // This tool intentionally follows the inode-based follower bootstrap 
transfer.
+    conf.setBoolean(OZONE_OM_DB_CHECKPOINT_USE_INODE_BASED_KEY, true);
+
+    Path snapshotWorkDir = Files.createTempDirectory("ozone-omdb-bootstrap-");
+    DBCheckpoint checkpoint = null;
+    try (OmRatisSnapshotProvider provider = new OmRatisSnapshotProvider(
+        conf, snapshotWorkDir.toFile(),
+        Collections.singletonMap(omNodeDetails.getNodeId(), omNodeDetails))) {
+      checkpoint = 
provider.downloadDBSnapshotFromLeader(omNodeDetails.getNodeId());
+      Path omDbPath = checkpoint.getCheckpointLocation().resolve(OM_DB_NAME);
+      if (!Files.isDirectory(omDbPath)) {
+        throw new IOException("Constructed OM DB directory not found in 
checkpoint: " + omDbPath);
+      }
+      FileUtils.moveDirectory(omDbPath.toFile(), outputDir.toFile());
+      info("Successfully downloaded and constructed om.db at: %s",
+          outputDir.toAbsolutePath());

Review Comment:
   Fixed in the next commit



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to