use of org.opendaylight.controller.cluster.raft.base.messages.TimeoutNow in project controller by opendaylight.
the class Follower method handleMessage.
@Override
public RaftActorBehavior handleMessage(final ActorRef sender, final Object message) {
if (message instanceof ElectionTimeout || message instanceof TimeoutNow) {
return handleElectionTimeout(message);
}
if (appendEntriesMessageAssembler.handleMessage(message, actor())) {
return this;
}
if (!(message instanceof RaftRPC)) {
// The rest of the processing requires the message to be a RaftRPC
return null;
}
final RaftRPC rpc = (RaftRPC) message;
// This applies to all RPC messages and responses
if (rpc.getTerm() > context.getTermInformation().getCurrentTerm()) {
log.info("{}: Term {} in \"{}\" message is greater than follower's term {} - updating term", logName(), rpc.getTerm(), rpc, context.getTermInformation().getCurrentTerm());
context.getTermInformation().updateAndPersist(rpc.getTerm(), null);
}
if (rpc instanceof InstallSnapshot) {
handleInstallSnapshot(sender, (InstallSnapshot) rpc);
restartLastLeaderMessageTimer();
scheduleElection(electionDuration());
return this;
}
if (!(rpc instanceof RequestVote) || canGrantVote((RequestVote) rpc)) {
restartLastLeaderMessageTimer();
scheduleElection(electionDuration());
}
return super.handleMessage(sender, rpc);
}
use of org.opendaylight.controller.cluster.raft.base.messages.TimeoutNow in project controller by opendaylight.
the class FollowerTest method testFollowerSchedulesElectionTimeoutImmediatelyWhenItHasNoPeers.
@Test
public void testFollowerSchedulesElectionTimeoutImmediatelyWhenItHasNoPeers() {
MockRaftActorContext context = createActorContext();
Stopwatch stopwatch = Stopwatch.createStarted();
follower = createBehavior(context);
TimeoutNow timeoutNow = MessageCollectorActor.expectFirstMatching(followerActor, TimeoutNow.class);
long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS);
assertTrue(elapsed < context.getConfigParams().getElectionTimeOutInterval().toMillis());
RaftActorBehavior newBehavior = follower.handleMessage(ActorRef.noSender(), timeoutNow);
assertTrue("Expected Candidate", newBehavior instanceof Candidate);
}
use of org.opendaylight.controller.cluster.raft.base.messages.TimeoutNow in project controller by opendaylight.
the class FollowerTest method testFollowerSchedulesElectionIfAutomaticElectionsAreDisabled.
@Test
public void testFollowerSchedulesElectionIfAutomaticElectionsAreDisabled() {
MockRaftActorContext context = createActorContext();
context.setConfigParams(new DefaultConfigParamsImpl() {
@Override
public FiniteDuration getElectionTimeOutInterval() {
return FiniteDuration.apply(100, TimeUnit.MILLISECONDS);
}
});
context.setRaftPolicy(createRaftPolicy(false, false));
follower = createBehavior(context);
TimeoutNow timeoutNow = MessageCollectorActor.expectFirstMatching(followerActor, TimeoutNow.class);
RaftActorBehavior newBehavior = follower.handleMessage(ActorRef.noSender(), timeoutNow);
assertSame("handleMessage result", follower, newBehavior);
}
Aggregations