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


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ReconRDBSnapshotProvider.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * 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.recon.spi.impl;
+
+import static java.net.HttpURLConnection.HTTP_CREATED;
+import static java.net.HttpURLConnection.HTTP_OK;
+import static org.apache.hadoop.ozone.OzoneConsts.MULTIPART_FORM_DATA_BOUNDARY;
+import static org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME;
+import static 
org.apache.hadoop.ozone.OzoneConsts.OZONE_DB_CHECKPOINT_HTTP_ENDPOINT;
+import static 
org.apache.hadoop.ozone.OzoneConsts.OZONE_DB_CHECKPOINT_HTTP_ENDPOINT_V2;
+import static 
org.apache.hadoop.ozone.OzoneConsts.OZONE_DB_CHECKPOINT_INCLUDE_SNAPSHOT_DATA;
+import static 
org.apache.hadoop.ozone.OzoneConsts.OZONE_DB_CHECKPOINT_REQUEST_FLUSH;
+import static 
org.apache.hadoop.ozone.recon.ReconConstants.RECON_OM_SNAPSHOT_DB;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.function.Supplier;
+import org.apache.commons.io.FileUtils;
+import org.apache.hadoop.hdds.server.http.HttpConfig;
+import org.apache.hadoop.hdds.utils.HAUtils;
+import org.apache.hadoop.hdds.utils.RDBSnapshotProvider;
+import org.apache.hadoop.hdds.utils.db.DBCheckpoint;
+import org.apache.hadoop.hdds.utils.db.InodeMetadataRocksDBCheckpoint;
+import org.apache.hadoop.hdds.utils.db.RocksDBCheckpoint;
+import org.apache.hadoop.hdfs.web.URLConnectionFactory;
+import org.apache.hadoop.ozone.om.helpers.ServiceInfo;
+import org.apache.hadoop.ozone.om.ratis_snapshot.OmRatisSnapshotProvider;
+import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ServicePort.Type;
+import org.apache.hadoop.security.SecurityUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Recon's {@link RDBSnapshotProvider} implementation that downloads the OM DB
+ * checkpoint using the same bootstrap mechanism an OM follower uses: a chunked
+ * {@code POST /v2/dbCheckpoint} request that carries a {@code toExcludeList[]}
+ * of the parts already received so an interrupted transfer can resume, with
+ * hard-link dedup on the leader and a completion sentinel to end the transfer.
+ *
+ * <p>This mirrors {@link OmRatisSnapshotProvider}: it overrides
+ * {@link #downloadSnapshot} to POST to the leader's {@code /v2/dbCheckpoint}
+ * endpoint and {@link #getCheckpointFromUntarredDb} to assemble and promote 
the
+ * downloaded DB into a stable snapshot dir Recon can open. Like the OM 
follower,
+ * it honors {@code ozone.om.db.checkpoint.use.inode.based.transfer}: when 
that is
+ * {@code false} it falls back to the v1 {@code /dbCheckpoint} endpoint.
+ */
+public class ReconRDBSnapshotProvider extends RDBSnapshotProvider {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(ReconRDBSnapshotProvider.class);
+
+  private final URLConnectionFactory connectionFactory;
+  private final boolean spnegoEnabled;
+  private final boolean httpsEnabled;
+  private final boolean flushBeforeCheckpoint;
+  private final boolean useV2CheckpointApi;
+  private final Supplier<ServiceInfo> leaderInfoSupplier;
+
+  public ReconRDBSnapshotProvider(File snapshotDir,
+      URLConnectionFactory connectionFactory, boolean spnegoEnabled,
+      HttpConfig.Policy httpPolicy, boolean flushBeforeCheckpoint,
+      boolean useV2CheckpointApi,
+      Supplier<ServiceInfo> leaderInfoSupplier) {
+    super(snapshotDir, RECON_OM_SNAPSHOT_DB);
+    this.connectionFactory = connectionFactory;
+    this.spnegoEnabled = spnegoEnabled;
+    this.httpsEnabled = httpPolicy.isHttpsEnabled();
+    this.flushBeforeCheckpoint = flushBeforeCheckpoint;
+    this.useV2CheckpointApi = useV2CheckpointApi;
+    this.leaderInfoSupplier = leaderInfoSupplier;
+  }
+
+  @Override
+  public void downloadSnapshot(String leaderNodeID, File targetFile)
+      throws IOException {
+    ServiceInfo leader = leaderInfoSupplier.get();
+    URL checkpointUrl = buildCheckpointUrl(leader);
+    LOG.info("Downloading OM DB checkpoint from leader {}. Checkpoint: {}, "
+        + "URL: {}", leaderNodeID, targetFile.getName(), checkpointUrl);

Review Comment:
   Question regarding leader transition corner case @devmadhuu  --
     this method is called multiple times during a checkpoint, each time it 
returns partial checkpoint.
     The leader may change at different time, and it may attempt to download 
partial checkpoint from another OM, will that be a problem?
   



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