private static final int SYNC_THRESHOLD = 10;
public Follower(RaftActorContext context) {
+ this(context, null);
+ }
+
+ public Follower(RaftActorContext context, String initialLeaderId) {
super(context, RaftState.Follower);
+ leaderId = initialLeaderId;
initialSyncStatusTracker = new SyncStatusTracker(context.getActor(), getId(), SYNC_THRESHOLD);
if(context.getRaftPolicy().automaticElectionsEnabled()) {
- if (context.getPeerAddresses().isEmpty()) {
+ if (context.getPeerIds().isEmpty() && getLeaderId() == null) {
actor().tell(ELECTION_TIMEOUT, actor());
} else {
scheduleElection(electionDuration());
context.getReplicatedLog().appendAndPersist(entry);
if(entry.getData() instanceof ServerConfigurationPayload) {
- applyServerConfiguration((ServerConfigurationPayload)entry.getData());
+ context.updatePeerIds((ServerConfigurationPayload)entry.getData());
}
}
logName(), installSnapshot.getLeaderId(), installSnapshot.getData().size(),
installSnapshot.getChunkIndex(), installSnapshot.getTotalChunks());
+ leaderId = installSnapshot.getLeaderId();
+
if(snapshotTracker == null){
snapshotTracker = new SnapshotTracker(LOG, installSnapshot.getTotalChunks());
}
installSnapshot.getLastIncludedIndex(),
installSnapshot.getLastIncludedTerm(),
context.getTermInformation().getCurrentTerm(),
- context.getTermInformation().getVotedFor());
+ context.getTermInformation().getVotedFor(),
+ context.getPeerServerInfo());
ApplySnapshot.Callback applySnapshotCallback = new ApplySnapshot.Callback() {
@Override