Skip to content

Commit

Permalink
Merge pull request #129372 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-24.1-129368

release-24.1: kvclient: improve logging in OptimizeReplicaOrder
  • Loading branch information
arulajmani authored Sep 27, 2024
2 parents cb89060 + 914d0ca commit 08418a5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/kv/kvclient/kvcoord/dist_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,7 @@ func (ds *DistSender) sendToReplicas(
// First order by latency, then move the leaseholder to the front of the
// list, if it is known.
if !ds.dontReorderReplicas {
replicas.OptimizeReplicaOrder(ds.st, ds.nodeIDGetter(), ds.healthFunc, ds.latencyFunc, ds.locality)
replicas.OptimizeReplicaOrder(ctx, ds.st, ds.nodeIDGetter(), ds.healthFunc, ds.latencyFunc, ds.locality)
}

idx := -1
Expand All @@ -2550,7 +2550,7 @@ func (ds *DistSender) sendToReplicas(

case kvpb.RoutingPolicy_NEAREST:
// Order by latency.
replicas.OptimizeReplicaOrder(ds.st, ds.nodeIDGetter(), ds.healthFunc, ds.latencyFunc, ds.locality)
replicas.OptimizeReplicaOrder(ctx, 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:
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvclient/kvcoord/dist_sender_rangefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ func newTransportForRange(
if err != nil {
return nil, err
}
replicas.OptimizeReplicaOrder(ds.st, ds.nodeIDGetter(), ds.healthFunc, ds.latencyFunc, ds.locality)
replicas.OptimizeReplicaOrder(ctx, ds.st, ds.nodeIDGetter(), ds.healthFunc, ds.latencyFunc, ds.locality)
opts := SendOptions{class: defRangefeedConnClass}
return ds.transportFactory(opts, replicas)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/kv/kvclient/kvcoord/replica_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ type HealthFunc func(roachpb.NodeID) bool
// leaseholder is known by the caller, the caller will move it to the
// front if appropriate.
func (rs ReplicaSlice) OptimizeReplicaOrder(
ctx context.Context,
st *cluster.Settings,
nodeID roachpb.NodeID,
healthFn HealthFunc,
Expand All @@ -227,6 +228,7 @@ func (rs ReplicaSlice) OptimizeReplicaOrder(
// If we don't know which node we're on or its locality, and we don't have
// latency information to other nodes, send the RPCs randomly.
if nodeID == 0 && latencyFn == nil && len(locality.Tiers) == 0 {
log.VEvent(ctx, 2, "randomly shuffling replicas to route to")
shuffle.Shuffle(rs)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvclient/kvcoord/replica_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func TestReplicaSliceOptimizeReplicaOrder(t *testing.T) {
}
// Randomize the input order, as it's not supposed to matter.
shuffle.Shuffle(test.slice)
test.slice.OptimizeReplicaOrder(st, test.nodeID, healthFn, latencyFn, test.locality)
test.slice.OptimizeReplicaOrder(context.Background(), st, test.nodeID, healthFn, latencyFn, test.locality)
var sortedNodes []roachpb.NodeID
sortedNodes = append(sortedNodes, test.slice[0].NodeID)
for i := 1; i < len(test.slice); i++ {
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/physicalplan/replicaoracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (o *closestOracle) ChoosePreferredReplica(
if err != nil {
return roachpb.ReplicaDescriptor{}, false, err
}
replicas.OptimizeReplicaOrder(o.st, o.nodeID, o.healthFunc, o.latencyFunc, o.locality)
replicas.OptimizeReplicaOrder(ctx, o.st, o.nodeID, o.healthFunc, o.latencyFunc, o.locality)
repl := replicas[0].ReplicaDescriptor
// There are no "misplanned" ranges if we know the leaseholder, and we're
// deliberately choosing non-leaseholder.
Expand Down Expand Up @@ -278,7 +278,7 @@ func (o *binPackingOracle) ChoosePreferredReplica(
if err != nil {
return roachpb.ReplicaDescriptor{}, false, err
}
replicas.OptimizeReplicaOrder(o.st, o.nodeID, o.healthFunc, o.latencyFunc, o.locality)
replicas.OptimizeReplicaOrder(ctx, o.st, o.nodeID, o.healthFunc, o.latencyFunc, o.locality)

// Look for a replica that has been assigned some ranges, but it's not yet full.
minLoad := int(math.MaxInt32)
Expand Down

0 comments on commit 08418a5

Please sign in to comment.