1
- # Tests that a node that is behind on the log will lose the vote.
2
- # It will still lose the vote when campaign again .
1
+ # Tests that a node that is behind on the log will lose the vote. Other nodes
2
+ # will have higher priority to start next campaign within current term .
3
3
4
4
log-level none
5
5
----
@@ -97,15 +97,17 @@ raft-log 2
97
97
----
98
98
1/11 EntryNormal ""
99
99
100
- # tick both nodes 9 times, it will trigger both to campaign, but
101
- # we will let node 2 try first. It will lose the vote due to log
102
- # being lag behind.
100
+ # tick both nodes 9 times, and let node 2 try first.
101
+ # 2 is de-prioritized on the next campaign. Its randomized election timeout
102
+ # is in range [2*electionTime, 3*electionTime), namely [10, 15). So 9 ticks
103
+ # shouldn't trigger the campaign.
103
104
tick 2 9
104
105
----
105
- INFO 2 is starting a new election at term 2
106
- INFO 2 became candidate at term 3
107
- INFO 2 [logterm: 1, index: 11] sent MsgVote request to 1 at term 3
106
+ ok
108
107
108
+ # node 1's randomized election timeout doesn't change, it's still in range
109
+ # [electionTime, 2*electionTime), namely [5, 10). So 9 ticks will definitely
110
+ # trigger the campaign.
109
111
tick 1 9
110
112
----
111
113
INFO 1 is starting a new election at term 2
@@ -115,18 +117,11 @@ INFO 1 [logterm: 1, index: 12] sent MsgVote request to 2 at term 3
115
117
# let node 2 try first
116
118
process-ready 2
117
119
----
118
- Ready MustSync=true:
119
- Lead:0 State:StateCandidate
120
- HardState Term:3 Vote:2 Commit:11
121
- Messages:
122
- 2->1 MsgVote Term:3 Log:1/11
123
- INFO 2 received MsgVoteResp from 2 at term 3
124
- INFO 2 has received 1 MsgVoteResp votes and 0 vote rejections
120
+ <empty Ready>
125
121
126
122
deliver-msgs 1
127
123
----
128
- 2->1 MsgVote Term:3 Log:1/11
129
- INFO 1 [logterm: 1, index: 12, vote: 1] rejected MsgVote from 2 [logterm: 1, index: 11] at term 3
124
+ no messages
130
125
131
126
stabilize
132
127
----
@@ -136,40 +131,97 @@ stabilize
136
131
HardState Term:3 Vote:1 Commit:11
137
132
Messages:
138
133
1->2 MsgVote Term:3 Log:1/12
139
- 1->2 MsgVoteResp Term:3 Log:0/0 Rejected (Hint: 0)
140
134
INFO 1 received MsgVoteResp from 1 at term 3
141
135
INFO 1 has received 1 MsgVoteResp votes and 0 vote rejections
142
136
> 2 receiving messages
143
137
1->2 MsgVote Term:3 Log:1/12
144
- INFO 2 [logterm: 1, index: 11, vote: 2] rejected MsgVote from 1 [logterm: 1, index: 12] at term 3
145
- 1->2 MsgVoteResp Term:3 Log:0/0 Rejected (Hint: 0)
146
- INFO 2 received MsgVoteResp rejection from 1 at term 3
147
- INFO 2 has received 1 MsgVoteResp votes and 1 vote rejections
138
+ INFO 2 [term: 2] received a MsgVote message with higher term from 1 [term: 3]
148
139
INFO 2 became follower at term 3
140
+ INFO 2 [logterm: 1, index: 11, vote: 0] cast MsgVote for 1 [logterm: 1, index: 12] at term 3
141
+ > 2 handling Ready
142
+ Ready MustSync=true:
143
+ HardState Term:3 Vote:1 Commit:11
144
+ Messages:
145
+ 2->1 MsgVoteResp Term:3 Log:0/0
146
+ > 1 receiving messages
147
+ 2->1 MsgVoteResp Term:3 Log:0/0
148
+ INFO 1 received MsgVoteResp from 2 at term 3
149
+ INFO 1 has received 2 MsgVoteResp votes and 0 vote rejections
150
+ INFO 1 became leader at term 3
151
+ > 1 handling Ready
152
+ Ready MustSync=true:
153
+ Lead:1 State:StateLeader
154
+ Entries:
155
+ 3/13 EntryNormal ""
156
+ Messages:
157
+ 1->2 MsgApp Term:3 Log:1/12 Commit:11 Entries:[3/13 EntryNormal ""]
158
+ > 2 receiving messages
159
+ 1->2 MsgApp Term:3 Log:1/12 Commit:11 Entries:[3/13 EntryNormal ""]
160
+ DEBUG 2 [logterm: 0, index: 12] rejected MsgApp [logterm: 1, index: 12] from 1
149
161
> 2 handling Ready
150
162
Ready MustSync=false:
151
- Lead:0 State:StateFollower
163
+ Lead:1 State:StateFollower
152
164
Messages:
153
- 2->1 MsgVoteResp Term:3 Log:0/0 Rejected (Hint: 0 )
165
+ 2->1 MsgAppResp Term:3 Log:1/12 Rejected (Hint: 11 )
154
166
> 1 receiving messages
155
- 2->1 MsgVoteResp Term:3 Log:0/0 Rejected (Hint: 0)
156
- INFO 1 received MsgVoteResp rejection from 2 at term 3
157
- INFO 1 has received 1 MsgVoteResp votes and 1 vote rejections
158
- INFO 1 became follower at term 3
167
+ 2->1 MsgAppResp Term:3 Log:1/12 Rejected (Hint: 11)
168
+ DEBUG 1 received MsgAppResp(rejected, hint: (index 11, term 1)) from 2 for index 12
169
+ DEBUG 1 decreased progress of 2 to [StateProbe match=0 next=12]
159
170
> 1 handling Ready
160
171
Ready MustSync=false:
161
- Lead:0 State:StateFollower
172
+ Messages:
173
+ 1->2 MsgApp Term:3 Log:1/11 Commit:11 Entries:[
174
+ 1/12 EntryNormal "foo"
175
+ 3/13 EntryNormal ""
176
+ ]
177
+ > 2 receiving messages
178
+ 1->2 MsgApp Term:3 Log:1/11 Commit:11 Entries:[
179
+ 1/12 EntryNormal "foo"
180
+ 3/13 EntryNormal ""
181
+ ]
182
+ > 2 handling Ready
183
+ Ready MustSync=true:
184
+ Entries:
185
+ 1/12 EntryNormal "foo"
186
+ 3/13 EntryNormal ""
187
+ Messages:
188
+ 2->1 MsgAppResp Term:3 Log:0/13
189
+ > 1 receiving messages
190
+ 2->1 MsgAppResp Term:3 Log:0/13
191
+ > 1 handling Ready
192
+ Ready MustSync=false:
193
+ HardState Term:3 Vote:1 Commit:13
194
+ CommittedEntries:
195
+ 1/12 EntryNormal "foo"
196
+ 3/13 EntryNormal ""
197
+ Messages:
198
+ 1->2 MsgApp Term:3 Log:3/13 Commit:13
199
+ > 2 receiving messages
200
+ 1->2 MsgApp Term:3 Log:3/13 Commit:13
201
+ > 2 handling Ready
202
+ Ready MustSync=false:
203
+ HardState Term:3 Vote:1 Commit:13
204
+ CommittedEntries:
205
+ 1/12 EntryNormal "foo"
206
+ 3/13 EntryNormal ""
207
+ Messages:
208
+ 2->1 MsgAppResp Term:3 Log:0/13
209
+ > 1 receiving messages
210
+ 2->1 MsgAppResp Term:3 Log:0/13
162
211
163
212
raft-state
164
213
----
165
- 1: StateFollower (Voter) Term:3 Lead:0
166
- 2: StateFollower (Voter) Term:3 Lead:0
214
+ 1: StateLeader (Voter) Term:3 Lead:1
215
+ 2: StateFollower (Voter) Term:3 Lead:1
167
216
168
217
raft-log 1
169
218
----
170
219
1/11 EntryNormal ""
171
220
1/12 EntryNormal "foo"
221
+ 3/13 EntryNormal ""
172
222
173
223
raft-log 2
174
224
----
175
225
1/11 EntryNormal ""
226
+ 1/12 EntryNormal "foo"
227
+ 3/13 EntryNormal ""
0 commit comments