Skip to content

Commit 7941334

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

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-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: 31 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,10 @@ 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.
4145
//
42-
// Requires replica.raftMu and replica.mu to be held.
43-
SetReplicasLocked(ctx context.Context, replicas roachpb.ReplicaSet) error
46+
// Requires replica.raftMu to be held.
47+
SetReplicasRaftMuLocked(ctx context.Context, replicas ReplicaSet) error
4448
// SetLeaseholderRaftMuLocked sets the leaseholder of the range.
4549
//
4650
// Requires raftMu to be held.
@@ -54,3 +58,27 @@ type RangeController interface {
5458
// TODO(pav-kv): This struct is a placeholder for the interface or struct
5559
// containing raft entries. Replace this as part of #128019.
5660
type RaftEvent struct{}
61+
62+
// NoReplicaID is a special value of roachpb.ReplicaID, which can never be a
63+
// valid ID.
64+
const NoReplicaID roachpb.ReplicaID = 0
65+
66+
type ReplicaSet map[roachpb.ReplicaID]roachpb.ReplicaDescriptor
67+
68+
// SafeFormat implements the redact.SafeFormatter interface.
69+
func (rs ReplicaSet) SafeFormat(w redact.SafePrinter, _ rune) {
70+
w.Printf("[")
71+
i := 0
72+
for _, desc := range rs {
73+
if i > 0 {
74+
w.Printf(",")
75+
}
76+
w.Printf("%v", desc)
77+
i++
78+
}
79+
w.Printf("]")
80+
}
81+
82+
func (rs ReplicaSet) String() string {
83+
return redact.StringWithoutMarkers(rs)
84+
}

0 commit comments

Comments
 (0)