Skip to content

Commit 800831c

Browse files
committed
Update the test vote.txt to demo the node being de-priotized on next campaign
When a node lost the vote, it will be de-prioritized on the next campaign. Its randomized election timeout is in range [2*electionTime, 3*electionTime). Signed-off-by: Benjamin Wang <[email protected]>
1 parent 49311b0 commit 800831c

File tree

1 file changed

+83
-31
lines changed

1 file changed

+83
-31
lines changed

testdata/vote.txt

Lines changed: 83 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
33

44
log-level none
55
----
@@ -97,15 +97,17 @@ raft-log 2
9797
----
9898
1/11 EntryNormal ""
9999

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.
103104
tick 2 9
104105
----
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
108107

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.
109111
tick 1 9
110112
----
111113
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
115117
# let node 2 try first
116118
process-ready 2
117119
----
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>
125121

126122
deliver-msgs 1
127123
----
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
130125

131126
stabilize
132127
----
@@ -136,40 +131,97 @@ stabilize
136131
HardState Term:3 Vote:1 Commit:11
137132
Messages:
138133
1->2 MsgVote Term:3 Log:1/12
139-
1->2 MsgVoteResp Term:3 Log:0/0 Rejected (Hint: 0)
140134
INFO 1 received MsgVoteResp from 1 at term 3
141135
INFO 1 has received 1 MsgVoteResp votes and 0 vote rejections
142136
> 2 receiving messages
143137
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]
148139
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
149161
> 2 handling Ready
150162
Ready MustSync=false:
151-
Lead:0 State:StateFollower
163+
Lead:1 State:StateFollower
152164
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)
154166
> 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]
159170
> 1 handling Ready
160171
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
162211

163212
raft-state
164213
----
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
167216

168217
raft-log 1
169218
----
170219
1/11 EntryNormal ""
171220
1/12 EntryNormal "foo"
221+
3/13 EntryNormal ""
172222

173223
raft-log 2
174224
----
175225
1/11 EntryNormal ""
226+
1/12 EntryNormal "foo"
227+
3/13 EntryNormal ""

0 commit comments

Comments
 (0)