X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FRaftActor.java;h=b93ea4dd8a8b3e6028d2943f87c84d17ee3eb01a;hb=733636ec5f1b4caecd130a6a26f6d196af6ff854;hp=5f6f3ec24e573c4dedba6ba42a38dbbe28a51698;hpb=f1c3050779d7770ef6a12a67a1870765c3dfd9eb;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java index 5f6f3ec24e..b93ea4dd8a 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java @@ -502,12 +502,23 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor { String newRaftPolicy = configParams. getCustomRaftPolicyImplementationClass(); - LOG.debug ("RaftPolicy used with prev.config {}, RaftPolicy used with newConfig {}", + LOG.debug("{}: RaftPolicy used with prev.config {}, RaftPolicy used with newConfig {}", persistenceId(), oldRaftPolicy, newRaftPolicy); context.setConfigParams(configParams); if (!Objects.equal(oldRaftPolicy, newRaftPolicy)) { - //RaftPolicy is modifed for the Actor. Re-initialize its current behaviour - initializeBehavior(); + // The RaftPolicy was modified. If the current behavior is Follower then re-initialize to Follower + // but transfer the previous leaderId so it doesn't immediately try to schedule an election. This + // avoids potential disruption. Otherwise, switch to Follower normally. + RaftActorBehavior behavior = currentBehavior.getDelegate(); + if(behavior instanceof Follower) { + String previousLeaderId = ((Follower)behavior).getLeaderId(); + + LOG.debug("{}: Re-initializing to Follower with previous leaderId {}", persistenceId(), previousLeaderId); + + changeCurrentBehavior(new Follower(context, previousLeaderId)); + } else { + initializeBehavior(); + } } }