@@ -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.
2226type 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.
5661type 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