Skip to content

Commit

Permalink
Merge pull request cockroachdb#129270 from cockroachdb/blathers/backp…
Browse files Browse the repository at this point in the history
…ort-release-24.2-129264

release-24.2: kvcoord: log replica order on nearest routing policy
  • Loading branch information
kvoli authored Aug 20, 2024
2 parents 9b56fdc + d281763 commit 8863a71
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/kv/kvclient/kvcoord/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ go_library(
"//pkg/util/future",
"//pkg/util/grpcutil",
"//pkg/util/hlc",
"//pkg/util/humanizeutil",
"//pkg/util/iterutil",
"//pkg/util/limit",
"//pkg/util/log",
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvclient/kvcoord/dist_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -2571,8 +2571,8 @@ func (ds *DistSender) sendToReplicas(

case kvpb.RoutingPolicy_NEAREST:
// Order by latency.
log.VEvent(ctx, 2, "routing to nearest replica; leaseholder not required")
replicas.OptimizeReplicaOrder(ds.st, ds.nodeIDGetter(), ds.healthFunc, ds.latencyFunc, ds.locality)
log.VEventf(ctx, 2, "routing to nearest replica; leaseholder not required order=%v", replicas)

default:
log.Fatalf(ctx, "unknown routing policy: %s", ba.RoutingPolicy)
Expand Down
21 changes: 21 additions & 0 deletions pkg/kv/kvclient/kvcoord/replica_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
"github.com/cockroachdb/cockroach/pkg/kv/kvclient"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/util/humanizeutil"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/shuffle"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/redact"
)

// ReplicaInfo extends the Replica structure with the associated node
Expand All @@ -41,6 +43,25 @@ type ReplicaInfo struct {
// A ReplicaSlice is a slice of ReplicaInfo.
type ReplicaSlice []ReplicaInfo

func (rs ReplicaSlice) String() string {
return redact.StringWithoutMarkers(rs)
}

// SafeFormat implements the redact.SafeFormatter interface.
func (rs ReplicaSlice) SafeFormat(w redact.SafePrinter, _ rune) {
var buf redact.StringBuilder
buf.Print("[")
for i, r := range rs {
if i > 0 {
buf.Print(",")
}
buf.Printf("%v(health=%v match=%d latency=%v)",
r, r.healthy, r.tierMatchLength, humanizeutil.Duration(r.latency))
}
buf.Print("]")
w.Print(buf)
}

// ReplicaSliceFilter controls which kinds of replicas are to be included in
// the slice for routing BatchRequests to.
type ReplicaSliceFilter int
Expand Down

0 comments on commit 8863a71

Please sign in to comment.