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%2FRaftActorLeadershipTransferCohort.java;h=b83bfd370948dc18a3826633568e2a78eeb650ac;hb=36372c716205959311bb86256872cf9c7b2d350b;hp=7105714b0ba8e807fd7cc137b928a3ad0a875539;hpb=204f45f8b3233dbea87e2c8065914f0d2a0ded07;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorLeadershipTransferCohort.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorLeadershipTransferCohort.java index 7105714b0b..b83bfd3709 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorLeadershipTransferCohort.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorLeadershipTransferCohort.java @@ -48,7 +48,7 @@ import scala.concurrent.duration.FiniteDuration; * * @author Thomas Pantelis */ -public class RaftActorLeadershipTransferCohort implements Runnable { +public class RaftActorLeadershipTransferCohort { private static final Logger LOG = LoggerFactory.getLogger(RaftActorLeadershipTransferCohort.class); private final RaftActor raftActor; @@ -84,14 +84,25 @@ public class RaftActorLeadershipTransferCohort implements Runnable { } } - raftActor.pauseLeader(this); + raftActor.pauseLeader(new TimedRunnable(context.getConfigParams().getElectionTimeOutInterval(), raftActor) { + @Override + protected void doRun() { + doTransfer(); + } + + @Override + protected void doCancel() { + LOG.debug("{}: pauseLeader timed out - aborting transfer", raftActor.persistenceId()); + abortTransfer(); + } + }); } /** - * This method is invoked to run the leadership transfer. + * This method is invoked to perform the leadership transfer. */ - @Override - public void run() { + @VisibleForTesting + void doTransfer() { RaftActorBehavior behavior = raftActor.getCurrentBehavior(); // Sanity check... if(behavior instanceof Leader) { @@ -125,7 +136,7 @@ public class RaftActorLeadershipTransferCohort implements Runnable { // Add a timer in case we don't get a leader change - 2 sec should be plenty of time if a new // leader is elected. Note: the Runnable is sent as a message to the raftActor which executes it - // safely run on actor's thread dispatcher. + // safely run on the actor's thread dispatcher. FiniteDuration timeout = FiniteDuration.create(newLeaderTimeoutInMillis, TimeUnit.MILLISECONDS); newLeaderTimer = raftActor.getContext().system().scheduler().scheduleOnce(timeout, raftActor.self(), new Runnable() { @@ -153,7 +164,7 @@ public class RaftActorLeadershipTransferCohort implements Runnable { LOG.info("{}: Successfully transferred leadership to {} in {}", raftActor.persistenceId(), raftActor.getLeaderId(), transferTimer.toString()); } else { - LOG.info("{}: Failed to transfer leadership in {}", raftActor.persistenceId(), + LOG.warn("{}: Failed to transfer leadership in {}", raftActor.persistenceId(), transferTimer.toString()); } }