Initial code for RaftActorServerConfigurationSupport
[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 /**
11  * The state of the followers log as known by the Leader
12  */
13 public interface FollowerLogInformation {
14
15     enum FollowerState {
16         VOTING,
17         NON_VOTING,
18         VOTING_NOT_INITIALIZED
19     };
20
21     /**
22      * Increment the value of the nextIndex
23      *
24      * @return the new value of nextIndex
25      */
26     long incrNextIndex();
27
28     /**
29      * Decrement the value of the nextIndex
30      *
31      * @return the new value of nextIndex
32      */
33     long decrNextIndex();
34
35     /**
36      * Sets the index of the next log entry for this follower.
37      *
38      * @param nextIndex
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      * Increment the value of the matchIndex
46      *
47      * @return the new value of matchIndex
48      */
49     long incrMatchIndex();
50
51     /**
52      * Sets the index of the highest log entry for this follower.
53      *
54      * @param matchIndex
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      *
62      * @return the identifier of the follower. This could simply be the url of the remote actor.
63      */
64     String getId();
65
66     /**
67      * @return index of the next log entry to send to that server (initialized to leader last log index + 1)
68      */
69     long getNextIndex();
70
71     /**
72      * @return index of highest log entry known to be replicated on server (initialized to 0, increases monotonically)
73      */
74     long getMatchIndex();
75
76     /**
77      * Checks if the follower is active by comparing the last updated with the duration
78      *
79      * @return true if follower is active, false otherwise
80      */
81     boolean isFollowerActive();
82
83     /**
84      * restarts the timeout clock of the follower
85      */
86     void markFollowerActive();
87
88     /**
89      * This will stop the timeout clock
90      */
91     void markFollowerInActive();
92
93
94     /**
95      * This will return the active time of follower, since it was last reset
96      *
97      * @return time in milliseconds since the last activity from the follower
98      */
99     long timeSinceLastActivity();
100
101     /**
102      * This method checks if it is ok to replicate
103      *
104      * @return true if it is ok to replicate, false otherwise
105      */
106     boolean okToReplicate();
107
108     /**
109      * @return the payload data version of the follower.
110      */
111     short getPayloadVersion();
112
113     /**
114      * Sets the payload data version of the follower.
115      */
116     void setPayloadVersion(short payloadVersion);
117
118     /**
119      * Sets the state of the follower.
120      */
121     void setFollowerState(FollowerState state);
122
123     /**
124      * @return the state of the follower.
125      */
126     FollowerState getFollowerState();
127
128     /**
129      * @return true if the follower is in a state where it can participate in leader elections and
130      *              commitment consensus.
131      */
132     boolean canParticipateInConsensus();
133 }