Bug 2890: Chunk AppendEntries when single payload size exceeds threshold
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / FollowerLogInformation.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.raft;
9
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;
14
15 /**
16  * The state of the followers log as known by the Leader.
17  */
18 public interface FollowerLogInformation {
19     long NO_INDEX = -1;
20
21     /**
22      * Increments the value of the follower's next index.
23      *
24      * @return the new value of nextIndex.
25      */
26     long incrNextIndex();
27
28     /**
29      * Decrements the value of the follower's next index.
30      *
31      * @return true if the next index was decremented, ie it was previously >= 0, false otherwise.
32      */
33     boolean decrNextIndex();
34
35     /**
36      * Sets the index of the follower's next log entry.
37      *
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
40      *              otherwise.
41      */
42     boolean setNextIndex(long nextIndex);
43
44     /**
45      * Increments the value of the follower's match index.
46      *
47      * @return the new value of matchIndex.
48      */
49     long incrMatchIndex();
50
51     /**
52      * Sets the index of the follower's highest log entry.
53      *
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
56      *              otherwise.
57      */
58     boolean setMatchIndex(long matchIndex);
59
60     /**
61      * Returns the identifier of the follower.
62      *
63      * @return the identifier of the follower.
64      */
65     String getId();
66
67     /**
68      * Returns the index of the next log entry to send to the follower.
69      *
70      * @return index of the follower's next log entry.
71      */
72     long getNextIndex();
73
74     /**
75      * Returns the index of highest log entry known to be replicated on the follower.
76      *
77      * @return the index of highest log entry.
78      */
79     long getMatchIndex();
80
81     /**
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.
84      *
85      * @return true if follower is active, false otherwise.
86      */
87     boolean isFollowerActive();
88
89     /**
90      * Marks the follower as active. This should be called when some activity has occurred for the follower.
91      */
92     void markFollowerActive();
93
94     /**
95      * Marks the follower as inactive. This should only be called from unit tests.
96      */
97     @VisibleForTesting
98     void markFollowerInActive();
99
100
101     /**
102      * Returns the time since the last activity occurred for the follower.
103      *
104      * @return time in milliseconds since the last activity from the follower.
105      */
106     long timeSinceLastActivity();
107
108     /**
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
112      *
113      * @return true if it is ok to replicate, false otherwise
114      */
115     boolean okToReplicate();
116
117     /**
118      * Returns the log entry payload data version of the follower.
119      *
120      * @return the payload data version.
121      */
122     short getPayloadVersion();
123
124     /**
125      * Sets the payload data version of the follower.
126      *
127      * @param payloadVersion the payload data version.
128      */
129     void setPayloadVersion(short payloadVersion);
130
131     /**
132      * Returns the the raft version of the follower.
133      *
134      * @return the raft version of the follower.
135      */
136     short getRaftVersion();
137
138     /**
139      * Sets the raft version of the follower.
140      *
141      * @param raftVersion the raft version.
142      */
143     void setRaftVersion(short raftVersion);
144
145     /**
146      * Returns the LeaderInstallSnapshotState for the in progress install snapshot.
147      *
148      * @return the LeaderInstallSnapshotState if a snapshot install is in progress, null otherwise.
149      */
150     @Nullable
151     LeaderInstallSnapshotState getInstallSnapshotState();
152
153     /**
154      * Sets the LeaderInstallSnapshotState when an install snapshot is initiated.
155      *
156      * @param state the LeaderInstallSnapshotState
157      */
158     void setLeaderInstallSnapshotState(@Nonnull LeaderInstallSnapshotState state);
159
160     /**
161      * Clears the LeaderInstallSnapshotState when an install snapshot is complete.
162      */
163     void clearLeaderInstallSnapshotState();
164
165     /**
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.
168      *
169      * @param index the log entry index or NO_INDEX to clear it
170      */
171     void setSlicedLogEntryIndex(long index);
172
173     /**
174      * Return whether or not log entry slicing is currently in progress.
175      *
176      * @return true if slicing is currently in progress, false otherwise
177      */
178     boolean isLogEntrySlicingInProgress();
179 }