import akka.actor.ActorSelection;
import akka.actor.Cancellable;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
import com.google.common.base.Stopwatch;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import java.util.concurrent.TimeUnit;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.controller.cluster.raft.base.messages.LeaderTransitioning;
import org.opendaylight.controller.cluster.raft.behaviors.Leader;
import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
this(raftActor, null);
}
- RaftActorLeadershipTransferCohort(final RaftActor raftActor, @Nullable final String requestedFollowerId) {
+ RaftActorLeadershipTransferCohort(final RaftActor raftActor, final @Nullable String requestedFollowerId) {
this.raftActor = raftActor;
this.requestedFollowerId = requestedFollowerId;
final long electionTimeout = raftActor.getRaftActorContext().getConfigParams()
.getElectionTimeOutInterval().toMillis();
final int variance = raftActor.getRaftActorContext().getConfigParams().getElectionTimeVariance();
- newLeaderTimeoutInMillis = electionTimeout + variance * 2;
+ newLeaderTimeoutInMillis = 2 * (electionTimeout + variance);
}
void init() {
raftActor.pauseLeader(new TimedRunnable(context.getConfigParams().getElectionTimeOutInterval(), raftActor) {
@Override
protected void doRun() {
+ LOG.debug("{}: pauseLeader successfully completed - doing transfer", raftActor.persistenceId());
doTransfer();
}
@Override
protected void doCancel() {
- LOG.debug("{}: pauseLeader timed out - aborting transfer", raftActor.persistenceId());
- abortTransfer();
+ LOG.debug("{}: pauseLeader timed out - continuing with transfer", raftActor.persistenceId());
+ doTransfer();
}
});
}
raftActor.getLeaderId(), transferTimer);
} else {
LOG.warn("{}: Failed to transfer leadership in {}", raftActor.persistenceId(), transferTimer);
+ raftActor.unpauseLeader();
}
}
}
public Optional<String> getRequestedFollowerId() {
- return Optional.fromNullable(requestedFollowerId);
+ return Optional.ofNullable(requestedFollowerId);
}
interface OnComplete {