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%2FFollowerLogInformation.java;h=123d206d05b9e20742a3c45aba6b2f5bf692d09d;hb=fbeed3e25ef80495c67bfe1698daf44b88fb10ff;hp=2c4304d404a57ca919cb0c71f274588c6654f6e5;hpb=e316a0ef36279a72767703d190f38a39d7d49395;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformation.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformation.java index 2c4304d404..123d206d05 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformation.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformation.java @@ -5,72 +5,159 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.raft; -import java.util.concurrent.atomic.AtomicLong; +import com.google.common.annotations.VisibleForTesting; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.opendaylight.controller.cluster.raft.behaviors.LeaderInstallSnapshotState; /** - * The state of the followers log as known by the Leader + * The state of the followers log as known by the Leader. */ public interface FollowerLogInformation { /** - * Increment the value of the nextIndex - * @return + * Increments the value of the follower's next index. + * + * @return the new value of nextIndex. + */ + long incrNextIndex(); + + /** + * Decrements the value of the follower's next index. + * + * @return true if the next index was decremented, ie it was previously >= 0, false otherwise. + */ + boolean decrNextIndex(); + + /** + * Sets the index of the follower's next log entry. + * + * @param nextIndex the new index. + * @return true if the new index differed from the current index and the current index was updated, false + * otherwise. + */ + boolean setNextIndex(long nextIndex); + + /** + * Increments the value of the follower's match index. + * + * @return the new value of matchIndex. + */ + long incrMatchIndex(); + + /** + * Sets the index of the follower's highest log entry. + * + * @param matchIndex the new index. + * @return true if the new index differed from the current index and the current index was updated, false + * otherwise. + */ + boolean setMatchIndex(long matchIndex); + + /** + * Returns the identifier of the follower. + * + * @return the identifier of the follower. + */ + String getId(); + + /** + * Returns the index of the next log entry to send to the follower. + * + * @return index of the follower's next log entry. */ - public long incrNextIndex(); + long getNextIndex(); /** - * Decrement the value of the nextIndex - * @return + * Returns the index of highest log entry known to be replicated on the follower. + * + * @return the index of highest log entry. */ - public long decrNextIndex(); + long getMatchIndex(); /** + * Checks if the follower is active by comparing the time of the last activity with the election time out. The + * follower is active if some activity has occurred for the follower within the election time out interval. * - * @param nextIndex + * @return true if follower is active, false otherwise. + */ + boolean isFollowerActive(); + + /** + * Marks the follower as active. This should be called when some activity has occurred for the follower. */ - void setNextIndex(long nextIndex); + void markFollowerActive(); /** - * Increment the value of the matchIndex - * @return + * Marks the follower as inactive. This should only be called from unit tests. */ - public long incrMatchIndex(); + @VisibleForTesting + void markFollowerInActive(); - public void setMatchIndex(long matchIndex); /** - * The identifier of the follower - * This could simply be the url of the remote actor + * Returns the time since the last activity occurred for the follower. + * + * @return time in milliseconds since the last activity from the follower. + */ + long timeSinceLastActivity(); + + /** + * This method checks if the next replicate message can be sent to the follower. This is an optimization to avoid + * sending duplicate message too frequently if the last replicate message was sent and no reply has been received + * yet within the current heart beat interval + * + * @return true if it is ok to replicate, false otherwise + */ + boolean okToReplicate(); + + /** + * Returns the log entry payload data version of the follower. + * + * @return the payload data version. */ - public String getId(); + short getPayloadVersion(); /** - * for each server, index of the next log entry - * to send to that server (initialized to leader - * last log index + 1) + * Sets the payload data version of the follower. + * + * @param payloadVersion the payload data version. */ - public AtomicLong getNextIndex(); + void setPayloadVersion(short payloadVersion); /** - * for each server, index of highest log entry - * known to be replicated on server - * (initialized to 0, increases monotonically) + * Returns the the raft version of the follower. + * + * @return the raft version of the follower. */ - public AtomicLong getMatchIndex(); + short getRaftVersion(); /** - * Checks if the follower is active by comparing the last updated with the duration - * @return boolean + * Sets the raft version of the follower. + * + * @param raftVersion the raft version. */ - public boolean isFollowerActive(); + void setRaftVersion(short raftVersion); /** - * restarts the timeout clock of the follower + * Returns the LeaderInstallSnapshotState for the in progress install snapshot. + * + * @return the LeaderInstallSnapshotState if a snapshot install is in progress, null otherwise. */ - public void markFollowerActive(); + @Nullable + LeaderInstallSnapshotState getInstallSnapshotState(); + /** + * Sets the LeaderInstallSnapshotState when an install snapshot is initiated. + * + * @param state the LeaderInstallSnapshotState + */ + void setLeaderInstallSnapshotState(@Nonnull LeaderInstallSnapshotState state); + /** + * Clears the LeaderInstallSnapshotState when an install snapshot is complete. + */ + void clearLeaderInstallSnapshotState(); }