Skip to content

Commit 1ddc364

Browse files
committed
rac2: specify lock ordering, and add ReplicaSet
Informs #128308 Epic: CRDB-37515 Release note: None
1 parent 19380bb commit 1ddc364

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

pkg/kv/kvserver/kvflowcontrol/rac2/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ go_library(
1717
"//pkg/util/buildutil",
1818
"//pkg/util/log",
1919
"//pkg/util/syncutil",
20+
"@com_github_cockroachdb_redact//:redact",
2021
],
2122
)
2223

pkg/kv/kvserver/kvflowcontrol/rac2/range_controller.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import (
1515

1616
"github.com/cockroachdb/cockroach/pkg/roachpb"
1717
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
18+
"github.com/cockroachdb/redact"
1819
)
1920

2021
// RangeController provides flow control for replication traffic in KV, for a
2122
// range at the leader.
23+
//
24+
// None of the methods are called with Replica.mu held. The caller should
25+
// typically order its mutexes before Replica.mu.
2226
type RangeController interface {
2327
// WaitForEval seeks admission to evaluate a request at the given priority.
2428
// This blocks until there are positive tokens available for the request to
@@ -37,10 +41,11 @@ type RangeController interface {
3741
//
3842
// Requires replica.raftMu to be held.
3943
HandleSchedulerEventRaftMuLocked(ctx context.Context) error
40-
// SetReplicasLocked sets the replicas of the range.
44+
// SetReplicasRaftMuLocked sets the replicas of the range. The caller will
45+
// never mutate replicas, and neither should the callee.
4146
//
42-
// Requires replica.raftMu and replica.mu to be held.
43-
SetReplicasLocked(ctx context.Context, replicas roachpb.ReplicaSet) error
47+
// Requires replica.raftMu to be held.
48+
SetReplicasRaftMuLocked(ctx context.Context, replicas ReplicaSet) error
4449
// SetLeaseholderRaftMuLocked sets the leaseholder of the range.
4550
//
4651
// Requires raftMu to be held.
@@ -54,3 +59,29 @@ type RangeController interface {
5459
// TODO(pav-kv): This struct is a placeholder for the interface or struct
5560
// containing raft entries. Replace this as part of #128019.
5661
type RaftEvent struct{}
62+
63+
// NoReplicaID is a special value of roachpb.ReplicaID, which can never be a
64+
// valid ID.
65+
const NoReplicaID roachpb.ReplicaID = 0
66+
67+
// ReplicaSet is a map, unlike roachpb.ReplicaSet, for convenient lookup by
68+
// ReplicaID.
69+
type ReplicaSet map[roachpb.ReplicaID]roachpb.ReplicaDescriptor
70+
71+
// SafeFormat implements the redact.SafeFormatter interface.
72+
func (rs ReplicaSet) SafeFormat(w redact.SafePrinter, _ rune) {
73+
w.Printf("[")
74+
i := 0
75+
for _, desc := range rs {
76+
if i > 0 {
77+
w.Printf(",")
78+
}
79+
w.Printf("%v", desc)
80+
i++
81+
}
82+
w.Printf("]")
83+
}
84+
85+
func (rs ReplicaSet) String() string {
86+
return redact.StringWithoutMarkers(rs)
87+
}

0 commit comments

Comments
 (0)