Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RATIS-1431. Add ratis-shell add&remove peer command #534

Merged
merged 6 commits into from
Nov 19, 2021

Conversation

codings-dan
Copy link
Contributor

@codings-dan codings-dan commented Nov 13, 2021

What changes were proposed in this pull request?

Add a sub command to remove and add peer.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/RATIS-1431

How was this patch tested?

[~/local/myproject/ratis] [removePeer *] -> %  mvn clean install  assembly:single -DskipTests -Dmaven.javadoc.skip=true -Dlicense.skip=true  -Dfindbugs.skip=true -Denforcer.skip=true -Dgpg.skip=true   -Djsse.enableSNIExtension=false  -Prelease -Papache-release
[~/local/myproject/ratis] [removePeer *]-> % cd ratis-assembly/target
[~/local/myproject/ratis/ratis-assembly/target] [removePeer *] -> % tar -xzf apache-ratis-2.3.0-SNAPSHOT-ratis-shell.tar.gz
[~/local/myproject/ratis/ratis-assembly/target] [removePeer *] -> % cd apache-ratis-2.3.0-SNAPSHOT
 [~/local/myproject/ratis/ratis-assembly/target/apache-ratis-2.3.0-SNAPSHOT] [removePeer *] -> % bin/ratis sh info -peers localhost:19200,localhost:19201,localhost:19202
group id: 02511d47-d67c-49a3-9011-abb3109a44c1
leader info: localhost_19200(localhost:19200)

[server {
  id: "localhost_19200"
  address: "localhost:19200"
}
commitIndex: 8
, server {
  id: "localhost_19202"
  address: "localhost:19202"
}
commitIndex: 8
, server {
  id: "localhost_19201"
  address: "localhost:19201"
}
commitIndex: 8
]
[~/local/myproject/ratis/ratis-assembly/target/apache-ratis-2.3.0-SNAPSHOT] [removePeer *]-> % bin/ratis sh quorumRemove -peers localhost:19200,localhost:19201,localhost:19202 -removePeer localhost:19202
[~/local/myproject/ratis/ratis-assembly/target/apache-ratis-2.3.0-SNAPSHOT] [removePeer *]-> % bin/ratis sh info -peers localhost:19200,localhost:19201,localhost:19202
group id: 02511d47-d67c-49a3-9011-abb3109a44c1
leader info: localhost_19200(localhost:19200)

[server {
  id: "localhost_19200"
  address: "localhost:19200"
}
commitIndex: 12
, server {
  id: "localhost_19201"
  address: "localhost:19201"
}
commitIndex: 12
]

@codings-dan codings-dan changed the title Add ratis-shell removePeer command RATIS-1431. Add ratis-shell removePeer command Nov 13, 2021
Copy link
Member

@maobaolong maobaolong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution, left some minor comments.


@Override
public String getCommandName() {
return "quorumRemove";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"quorumRemove" -> "remove"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szetszwo What sub command name do you think is better?

  • quorumRemove
  • remove
  • removePeers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"removePeers" sounds good.

@codings-dan
Copy link
Contributor Author

@maobaolong I modified the code according to your suggestion. PTAL, thx!
What do you think about commandName?@szetszwo

@szetszwo
Copy link
Contributor

@codings-dan , @maobaolong , I think we should combine addPeers and removePeers to a single setConfiguration command so that users can add and remove peers at the same time. What do you think?

@codings-dan
Copy link
Contributor Author

@szetszwo You mean that the original cluster members were A, B, and C, but now they become A, B, and D, right?

@szetszwo
Copy link
Contributor

Yes.

@szetszwo
Copy link
Contributor

The command could look like:

ratis sh setConf -groupid xxx -peers a0,a1,a2 -remove a2 -add a3

@codings-dan
Copy link
Contributor Author

I think this is a good idea, but I tend to modify it to
ratis sh memberChange -groupid xxx -peers a0,a1,a2 -remove a2 -add a3
For setConf is not very use-friendly, what do you think? @szetszwo

@szetszwo
Copy link
Contributor

How about "group"?

ratis sh group -groupid xxx -peers a0,a1,a2 -remove a2 -add a3

@codings-dan
Copy link
Contributor Author

Ok, I will modify the code according to this comment

@codings-dan
Copy link
Contributor Author

@szetszwo I modified the code according to your comment. PTAL, thx! And I have tested it locally and there is no problem with the function.

Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codings-dan , thanks for the update. Some comments inlined and some suggestions can be found in https://issues.apache.org/jira/secure/attachment/13036297/534_review.patch . (It did not rename QuorumCommand to GroupCommand so that it is easily to see the changes. Please do the rename.)

/**
* Command for remove ratis server.
*/
public class QuorumCommand extends AbstractRatisCommand {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call it GroupCommand.

Comment on lines 41 to 42
public static final String REMOVE_PEER_ADDRESS_OPTION_NAME = "removePeer";
public static final String ADD_PEER_ADDRESS_OPTION_NAME = "addPeer";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use "remove" and "add".

private String[] isFormat(String address) {
String[] str = address.split(":");
if(str.length < 2) {
println("The format of the parameter is wrong");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's throw an exception.

@maobaolong
Copy link
Member

@codings-dan Please address the comments from @szetszwo and update the description of this PR, combine the add and remove into one command sounds a good idea.

@codings-dan codings-dan changed the title RATIS-1431. Add ratis-shell removePeer command RATIS-1431. Add ratis-shell add and remove peer command Nov 19, 2021
@codings-dan codings-dan changed the title RATIS-1431. Add ratis-shell add and remove peer command RATIS-1431. Add ratis-shell add&remove peer command Nov 19, 2021
@codings-dan
Copy link
Contributor Author

@szetszwo Thank you for reviewing the code, I modified it according to the patch you left, PTAL, thx!

Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 the change looks good.

@szetszwo
Copy link
Contributor

@codings-dan thanks for updating the change and this pull request. Could you also update the JIRAs?

@codings-dan
Copy link
Contributor Author

Jira has been updated.

@szetszwo szetszwo merged commit 2c86489 into apache:master Nov 19, 2021
@codings-dan codings-dan deleted the removePeer branch January 21, 2022 03:46
symious pushed a commit to symious/ratis that referenced this pull request Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants