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%2FFollowerLogInformationImpl.java;h=288a540344bda27cab5276265ebcae6079c492fd;hb=a51537ff2f51571e54b607eace980a145b2a29da;hp=04b9f163f4b6ad7be0f423e485902f7b3d5ccb79;hpb=614324d63a339ef4acbc9e2c3bbaaef469f97868;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImpl.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImpl.java index 04b9f163f4..288a540344 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImpl.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImpl.java @@ -11,7 +11,6 @@ package org.opendaylight.controller.cluster.raft; import com.google.common.base.Stopwatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLongFieldUpdater; -import scala.concurrent.duration.FiniteDuration; public class FollowerLogInformationImpl implements FollowerLogInformation { private static final AtomicLongFieldUpdater NEXT_INDEX_UPDATER = AtomicLongFieldUpdater.newUpdater(FollowerLogInformationImpl.class, "nextIndex"); @@ -21,18 +20,17 @@ public class FollowerLogInformationImpl implements FollowerLogInformation { private final Stopwatch stopwatch = Stopwatch.createUnstarted(); - private final long followerTimeoutMillis; + private final RaftActorContext context; private volatile long nextIndex; private volatile long matchIndex; - public FollowerLogInformationImpl(String id, long nextIndex, - long matchIndex, FiniteDuration followerTimeoutDuration) { + public FollowerLogInformationImpl(String id, long matchIndex, RaftActorContext context) { this.id = id; - this.nextIndex = nextIndex; + this.nextIndex = context.getCommitIndex(); this.matchIndex = matchIndex; - this.followerTimeoutMillis = followerTimeoutDuration.toMillis(); + this.context = context; } @Override @@ -46,8 +44,13 @@ public class FollowerLogInformationImpl implements FollowerLogInformation { } @Override - public void setNextIndex(long nextIndex) { - this.nextIndex = nextIndex; + public boolean setNextIndex(long nextIndex) { + if(this.nextIndex != nextIndex) { + this.nextIndex = nextIndex; + return true; + } + + return false; } @Override @@ -56,8 +59,13 @@ public class FollowerLogInformationImpl implements FollowerLogInformation { } @Override - public void setMatchIndex(long matchIndex) { - this.matchIndex = matchIndex; + public boolean setMatchIndex(long matchIndex) { + if(this.matchIndex != matchIndex) { + this.matchIndex = matchIndex; + return true; + } + + return false; } @Override @@ -78,7 +86,8 @@ public class FollowerLogInformationImpl implements FollowerLogInformation { @Override public boolean isFollowerActive() { long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS); - return (stopwatch.isRunning()) && (elapsed <= followerTimeoutMillis); + return (stopwatch.isRunning()) && + (elapsed <= context.getConfigParams().getElectionTimeOutInterval().toMillis()); } @Override @@ -107,7 +116,8 @@ public class FollowerLogInformationImpl implements FollowerLogInformation { builder.append("FollowerLogInformationImpl [id=").append(id).append(", nextIndex=").append(nextIndex) .append(", matchIndex=").append(matchIndex).append(", stopwatch=") .append(stopwatch.elapsed(TimeUnit.MILLISECONDS)) - .append(", followerTimeoutMillis=").append(followerTimeoutMillis).append("]"); + .append(", followerTimeoutMillis=") + .append(context.getConfigParams().getElectionTimeOutInterval().toMillis()).append("]"); return builder.toString(); }