Skip to content

Commit

Permalink
updated the raft test data
Browse files Browse the repository at this point in the history
1. added one more command "report-status" so that the leader can acknowledges
   that the entries has already been persisted.
2. regenerated some test data.

Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Sep 2, 2022
1 parent 7ec19d9 commit a799416
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 0 deletions.
9 changes: 9 additions & 0 deletions raft/rafttest/interaction_env_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ func (env *InteractionEnv) Handle(t *testing.T, d datadriven.TestData) string {
// propose-conf-change 2 v1=true
// v5
err = env.handleProposeConfChange(t, d)
case "report-status":
// The leader acknowledges that the Entries has already been
// successfully persisted.
//
// Example:
//
// report-status 1
// 4
err = env.handleLeaderReportStatus(t, d)
default:
err = fmt.Errorf("unknown command")
}
Expand Down
37 changes: 37 additions & 0 deletions raft/rafttest/interaction_env_handler_leader_report_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2022 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package rafttest

import (
"strconv"
"testing"

"github.com/cockroachdb/datadriven"
pb "go.etcd.io/etcd/raft/v3/raftpb"
)

func (env *InteractionEnv) handleLeaderReportStatus(t *testing.T, d datadriven.TestData) error {
idx := firstAsNodeIdx(t, d)
logIndex, err := strconv.Atoi(d.Input)
if err != nil {
t.Fatalf("Invalid input for the report-status command: %s, error: %v", d.Input, err)
}
return env.ReportStatus(idx, logIndex)
}

func (env *InteractionEnv) ReportStatus(idx int, index int) error {
rn := env.Nodes[idx].RawNode
return rn.Step(pb.Message{From: rn.Status().ID, To: rn.Status().ID, Type: pb.MsgAppResp, Index: uint64(index)})
}
6 changes: 6 additions & 0 deletions raft/testdata/campaign_learner_must_vote.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ v3
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 1
4
----
ok

# Commit and fully apply said conf change. n1 and n2 now consider n3 a voter.
stabilize 1 2
----
Expand Down
6 changes: 6 additions & 0 deletions raft/testdata/confchange_v1_add_single.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ v2
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 1
4
----
ok

# Pull n2 out of thin air.
add-nodes 1
----
Expand Down
6 changes: 6 additions & 0 deletions raft/testdata/confchange_v1_remove_leader.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ r1
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 1
5
----
ok

raft-state
----
1: StateLeader (Voter)
Expand Down
20 changes: 20 additions & 0 deletions raft/testdata/confchange_v2_add_double_auto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ v2 v3
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 1
4
----
ok

# Add two "empty" nodes to the cluster, n2 and n3.
add-nodes 2
----
Expand Down Expand Up @@ -204,6 +210,12 @@ r2 r3
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 1
5
----
ok

# n1 sends out MsgApps.
stabilize 1
----
Expand Down Expand Up @@ -246,6 +258,12 @@ propose 1 bar
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 1
7
----
ok

# n1 switches to the joint config, then initiates a transition into the final
# config.
stabilize 1
Expand All @@ -260,9 +278,11 @@ stabilize 1
1->3 MsgApp Term:1 Log:1/6 Commit:5 Entries:[1/7 EntryNormal "foo"]
1->2 MsgApp Term:1 Log:1/7 Commit:5 Entries:[1/8 EntryNormal "bar"]
1->3 MsgApp Term:1 Log:1/7 Commit:5 Entries:[1/8 EntryNormal "bar"]
1->1 MsgApp Term:1 Log:1/7 Commit:5 Entries:[1/8 EntryNormal "bar"]
> 1 receiving messages
2->1 MsgAppResp Term:1 Log:0/6
3->1 MsgAppResp Term:1 Log:0/6
1->1 MsgApp Term:1 Log:1/7 Commit:5 Entries:[1/8 EntryNormal "bar"]
> 1 handling Ready
Ready MustSync=false:
HardState Term:1 Vote:1 Commit:6
Expand Down
6 changes: 6 additions & 0 deletions raft/testdata/confchange_v2_add_double_implicit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ v2
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 1
4
----
ok

# Add n2.
add-nodes 1
----
Expand Down
6 changes: 6 additions & 0 deletions raft/testdata/confchange_v2_add_single_auto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ v2
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 1
4
----
ok

# Pull n2 out of thin air.
add-nodes 1
----
Expand Down
12 changes: 12 additions & 0 deletions raft/testdata/confchange_v2_add_single_explicit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ v2
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 1
4
----
ok

# Pull n2 out of thin air.
add-nodes 1
----
Expand Down Expand Up @@ -110,6 +116,12 @@ propose-conf-change 1
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 1
6
----
ok

# The group commits the command and everyone switches to the final config.
stabilize
----
Expand Down
17 changes: 17 additions & 0 deletions raft/testdata/confchange_v2_replace_leader.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ r1 v4
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 1
4
----
ok

# Enter joint config.
stabilize
----
Expand Down Expand Up @@ -337,6 +343,12 @@ propose-conf-change 4
----
ok

# The leader acknowledges that the entries has already been persisted.
report-status 4
5
----
ok

# The group commits the command and everyone switches to the final config.
stabilize
----
Expand Down Expand Up @@ -416,11 +428,16 @@ stabilize
Messages:
3->4 MsgAppResp Term:2 Log:0/6
INFO 3 switched to configuration voters=(2 3 4)
> 4 handling Ready
Ready MustSync=false:
Messages:
4->4 MsgApp Term:2 Log:2/5 Commit:6 Entries:[2/6 EntryConfChangeV2]
> 4 receiving messages
1->4 MsgAppResp Term:2 Log:0/6
raft: cannot step as peer not found
2->4 MsgAppResp Term:2 Log:0/6
3->4 MsgAppResp Term:2 Log:0/6
4->4 MsgApp Term:2 Log:2/5 Commit:6 Entries:[2/6 EntryConfChangeV2]

# n1 is out of the configuration.
raft-state
Expand Down

0 comments on commit a799416

Please sign in to comment.