c0855c7f71835971f0cd81ffd70430dbeecb5a0c
[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 javax.annotation.Nonnull;
11 import javax.annotation.Nullable;
12 import org.opendaylight.controller.cluster.raft.behaviors.LeaderInstallSnapshotState;
13
14 /**
15  * The state of the followers log as known by the Leader
16  */
17 public interface FollowerLogInformation {
18
19     /**
20      * Increment the value of the nextIndex
21      *
22      * @return the new value of nextIndex
23      */
24     long incrNextIndex();
25
26     /**
27      * Decrement the value of the nextIndex
28      *
29      * @return the new value of nextIndex
30      */
31     long decrNextIndex();
32
33     /**
34      * Sets the index of the next log entry for this follower.
35      *
36      * @param nextIndex
37      * @return true if the new index differed from the current index and the current index was updated, false
38      *              otherwise.
39      */
40     boolean setNextIndex(long nextIndex);
41
42     /**
43      * Increment the value of the matchIndex
44      *
45      * @return the new value of matchIndex
46      */
47     long incrMatchIndex();
48
49     /**
50      * Sets the index of the highest log entry for this follower.
51      *
52      * @param matchIndex
53      * @return true if the new index differed from the current index and the current index was updated, false
54      *              otherwise.
55      */
56     boolean setMatchIndex(long matchIndex);
57
58     /**
59      *
60      * @return the identifier of the follower. This could simply be the url of the remote actor.
61      */
62     String getId();
63
64     /**
65      * @return index of the next log entry to send to that server (initialized to leader last log index + 1)
66      */
67     long getNextIndex();
68
69     /**
70      * @return index of highest log entry known to be replicated on server (initialized to 0, increases monotonically)
71      */
72     long getMatchIndex();
73
74     /**
75      * Checks if the follower is active by comparing the last updated with the duration
76      *
77      * @return true if follower is active, false otherwise
78      */
79     boolean isFollowerActive();
80
81     /**
82      * restarts the timeout clock of the follower
83      */
84     void markFollowerActive();
85
86     /**
87      * This will stop the timeout clock
88      */
89     void markFollowerInActive();
90
91
92     /**
93      * This will return the active time of follower, since it was last reset
94      *
95      * @return time in milliseconds since the last activity from the follower
96      */
97     long timeSinceLastActivity();
98
99     /**
100      * This method checks if it is ok to replicate
101      *
102      * @return true if it is ok to replicate, false otherwise
103      */
104     boolean okToReplicate();
105
106     /**
107      * @return the payload data version of the follower.
108      */
109     short getPayloadVersion();
110
111     /**
112      * Sets the payload data version of the follower.
113      */
114     void setPayloadVersion(short payloadVersion);
115
116     /**
117      * @return the raft version of the follower.
118      */
119     short getRaftVersion();
120
121     /**
122      * Sets the raft version of the follower.
123      */
124     void setRaftVersion(short payloadVersion);
125
126     /**
127      * Returns the LeaderInstallSnapshotState for the in progress install snapshot.
128      *
129      * @return the LeaderInstallSnapshotState if a snapshot install is in progress, null otherwise.
130      */
131     @Nullable
132     LeaderInstallSnapshotState getInstallSnapshotState();
133
134     /**
135      * Sets the LeaderInstallSnapshotState when an install snapshot is initiated.
136      *
137      * @param state the LeaderInstallSnapshotState
138      */
139     void setLeaderInstallSnapshotState(@Nonnull LeaderInstallSnapshotState state);
140
141     /**
142      * Clears the LeaderInstallSnapshotState when an install snapshot is complete.
143      */
144     void clearLeaderInstallSnapshotState();
145 }