Skip to content

Commit

Permalink
regenerate raft testdata
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Sep 1, 2022
1 parent d1957fe commit cf9306b
Show file tree
Hide file tree
Showing 11 changed files with 351 additions and 1,029 deletions.
6 changes: 5 additions & 1 deletion raft/rafttest/interaction_env_handler_propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ func (env *InteractionEnv) handlePropose(t *testing.T, d datadriven.TestData) er
if len(d.CmdArgs) != 2 || len(d.CmdArgs[1].Vals) > 0 {
t.Fatalf("expected exactly one key with no vals: %+v", d.CmdArgs[1:])
}
return env.Propose(idx, []byte(d.CmdArgs[1].Key))
if err := env.Propose(idx, []byte(d.CmdArgs[1].Key)); err != nil {
return err
}

return env.ReportStatus(idx)
}

// Propose a regular entry.
Expand Down
19 changes: 18 additions & 1 deletion raft/rafttest/interaction_env_handler_propose_conf_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,27 @@ func (env *InteractionEnv) handleProposeConfChange(t *testing.T, d datadriven.Te
Changes: ccs,
}
}
return env.ProposeConfChange(idx, c)
if err := env.ProposeConfChange(idx, c); err != nil {
return err
}

return env.ReportStatus(idx)
}

// ProposeConfChange proposes a configuration change on the node with the given index.
func (env *InteractionEnv) ProposeConfChange(idx int, c raftpb.ConfChangeI) error {
return env.Nodes[idx].ProposeConfChange(c)
}

func (env *InteractionEnv) ReportStatus(idx int) error {
rn := env.Nodes[idx]
rd := rn.Ready()
status := rn.Status()

if status.ID == status.Lead && (len(rd.Entries) > 1 || (len(rd.Entries) == 1 && len(rd.Entries[0].Data) > 0)) {
e := rd.Entries[len(rd.Entries)-1]
return rn.Step(raftpb.Message{From: status.ID, To: status.ID, Type: raftpb.MsgAppResp, Index: e.Index})
}

return nil
}
83 changes: 5 additions & 78 deletions raft/testdata/campaign_learner_must_vote.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,98 +55,25 @@ campaign 2
INFO 2 is starting a new election at term 1
INFO 2 became candidate at term 2
INFO 2 received MsgVoteResp from 2 at term 2
INFO 2 [logterm: 1, index: 4] sent MsgVote request to 1 at term 2
INFO 2 [logterm: 1, index: 4] sent MsgVote request to 3 at term 2
INFO 2 [logterm: 1, index: 3] sent MsgVote request to 1 at term 2

# Send out the MsgVote requests.
process-ready 2
----
Ready MustSync=true:
Lead:0 State:StateCandidate
HardState Term:2 Vote:2 Commit:4
HardState Term:2 Vote:2 Commit:3
Messages:
2->1 MsgVote Term:2 Log:1/4
2->3 MsgVote Term:2 Log:1/4
2->1 MsgVote Term:2 Log:1/3

# n2 is now campaigning while n1 is down (does not respond). The latest config
# has n3 as a voter, but n3 doesn't even have the corresponding conf change in
# its log. Still, it casts a vote for n2 which can in turn become leader and
# catches up n3.
stabilize 3
----
> 3 receiving messages
2->3 MsgVote Term:2 Log:1/4
INFO 3 [term: 1] received a MsgVote message with higher term from 2 [term: 2]
INFO 3 became follower at term 2
INFO 3 [logterm: 1, index: 3, vote: 0] cast MsgVote for 2 [logterm: 1, index: 4] at term 2
> 3 handling Ready
Ready MustSync=true:
Lead:0 State:StateFollower
HardState Term:2 Vote:2 Commit:3
Messages:
3->2 MsgVoteResp Term:2 Log:0/0
ok

stabilize 2 3
----
> 2 receiving messages
3->2 MsgVoteResp Term:2 Log:0/0
INFO 2 received MsgVoteResp from 3 at term 2
INFO 2 has received 2 MsgVoteResp votes and 0 vote rejections
INFO 2 became leader at term 2
> 2 handling Ready
Ready MustSync=true:
Lead:2 State:StateLeader
Entries:
2/5 EntryNormal ""
Messages:
2->1 MsgApp Term:2 Log:1/4 Commit:4 Entries:[2/5 EntryNormal ""]
2->3 MsgApp Term:2 Log:1/4 Commit:4 Entries:[2/5 EntryNormal ""]
> 3 receiving messages
2->3 MsgApp Term:2 Log:1/4 Commit:4 Entries:[2/5 EntryNormal ""]
DEBUG 3 [logterm: 0, index: 4] rejected MsgApp [logterm: 1, index: 4] from 2
> 3 handling Ready
Ready MustSync=false:
Lead:2 State:StateFollower
Messages:
3->2 MsgAppResp Term:2 Log:1/4 Rejected (Hint: 3)
> 2 receiving messages
3->2 MsgAppResp Term:2 Log:1/4 Rejected (Hint: 3)
DEBUG 2 received MsgAppResp(rejected, hint: (index 3, term 1)) from 3 for index 4
DEBUG 2 decreased progress of 3 to [StateProbe match=0 next=4]
> 2 handling Ready
Ready MustSync=false:
Messages:
2->3 MsgApp Term:2 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v3, 2/5 EntryNormal ""]
> 3 receiving messages
2->3 MsgApp Term:2 Log:1/3 Commit:4 Entries:[1/4 EntryConfChangeV2 v3, 2/5 EntryNormal ""]
> 3 handling Ready
Ready MustSync=true:
HardState Term:2 Vote:2 Commit:4
Entries:
1/4 EntryConfChangeV2 v3
2/5 EntryNormal ""
CommittedEntries:
1/4 EntryConfChangeV2 v3
Messages:
3->2 MsgAppResp Term:2 Log:0/5
INFO 3 switched to configuration voters=(1 2 3)
> 2 receiving messages
3->2 MsgAppResp Term:2 Log:0/5
> 2 handling Ready
Ready MustSync=false:
HardState Term:2 Vote:2 Commit:5
CommittedEntries:
2/5 EntryNormal ""
Messages:
2->3 MsgApp Term:2 Log:2/5 Commit:5
> 3 receiving messages
2->3 MsgApp Term:2 Log:2/5 Commit:5
> 3 handling Ready
Ready MustSync=false:
HardState Term:2 Vote:2 Commit:5
CommittedEntries:
2/5 EntryNormal ""
Messages:
3->2 MsgAppResp Term:2 Log:0/5
> 2 receiving messages
3->2 MsgAppResp Term:2 Log:0/5
ok
1 change: 0 additions & 1 deletion raft/testdata/confchange_v1_add_single.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ stabilize
----
> 1 handling Ready
Ready MustSync=true:
Lead:1 State:StateLeader
HardState Term:1 Vote:1 Commit:4
Entries:
1/3 EntryNormal ""
Expand Down
Loading

0 comments on commit cf9306b

Please sign in to comment.