Skip to content

Commit

Permalink
Update the test vote.txt to demo the node being de-priotized on next …
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
ahrtr committed Mar 4, 2024
1 parent f0c915f commit 1e3047d
Showing 1 changed file with 83 additions and 31 deletions.
114 changes: 83 additions & 31 deletions testdata/vote.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Tests that a node that is behind on the log will lose the vote.
# It will still lose the vote when campaign again.
# Tests that a node that is behind on the log will lose the vote. Other nodes
# will have higher priority to start next campaign within current term.

log-level none
----
Expand Down Expand Up @@ -97,15 +97,17 @@ raft-log 2
----
1/11 EntryNormal ""

# tick both nodes 9 times, it will trigger both to campaign, but
# we will let node 2 try first. It will lose the vote due to log
# being lag behind.
# tick both nodes 9 times, and let node 2 try first.
# 2 is de-prioritized on the next campaign. Its randomized election timeout
# is in range [2*electionTime, 3*electionTime), namely [10, 15). So 9 ticks
# shouldn't trigger the campaign.
tick 2 9
----
INFO 2 is starting a new election at term 2
INFO 2 became candidate at term 3
INFO 2 [logterm: 1, index: 11] sent MsgVote request to 1 at term 3
ok

# node 1's randomized election timeout doesn't change, it's still in range
# [electionTime, 2*electionTime), namely [5, 10). So 9 ticks will definitely
# trigger the campaign.
tick 1 9
----
INFO 1 is starting a new election at term 2
Expand All @@ -115,18 +117,11 @@ INFO 1 [logterm: 1, index: 12] sent MsgVote request to 2 at term 3
# let node 2 try first
process-ready 2
----
Ready MustSync=true:
Lead:0 State:StateCandidate
HardState Term:3 Vote:2 Commit:11
Messages:
2->1 MsgVote Term:3 Log:1/11
INFO 2 received MsgVoteResp from 2 at term 3
INFO 2 has received 1 MsgVoteResp votes and 0 vote rejections
<empty Ready>

deliver-msgs 1
----
2->1 MsgVote Term:3 Log:1/11
INFO 1 [logterm: 1, index: 12, vote: 1] rejected MsgVote from 2 [logterm: 1, index: 11] at term 3
no messages

stabilize
----
Expand All @@ -136,40 +131,97 @@ stabilize
HardState Term:3 Vote:1 Commit:11
Messages:
1->2 MsgVote Term:3 Log:1/12
1->2 MsgVoteResp Term:3 Log:0/0 Rejected (Hint: 0)
INFO 1 received MsgVoteResp from 1 at term 3
INFO 1 has received 1 MsgVoteResp votes and 0 vote rejections
> 2 receiving messages
1->2 MsgVote Term:3 Log:1/12
INFO 2 [logterm: 1, index: 11, vote: 2] rejected MsgVote from 1 [logterm: 1, index: 12] at term 3
1->2 MsgVoteResp Term:3 Log:0/0 Rejected (Hint: 0)
INFO 2 received MsgVoteResp rejection from 1 at term 3
INFO 2 has received 1 MsgVoteResp votes and 1 vote rejections
INFO 2 [term: 2] received a MsgVote message with higher term from 1 [term: 3]
INFO 2 became follower at term 3
INFO 2 [logterm: 1, index: 11, vote: 0] cast MsgVote for 1 [logterm: 1, index: 12] at term 3
> 2 handling Ready
Ready MustSync=true:
HardState Term:3 Vote:1 Commit:11
Messages:
2->1 MsgVoteResp Term:3 Log:0/0
> 1 receiving messages
2->1 MsgVoteResp Term:3 Log:0/0
INFO 1 received MsgVoteResp from 2 at term 3
INFO 1 has received 2 MsgVoteResp votes and 0 vote rejections
INFO 1 became leader at term 3
> 1 handling Ready
Ready MustSync=true:
Lead:1 State:StateLeader
Entries:
3/13 EntryNormal ""
Messages:
1->2 MsgApp Term:3 Log:1/12 Commit:11 Entries:[3/13 EntryNormal ""]
> 2 receiving messages
1->2 MsgApp Term:3 Log:1/12 Commit:11 Entries:[3/13 EntryNormal ""]
DEBUG 2 [logterm: 0, index: 12] rejected MsgApp [logterm: 1, index: 12] from 1
> 2 handling Ready
Ready MustSync=false:
Lead:0 State:StateFollower
Lead:1 State:StateFollower
Messages:
2->1 MsgVoteResp Term:3 Log:0/0 Rejected (Hint: 0)
2->1 MsgAppResp Term:3 Log:1/12 Rejected (Hint: 11)
> 1 receiving messages
2->1 MsgVoteResp Term:3 Log:0/0 Rejected (Hint: 0)
INFO 1 received MsgVoteResp rejection from 2 at term 3
INFO 1 has received 1 MsgVoteResp votes and 1 vote rejections
INFO 1 became follower at term 3
2->1 MsgAppResp Term:3 Log:1/12 Rejected (Hint: 11)
DEBUG 1 received MsgAppResp(rejected, hint: (index 11, term 1)) from 2 for index 12
DEBUG 1 decreased progress of 2 to [StateProbe match=0 next=12]
> 1 handling Ready
Ready MustSync=false:
Lead:0 State:StateFollower
Messages:
1->2 MsgApp Term:3 Log:1/11 Commit:11 Entries:[
1/12 EntryNormal "foo"
3/13 EntryNormal ""
]
> 2 receiving messages
1->2 MsgApp Term:3 Log:1/11 Commit:11 Entries:[
1/12 EntryNormal "foo"
3/13 EntryNormal ""
]
> 2 handling Ready
Ready MustSync=true:
Entries:
1/12 EntryNormal "foo"
3/13 EntryNormal ""
Messages:
2->1 MsgAppResp Term:3 Log:0/13
> 1 receiving messages
2->1 MsgAppResp Term:3 Log:0/13
> 1 handling Ready
Ready MustSync=false:
HardState Term:3 Vote:1 Commit:13
CommittedEntries:
1/12 EntryNormal "foo"
3/13 EntryNormal ""
Messages:
1->2 MsgApp Term:3 Log:3/13 Commit:13
> 2 receiving messages
1->2 MsgApp Term:3 Log:3/13 Commit:13
> 2 handling Ready
Ready MustSync=false:
HardState Term:3 Vote:1 Commit:13
CommittedEntries:
1/12 EntryNormal "foo"
3/13 EntryNormal ""
Messages:
2->1 MsgAppResp Term:3 Log:0/13
> 1 receiving messages
2->1 MsgAppResp Term:3 Log:0/13

raft-state
----
1: StateFollower (Voter) Term:3 Lead:0
2: StateFollower (Voter) Term:3 Lead:0
1: StateLeader (Voter) Term:3 Lead:1
2: StateFollower (Voter) Term:3 Lead:1

raft-log 1
----
1/11 EntryNormal ""
1/12 EntryNormal "foo"
3/13 EntryNormal ""

raft-log 2
----
1/11 EntryNormal ""
1/12 EntryNormal "foo"
3/13 EntryNormal ""

0 comments on commit 1e3047d

Please sign in to comment.