szetszwo commented on a change in pull request #586:
URL: https://github.com/apache/ratis/pull/586#discussion_r790223827



##########
File path: ratis-client/src/main/java/org/apache/ratis/client/RaftClient.java
##########
@@ -58,8 +58,8 @@
   /** Get the {@link GroupManagementApi} for the given server. */
   GroupManagementApi getGroupManagementApi(RaftPeerId server);
 
-  /** Get the {@link SnapshotManagementApi}. */
-  SnapshotManagementApi getSnapshotManagementApi();
+  /** Get the {@link SnapshotManagementApi} for the given server. */

Review comment:
       We should support null as below:
   ```
     /**
      * If server != null, return the {@link SnapshotManagementApi} for the 
given server.
      * Otherwise, return the {@link SnapshotManagementApi} for the group.
      */
   ```

##########
File path: 
ratis-client/src/main/java/org/apache/ratis/client/impl/SnapshotManagementImpl.java
##########
@@ -27,15 +28,19 @@
 
 class SnapshotManagementImpl implements SnapshotManagementApi {
   private final RaftClientImpl client;
+  private final RaftPeerId server;
 
-  SnapshotManagementImpl(RaftClientImpl client) {
+  SnapshotManagementImpl(RaftPeerId server, RaftClientImpl client) {
+    this.server = Objects.requireNonNull(server, "server == null");
     this.client = Objects.requireNonNull(client, "client == null");
   }
 
   @Override
   public RaftClientReply create(long timeoutMs) throws IOException {
     final long callId = CallId.getAndIncrement();
-    return client.io().sendRequestWithRetry(() -> 
SnapshotManagementRequest.newCreate(
-        client.getId(), client.getLeaderId(), client.getGroupId(), callId, 
timeoutMs));
+    final RaftClientReply reply = client.io().sendRequestWithRetry(
+        () -> SnapshotManagementRequest.newCreate(client.getId(), server,
+            client.getGroupId(), callId, timeoutMs));
+    return reply;

Review comment:
       We should support the case the server == null. When server == null, use 
client.getLeaderId() as before.
   ```
       return client.io().sendRequestWithRetry(() -> 
SnapshotManagementRequest.newCreate(client.getId(),
           Optional.ofNullable(server).orElseGet(client::getLeaderId), 
client.getGroupId(), callId, timeoutMs));
   ```

##########
File path: 
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/snapshot/TakeSnapshotCommand.java
##########
@@ -50,16 +52,22 @@ public String getCommandName() {
   public int run(CommandLine cl) throws IOException {
     super.run(cl);
     long timeout;
+    final RaftPeerId peerId;
     if (cl.hasOption(TAKE_SNAPSHOT_TIMEOUT_OPTION_NAME)) {
       timeout = 
Long.parseLong(cl.getOptionValue(TAKE_SNAPSHOT_TIMEOUT_OPTION_NAME));
     } else {
       timeout = 3000;
     }
     try(final RaftClient raftClient = RaftUtils.createClient(getRaftGroup())) {
-      RaftClientReply reply = 
raftClient.getSnapshotManagementApi().create(timeout);
-      processReply(reply, () -> String.format("Failed to take snapshot of 
peerId %s", raftClient.getLeaderId()));
-      printf(String.format("Successful take snapshot, the latest snapshot 
index is %d",
-          reply.getLogIndex()));
+      if (cl.hasOption(PEER_ID_OPTION_NAME)) {
+        peerId = 
RaftPeerId.getRaftPeerId(cl.getOptionValue(PEER_ID_OPTION_NAME));
+      } else {
+        peerId = raftClient.getLeaderId();

Review comment:
       Just set peerId = null.  The leader could change so that we should 
getLeaderId right before sending the rpc.




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