Bug 2187: Bootstrap EOS shard when no local shards configured
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / behaviors / Follower.java
index c69528230084af9091dc906324f8c3eff7e2f856..0149b57e6e94f8ddf076a406f14eea1546d2aa1e 100644 (file)
@@ -45,12 +45,17 @@ public class Follower extends AbstractRaftActorBehavior {
     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.getPeerIds().isEmpty()) {
+            if (context.getPeerIds().isEmpty() && getLeaderId() == null) {
                 actor().tell(ELECTION_TIMEOUT, actor());
             } else {
                 scheduleElection(electionDuration());
@@ -192,7 +197,7 @@ public class Follower extends AbstractRaftActorBehavior {
                 context.getReplicatedLog().appendAndPersist(entry);
 
                 if(entry.getData() instanceof ServerConfigurationPayload) {
-                    applyServerConfiguration((ServerConfigurationPayload)entry.getData());
+                    context.updatePeerIds((ServerConfigurationPayload)entry.getData());
                 }
             }
 
@@ -346,6 +351,8 @@ public class Follower extends AbstractRaftActorBehavior {
                     logName(), installSnapshot.getLeaderId(), installSnapshot.getData().size(),
                     installSnapshot.getChunkIndex(), installSnapshot.getTotalChunks());
 
+        leaderId = installSnapshot.getLeaderId();
+
         if(snapshotTracker == null){
             snapshotTracker = new SnapshotTracker(LOG, installSnapshot.getTotalChunks());
         }
@@ -365,7 +372,8 @@ public class Follower extends AbstractRaftActorBehavior {
                         installSnapshot.getLastIncludedIndex(),
                         installSnapshot.getLastIncludedTerm(),
                         context.getTermInformation().getCurrentTerm(),
-                        context.getTermInformation().getVotedFor());
+                        context.getTermInformation().getVotedFor(),
+                        context.getPeerServerInfo());
 
                 ApplySnapshot.Callback applySnapshotCallback = new ApplySnapshot.Callback() {
                     @Override