runzhiwang commented on a change in pull request #372:
URL: https://github.com/apache/incubator-ratis/pull/372#discussion_r548321499
##########
File path:
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
##########
@@ -866,18 +880,112 @@ RaftClientReply waitForReply(RaftClientRequest request,
CompletableFuture<RaftCl
@Override
public RaftClientReply transferLeadership(TransferLeadershipRequest request)
throws IOException {
- //TODO(runzhiwang): implement transfer leadership in server
- return null;
+ return waitForReply(request, transferLeadershipAsync(request));
+ }
+
+ private CompletableFuture<RaftClientReply>
logAndReturnTransferLeadershipFail(
+ TransferLeadershipRequest request, String msg) {
+ LOG.warn(msg);
+ return CompletableFuture.completedFuture(newExceptionReply(request, new
StateMachineException(msg)));
+ }
+
+ boolean isSteppingDown() {
+ return finishTransferLeader != null;
+ }
+
+ private Consumer<RaftPeerId> finishTransferLeader;
+
+ public Consumer<RaftPeerId> finishTransferLeader() {
+ return finishTransferLeader;
+ }
+
+ public Consumer<RaftPeerId> setFinishTransferLeader(Consumer<RaftPeerId>
consumer) {
+ return finishTransferLeader = consumer;
+ }
+
+ private void timeoutTransferLeadership(
+ TransferLeadershipRequest request, CompletableFuture<RaftClientReply>
replyFuture)
+ throws StateMachineException {
+ synchronized (replyFuture) {
Review comment:
With the new `AtomicReference<PendingRequest> pending`, we do not need
synchronized anymore, thanks a lot.
----------------------------------------------------------------
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]