You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by GitBox <gi...@apache.org> on 2022/02/24 11:28:40 UTC

[GitHub] [ratis] codings-dan opened a new pull request #610: RATIS-1535. Add a command to step down the leader

codings-dan opened a new pull request #610:
URL: https://github.com/apache/ratis/pull/610


   ## What changes were proposed in this pull request?
   
   Add a sub command to step down the leader.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/RATIS-1535
   
   ## How was this patch tested?
   
   UT
   


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ratis] szetszwo merged pull request #610: RATIS-1535. Add a command to step down the leader

Posted by GitBox <gi...@apache.org>.
szetszwo merged pull request #610:
URL: https://github.com/apache/ratis/pull/610


   


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ratis] codings-dan commented on a change in pull request #610: RATIS-1535. Add a command to step down the leader

Posted by GitBox <gi...@apache.org>.
codings-dan commented on a change in pull request #610:
URL: https://github.com/apache/ratis/pull/610#discussion_r814501549



##########
File path: ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/election/StepDownCommand.java
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.ratis.shell.cli.sh.election;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.client.RaftClient;
+import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.shell.cli.RaftUtils;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+
+import java.io.IOException;
+
+/**
+ * Command for stepping down ratis leader server.
+ */
+public class StepDownCommand extends AbstractRatisCommand {
+
+  /**
+   * @param context command context
+   */
+  public StepDownCommand(Context context) {
+    super(context);
+  }
+
+  @Override
+  public String getCommandName() {
+    return "stepDown";
+  }
+
+  @Override
+  public int run(CommandLine cl) throws IOException {
+    super.run(cl);
+
+    try (RaftClient client = RaftUtils.createClient(getRaftGroup())) {
+      try {

Review comment:
       This is my negligence, I try to avoid it in the future, thanks




-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ratis] codings-dan commented on a change in pull request #610: RATIS-1535. Add a command to step down the leader

Posted by GitBox <gi...@apache.org>.
codings-dan commented on a change in pull request #610:
URL: https://github.com/apache/ratis/pull/610#discussion_r814500850



##########
File path: ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/ElectionCommand.java
##########
@@ -29,7 +30,7 @@
 public class ElectionCommand extends AbstractParentCommand {
   private static final List<Function<Context, AbstractRatisCommand>> SUB_COMMAND_CONSTRUCTORS
       = Collections.unmodifiableList(Arrays.asList(
-      TransferCommand::new, PauseCommand::new, ResumeCommand::new));
+      TransferCommand::new, PauseCommand::new, ResumeCommand::new, StepDownCommand::new));

Review comment:
       done




-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ratis] codings-dan commented on a change in pull request #610: RATIS-1535. Add a command to step down the leader

Posted by GitBox <gi...@apache.org>.
codings-dan commented on a change in pull request #610:
URL: https://github.com/apache/ratis/pull/610#discussion_r814501549



##########
File path: ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/election/StepDownCommand.java
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.ratis.shell.cli.sh.election;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.client.RaftClient;
+import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.shell.cli.RaftUtils;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+
+import java.io.IOException;
+
+/**
+ * Command for stepping down ratis leader server.
+ */
+public class StepDownCommand extends AbstractRatisCommand {
+
+  /**
+   * @param context command context
+   */
+  public StepDownCommand(Context context) {
+    super(context);
+  }
+
+  @Override
+  public String getCommandName() {
+    return "stepDown";
+  }
+
+  @Override
+  public int run(CommandLine cl) throws IOException {
+    super.run(cl);
+
+    try (RaftClient client = RaftUtils.createClient(getRaftGroup())) {
+      try {

Review comment:
       This is my negligence, I will avoid it in the future, thanks




-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ratis] szetszwo commented on a change in pull request #610: RATIS-1535. Add a command to step down the leader

Posted by GitBox <gi...@apache.org>.
szetszwo commented on a change in pull request #610:
URL: https://github.com/apache/ratis/pull/610#discussion_r814056236



##########
File path: ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/ElectionCommand.java
##########
@@ -29,7 +30,7 @@
 public class ElectionCommand extends AbstractParentCommand {
   private static final List<Function<Context, AbstractRatisCommand>> SUB_COMMAND_CONSTRUCTORS
       = Collections.unmodifiableList(Arrays.asList(
-      TransferCommand::new, PauseCommand::new, ResumeCommand::new));
+      TransferCommand::new, PauseCommand::new, ResumeCommand::new, StepDownCommand::new));

Review comment:
       Let's move StepDownCommand next to TransferCommand.
   ```
         TransferCommand::new, StepDownCommand::new, PauseCommand::new, ResumeCommand::new));
   ```
   Also, we should use LinkedHashMap in AbstractParentCommand so that it can preserve the order.
   ```
   +++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractParentCommand.java
   @@ -32,7 +33,9 @@ public abstract class AbstractParentCommand extends AbstractRatisCommand{
        super(context);
        this.subs = Collections.unmodifiableMap(subCommandConstructors.stream()
            .map(constructor -> constructor.apply(context))
   -        .collect(Collectors.toMap(Command::getCommandName, Function.identity())));
   +        .collect(Collectors.toMap(Command::getCommandName, Function.identity(),
   +            (a, b) -> {throw new IllegalStateException("Found duplicated commands: " + a + " and " + b);},
   +            LinkedHashMap::new)));
      }
   ```
   Without the change above, the sub commands will be printed out randomly.
   ```
   Usage: ratis sh [generic options]
   	 [election [resume] [stepDown] [transfer] [pause]]         
   	 [group [list] [info]]                                     
   	 [peer [add] [setPriority] [remove]]                       
   	 [snapshot [create]]                                       
   ```

##########
File path: ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/election/StepDownCommand.java
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.ratis.shell.cli.sh.election;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.client.RaftClient;
+import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.shell.cli.RaftUtils;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+
+import java.io.IOException;
+
+/**
+ * Command for stepping down ratis leader server.
+ */
+public class StepDownCommand extends AbstractRatisCommand {
+
+  /**
+   * @param context command context
+   */
+  public StepDownCommand(Context context) {
+    super(context);
+  }
+
+  @Override
+  public String getCommandName() {
+    return "stepDown";
+  }
+
+  @Override
+  public int run(CommandLine cl) throws IOException {
+    super.run(cl);
+
+    try (RaftClient client = RaftUtils.createClient(getRaftGroup())) {
+      try {

Review comment:
       These two try-blocks can be combined as below:
   ```
     public int run(CommandLine cl) throws IOException {
       super.run(cl);
   
       try (RaftClient client = RaftUtils.createClient(getRaftGroup())) {
         final RaftClientReply transferLeadershipReply = client.admin().transferLeadership(null, 60_000);
         processReply(transferLeadershipReply, () -> "Failed to step down leader");
       } catch (Throwable t) {
         printf("Failed to step down leader: %s%n", t.getMessage());
         return -1;
       }
       println("Step down leader successfully");
       return 0;
     }
   ```




-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org