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 {
22 * Increments the value of the follower's next index.
24 * @return the new value of nextIndex.
29 * Decrements the value of the follower's next index.
31 * @return true if the next index was decremented, ie it was previously >= 0, false otherwise.
33 boolean decrNextIndex();
36 * Sets the index of the follower's next log entry.
38 * @param nextIndex the new index.
39 * @return true if the new index differed from the current index and the current index was updated, false
42 boolean setNextIndex(long nextIndex);
45 * Increments the value of the follower's match index.
47 * @return the new value of matchIndex.
49 long incrMatchIndex();
52 * Sets the index of the follower's highest log entry.
54 * @param matchIndex the new index.
55 * @return true if the new index differed from the current index and the current index was updated, false
58 boolean setMatchIndex(long matchIndex);
61 * Returns the identifier of the follower.
63 * @return the identifier of the follower.
68 * Returns the index of the next log entry to send to the follower.
70 * @return index of the follower's next log entry.
75 * Returns the index of highest log entry known to be replicated on the follower.
77 * @return the index of highest log entry.
82 * Checks if the follower is active by comparing the time of the last activity with the election time out. The
83 * follower is active if some activity has occurred for the follower within the election time out interval.
85 * @return true if follower is active, false otherwise.
87 boolean isFollowerActive();
90 * Marks the follower as active. This should be called when some activity has occurred for the follower.
92 void markFollowerActive();
95 * Marks the follower as inactive. This should only be called from unit tests.
98 void markFollowerInActive();
102 * Returns the time since the last activity occurred for the follower.
104 * @return time in milliseconds since the last activity from the follower.
106 long timeSinceLastActivity();
109 * This method checks if the next replicate message can be sent to the follower. This is an optimization to avoid
110 * sending duplicate message too frequently if the last replicate message was sent and no reply has been received
111 * yet within the current heart beat interval
113 * @return true if it is ok to replicate, false otherwise
115 boolean okToReplicate();
118 * Returns the log entry payload data version of the follower.
120 * @return the payload data version.
122 short getPayloadVersion();
125 * Sets the payload data version of the follower.
127 * @param payloadVersion the payload data version.
129 void setPayloadVersion(short payloadVersion);
132 * Returns the the raft version of the follower.
134 * @return the raft version of the follower.
136 short getRaftVersion();
139 * Sets the raft version of the follower.
141 * @param raftVersion the raft version.
143 void setRaftVersion(short raftVersion);
146 * Returns the LeaderInstallSnapshotState for the in progress install snapshot.
148 * @return the LeaderInstallSnapshotState if a snapshot install is in progress, null otherwise.
151 LeaderInstallSnapshotState getInstallSnapshotState();
154 * Sets the LeaderInstallSnapshotState when an install snapshot is initiated.
156 * @param state the LeaderInstallSnapshotState
158 void setLeaderInstallSnapshotState(@Nonnull LeaderInstallSnapshotState state);
161 * Clears the LeaderInstallSnapshotState when an install snapshot is complete.
163 void clearLeaderInstallSnapshotState();
166 * Sets the index of the log entry whose payload size exceeds the maximum size for a single message and thus
167 * needs to be sliced into smaller chunks.
169 * @param index the log entry index or NO_INDEX to clear it
171 void setSlicedLogEntryIndex(long index);
174 * Return whether or not log entry slicing is currently in progress.
176 * @return true if slicing is currently in progress, false otherwise
178 boolean isLogEntrySlicingInProgress();