2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.raft;
10 import com.google.common.annotations.VisibleForTesting;
11 import javax.annotation.Nonnull;
12 import javax.annotation.Nullable;
13 import org.opendaylight.controller.cluster.raft.behaviors.LeaderInstallSnapshotState;
16 * The state of the followers log as known by the Leader.
18 public interface FollowerLogInformation {
21 * Increments the value of the follower's next index.
23 * @return the new value of nextIndex.
28 * Decrements the value of the follower's next index.
30 * @return true if the next index was decremented, ie it was previously >= 0, false otherwise.
32 boolean decrNextIndex();
35 * Sets the index of the follower's next log entry.
37 * @param nextIndex the new index.
38 * @return true if the new index differed from the current index and the current index was updated, false
41 boolean setNextIndex(long nextIndex);
44 * Increments the value of the follower's match index.
46 * @return the new value of matchIndex.
48 long incrMatchIndex();
51 * Sets the index of the follower's highest log entry.
53 * @param matchIndex the new index.
54 * @return true if the new index differed from the current index and the current index was updated, false
57 boolean setMatchIndex(long matchIndex);
60 * Returns the identifier of the follower.
62 * @return the identifier of the follower.
67 * Returns the index of the next log entry to send to the follower.
69 * @return index of the follower's next log entry.
74 * Returns the index of highest log entry known to be replicated on the follower.
76 * @return the index of highest log entry.
81 * Checks if the follower is active by comparing the time of the last activity with the election time out. The
82 * follower is active if some activity has occurred for the follower within the election time out interval.
84 * @return true if follower is active, false otherwise.
86 boolean isFollowerActive();
89 * Marks the follower as active. This should be called when some activity has occurred for the follower.
91 void markFollowerActive();
94 * Marks the follower as inactive. This should only be called from unit tests.
97 void markFollowerInActive();
101 * Returns the time since the last activity occurred for the follower.
103 * @return time in milliseconds since the last activity from the follower.
105 long timeSinceLastActivity();
108 * This method checks if the next replicate message can be sent to the follower. This is an optimization to avoid
109 * sending duplicate message too frequently if the last replicate message was sent and no reply has been received
110 * yet within the current heart beat interval
112 * @return true if it is ok to replicate, false otherwise
114 boolean okToReplicate();
117 * Returns the log entry payload data version of the follower.
119 * @return the payload data version.
121 short getPayloadVersion();
124 * Sets the payload data version of the follower.
126 * @param payloadVersion the payload data version.
128 void setPayloadVersion(short payloadVersion);
131 * Returns the the raft version of the follower.
133 * @return the raft version of the follower.
135 short getRaftVersion();
138 * Sets the raft version of the follower.
140 * @param raftVersion the raft version.
142 void setRaftVersion(short raftVersion);
145 * Returns the LeaderInstallSnapshotState for the in progress install snapshot.
147 * @return the LeaderInstallSnapshotState if a snapshot install is in progress, null otherwise.
150 LeaderInstallSnapshotState getInstallSnapshotState();
153 * Sets the LeaderInstallSnapshotState when an install snapshot is initiated.
155 * @param state the LeaderInstallSnapshotState
157 void setLeaderInstallSnapshotState(@Nonnull LeaderInstallSnapshotState state);
160 * Clears the LeaderInstallSnapshotState when an install snapshot is complete.
162 void clearLeaderInstallSnapshotState();