Skip to content

Commit

Permalink
simplify the useBalancer logic
Browse files Browse the repository at this point in the history
  • Loading branch information
demmer committed Jul 8, 2024
1 parent 308d7c8 commit 157b40f
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions go/vt/vtgate/tabletgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ func init() {
})
}

func useBalancer(keyspace string) bool {
if balancerEnabled {
if len(balancerKeyspaces) == 0 {
return true
}

for _, k := range balancerKeyspaces {
if keyspace == k {
return true
}
}
}

return false
}

// TabletGateway implements the Gateway interface.
// This implementation uses the new healthcheck module.
type TabletGateway struct {
Expand Down Expand Up @@ -356,23 +372,8 @@ func (gw *TabletGateway) withRetry(ctx context.Context, target *querypb.Target,
break
}

// Determine whether or not to use the balancer or the standard affinity-based shuffle
useBalancer := false
if balancerEnabled {
if len(balancerKeyspaces) != 0 {
for _, keyspace := range balancerKeyspaces {
if keyspace == target.Keyspace {
useBalancer = true
break
}
}
} else {
useBalancer = true
}
}

var th *discovery.TabletHealth
if useBalancer {
if useBalancer(target.Keyspace) {
// filter out the tablets that we've tried before (if any), then pick the best one
if len(invalidTablets) > 0 {
validTablets := make([]*discovery.TabletHealth, len(tablets))
Expand Down

0 comments on commit 157b40f

Please sign in to comment.