Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raft: properly setup BenchmarkStatus #138228

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/raft/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5217,6 +5217,7 @@ func SetRandomizedElectionTimeout(r *RawNode, v int64) {
// testConfigModifiers allows callers to optionally modify newTestConfig.
type testConfigModifiers struct {
testingStoreLiveness raftstoreliveness.StoreLiveness
testingLogger raftlogger.Logger
}

// testConfigModifierOpt is the type of an optional parameter to newTestConfig
Expand All @@ -5235,6 +5236,13 @@ func withStoreLiveness(storeLiveness raftstoreliveness.StoreLiveness) testConfig
}
}

// withLogger explicitly uses the supplied raft logger.
func withLogger(logger raftlogger.Logger) testConfigModifierOpt {
return func(modifier *testConfigModifiers) {
modifier.testingLogger = logger
}
}

func newTestConfig(
id pb.PeerID, election, heartbeat int64, storage Storage, opts ...testConfigModifierOpt,
) *Config {
Expand All @@ -5248,6 +5256,14 @@ func newTestConfig(
} else {
storeLiveness = raftstoreliveness.AlwaysLive{}
}

var logger raftlogger.Logger
if modifiers.testingLogger != nil {
logger = modifiers.testingLogger
} else {
logger = raftlogger.DefaultRaftLogger
}

return &Config{
ID: id,
ElectionTick: election,
Expand All @@ -5256,6 +5272,7 @@ func newTestConfig(
MaxSizePerMsg: noLimit,
MaxInflightMsgs: 256,
StoreLiveness: storeLiveness,
Logger: logger,
CRDBVersion: cluster.MakeTestingClusterSettings().Version,
Metrics: NewMetrics(),
}
Expand Down
17 changes: 10 additions & 7 deletions pkg/raft/rawnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,13 +887,16 @@ func BenchmarkStatus(b *testing.B) {
for i := range peers {
peers[i] = pb.PeerID(i + 1)
}
cfg := newTestConfig(1, 3, 1, newTestMemoryStorage(withPeers(peers...)))
cfg.Logger = raftlogger.DiscardLogger
r := newRaft(cfg)
r.becomeFollower(1, 1)
r.becomeCandidate()
r.becomeLeader()
return &RawNode{raft: r}

raftPeers := make([]stateMachine, members)
for i := range raftPeers {
raftPeers[i] = newTestRaft(pb.PeerID(i+1), 10, 1, newTestMemoryStorage(withPeers(peers...)),
withLogger(raftlogger.DiscardLogger))
}

tt := newNetworkWithConfig(nil, raftPeers...)
tt.send(pb.Message{From: 1, To: 1, Type: pb.MsgHup})
return &RawNode{raft: raftPeers[0].(*raft)}
}

for _, members := range []int{1, 3, 5, 100} {
Expand Down
Loading