Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvclient: improve logging in OptimizeReplicaOrder #129368

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2551,7 +2551,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 @@ -2571,7 +2571,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 @@ -646,7 +646,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), nil
}
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 @@ -220,6 +220,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 @@ -229,6 +230,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 @@ -327,7 +327,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 @@ -211,7 +211,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 @@ -279,7 +279,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
Loading