RATIS-1526. Add ratis-shell pause&resume leader election command#603
RATIS-1526. Add ratis-shell pause&resume leader election command#603szetszwo merged 4 commits intoapache:masterfrom
Conversation
|
|
||
| @Override | ||
| public String getCommandName() { | ||
| return "leaderElection"; |
There was a problem hiding this comment.
This command and the ElectCommand are closely related. How about we have a base election command and then have the following subcommands?
- transfer
- pause
- resume
|
@szetszwo I did code splitting related to election command, PTAL, thx! |
@codings-dan , if we add the code above, the new subcommnads will be ignored. |
Do you mean we add these lines of code and then display this information during compilation? |
@codings-dan, The code lines are for printing debug messages. Currently, the debug messages show that many of the command classes are ignored since they are not under the |
|
@szetszwo We don't need load classes outside the |
|
@codings-dan , I see. The print out is a little bit confusing. Thanks for explaining it. I suggest that we move the setPriority command as a subcommand of the peer command and change the peer command with the following subcommands.
See if you are interested working on it. |
Good idea, since this change has nothing to do with this jira, I will complete the code change in the future. |
szetszwo
left a comment
There was a problem hiding this comment.
@codings-dan , thanks a lot. Let's move the common code to a new AbstractParentCommand class. Could you also clean up the GroupCommnad and the SnapshotCommand? See https://issues.apache.org/jira/secure/attachment/13040333/603_review.patch
| = Collections.unmodifiableList(Arrays.asList( | ||
| TransferCommand::new, PauseCommand::new, ResumeCommand::new)); | ||
|
|
||
| private final Map<String, Command> subs; |
There was a problem hiding this comment.
Let's move the common code to a parent class:
public abstract class AbstractParentCommand extends AbstractRatisCommand{
private final Map<String, Command> subs;
public AbstractParentCommand(Context context, List<Function<Context, AbstractRatisCommand>> subCommandConstructors) {
super(context);
this.subs = Collections.unmodifiableMap(subCommandConstructors.stream()
.map(constructor -> constructor.apply(context))
.collect(Collectors.toMap(Command::getCommandName, Function.identity())));
}
@Override
public final Map<String, Command> getSubCommands() {
return subs;
}
@Override
public final String getUsage() {
final StringBuilder usage = new StringBuilder(getCommandName());
for (String cmd : getSubCommands().keySet()) {
usage.append(" [").append(cmd).append("]");
}
return usage.toString();
}
}
| TransferCommand::new, PauseCommand::new, ResumeCommand::new)); | ||
|
|
||
| private final Map<String, Command> subs; | ||
| public static final String ADDRESS_OPTION_NAME = "address"; |
There was a problem hiding this comment.
Let's remove it. This is not really used.
| } | ||
|
|
||
| @Override | ||
| public Options getOptions() { |
There was a problem hiding this comment.
Let's remove it. This is not really used.
| final RaftPeerId peerId; | ||
| Optional<RaftPeer> peer = | ||
| getRaftGroup().getPeers().stream().filter(p -> p.getAddress().equals(strAddr)).findAny(); | ||
| if (peer.isPresent()) { | ||
| peerId = peer.get().getId(); | ||
| } else { | ||
| printf("Can't find a sever with the address:%s", strAddr); | ||
| return -1; | ||
| } |
There was a problem hiding this comment.
The code can be simplified as below.
final RaftPeerId peerId = getRaftGroup().getPeers().stream()
.filter(p -> p.getAddress().equals(strAddr)).findAny()
.map(RaftPeer::getId)
.orElse(null);
if (peerId == null) {
printf("Peer not found: %s", strAddr);
return -1;
}
| final RaftPeerId peerId; | ||
| Optional<RaftPeer> peer = | ||
| getRaftGroup().getPeers().stream().filter(p -> p.getAddress().equals(strAddr)).findAny(); | ||
| if (peer.isPresent()) { | ||
| peerId = peer.get().getId(); | ||
| } else { |
There was a problem hiding this comment.
We may simplify the code as in the PauseCommnad.
@szetszwo I have refactored the code, PTAL, thx! |
szetszwo
left a comment
There was a problem hiding this comment.
+1 the change looks good.
What changes were proposed in this pull request?
Add a sub command to pause and resume leader election on the specific peer.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/RATIS-1526
How was this patch tested?
UT