- protected void scheduleIsolatedLeaderCheck(FiniteDuration isolatedCheckInterval) {
- isolatedLeaderCheckSchedule = context.getActorSystem().scheduler().schedule(isolatedCheckInterval, isolatedCheckInterval,
- context.getActor(), new IsolatedLeaderCheck(),
- context.getActorSystem().dispatcher(), context.getActor());
+ FollowerLogInformation followerInfo = getFollower(followerId);
+ if(followerInfo == null) {
+ return;
+ }
+
+ long lastIndex = context.getReplicatedLog().lastIndex();
+ boolean isVoting = context.getPeerInfo(followerId).isVoting();
+
+ LOG.debug("{}: tryToCompleteLeadershipTransfer: followerId: {}, matchIndex: {}, lastIndex: {}, isVoting: {}",
+ logName(), followerId, followerInfo.getMatchIndex(), lastIndex, isVoting);
+
+ if(isVoting && followerInfo.getMatchIndex() == lastIndex) {
+ LOG.debug("{}: Follower's log matches - sending ElectionTimeout", logName());
+
+ // We can't be sure if the follower has applied all its log entries to its state so send an
+ // additional AppendEntries with the latest commit index.
+ sendAppendEntries(0, false);
+
+ // Now send an ElectionTimeout to the matching follower to immediately start an election.
+ ActorSelection followerActor = context.getPeerActorSelection(followerId);
+ followerActor.tell(ElectionTimeout.INSTANCE, context.getActor());
+
+ LOG.debug("{}: Leader transfer complete", logName());
+
+ leadershipTransferContext.transferCohort.transferComplete();
+ leadershipTransferContext = null;
+ }