amaliujia commented on a change in pull request #1870:
URL: https://github.com/apache/ozone/pull/1870#discussion_r569133417



##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/InterSCMGrpcClient.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hdds.scm.ha;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.protocol.scm.proto.InterSCMProtocolProtos;
+import 
org.apache.hadoop.hdds.protocol.scm.proto.InterSCMProtocolProtos.CopyDBCheckpointResponseProto;
+import org.apache.hadoop.hdds.protocol.scm.proto.InterSCMProtocolServiceGrpc;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.ratis.thirdparty.io.grpc.ManagedChannel;
+import org.apache.ratis.thirdparty.io.grpc.netty.NettyChannelBuilder;
+import org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Grpc client to download a Rocks db checkpoint from leader node
+ * in SCM HA ring.
+ */
+public class InterSCMGrpcClient implements SCMSnapshotDownloader{
+  private static final Logger LOG =
+      LoggerFactory.getLogger(InterSCMGrpcClient.class);
+
+  private final ManagedChannel channel;
+
+  private final InterSCMProtocolServiceGrpc.InterSCMProtocolServiceStub
+      client;
+
+  private final long timeout;
+
+  public InterSCMGrpcClient(final String host, final ConfigurationSource conf) 
{
+    Preconditions.checkNotNull(conf);
+    int port = conf.getObject(SCMHAConfiguration.class).getGrpcBindPort();
+    timeout =
+        conf.getObject(SCMHAConfiguration.class).getGrpcDeadlineInterval();
+    NettyChannelBuilder channelBuilder =
+        NettyChannelBuilder.forAddress(host, port).usePlaintext()
+            .maxInboundMessageSize(OzoneConsts.OZONE_SCM_CHUNK_MAX_SIZE);
+    channel = channelBuilder.build();
+    client = InterSCMProtocolServiceGrpc.newStub(channel).
+        withDeadlineAfter(timeout, TimeUnit.SECONDS);
+  }
+
+
+  @Override
+  public CompletableFuture<Path> download(final Path outputPath) {
+    // By default on every checkpoint, the rocks db will be flushed
+    InterSCMProtocolProtos.CopyDBCheckpointRequestProto request =
+        InterSCMProtocolProtos.CopyDBCheckpointRequestProto.newBuilder()
+            .setFlush(true)

Review comment:
       Why we need a flush flag than always flush the DB before take a 
checkpoint? Or when we want to set this flush flag as false?  

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMSnapshotDownloader.java
##########
@@ -0,0 +1,35 @@
+package org.apache.hadoop.hdds.scm.ha;/*
+ * 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
+ * <p>
+ * <p>http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * <p>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.
+ */
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Contract to download a SCM Snapshot from remote server..
+ * <p>
+ *
+ * The underlying implementation is supposed to download SCM snapshot via
+ * any chosen protoclol(for now its Grpc).
+ * images.
+ */
+public interface SCMSnapshotDownloader {
+
+  CompletableFuture<Path> download(final Path destination) throws IOException;

Review comment:
       Question: is `destination` a file or a directory? 
   
   Nit: maybe add a javadoc here to explain.




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

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