Skip to content

Commit e62c88f

Browse files
committed
Pass PickOpts by value
Signed-off-by: Mohamed Hamza <mhamza15@github.com>
1 parent 2620b76 commit e62c88f

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎go/vt/vtgate/balancer/balancer.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ converge on the desired balanced query load.
9090
type TabletBalancer interface {
9191
// Pick is the main entry point to the balancer. Returns the best tablet out of the list
9292
// for a given query to maintain the desired balanced allocation over multiple executions.
93-
Pick(target *querypb.Target, tablets []*discovery.TabletHealth, opts *PickOpts) *discovery.TabletHealth
93+
Pick(target *querypb.Target, tablets []*discovery.TabletHealth, opts PickOpts) *discovery.TabletHealth
9494

9595
// DebugHandler provides a summary of tablet balancer state
9696
DebugHandler(w http.ResponseWriter, r *http.Request)
@@ -176,7 +176,7 @@ func (b *tabletBalancer) DebugHandler(w http.ResponseWriter, _ *http.Request) {
176176
// Given the total allocation for the set of tablets, choose the best target
177177
// by a weighted random sample so that over time the system will achieve the
178178
// desired balanced allocation.
179-
func (b *tabletBalancer) Pick(target *querypb.Target, tablets []*discovery.TabletHealth, _ *PickOpts) *discovery.TabletHealth {
179+
func (b *tabletBalancer) Pick(target *querypb.Target, tablets []*discovery.TabletHealth, _ PickOpts) *discovery.TabletHealth {
180180
numTablets := len(tablets)
181181
if numTablets == 0 {
182182
return nil

‎go/vt/vtgate/balancer/balancer_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func TestBalancedPick(t *testing.T) {
298298
b := NewTabletBalancer(localCell, vtGateCells).(*tabletBalancer)
299299

300300
for i := 0; i < N/len(vtGateCells); i++ {
301-
th := b.Pick(target, tablets, nil)
301+
th := b.Pick(target, tablets, PickOpts{})
302302
if i == 0 {
303303
t.Logf("Target Flows %v, Balancer: %s\n", expectedPerCell, b.print())
304304
}
@@ -336,7 +336,7 @@ func TestTopologyChanged(t *testing.T) {
336336
tablets = tablets[0:2]
337337

338338
for i := 0; i < N; i++ {
339-
th := b.Pick(target, tablets, nil)
339+
th := b.Pick(target, tablets, PickOpts{})
340340
allocation, totalAllocation := b.getAllocation(target, tablets)
341341

342342
assert.Equalf(t, ALLOCATION/2, totalAllocation, "totalAllocation mismatch %s", b.print())
@@ -346,7 +346,7 @@ func TestTopologyChanged(t *testing.T) {
346346

347347
// Run again with the full topology. Now traffic should go to cell b
348348
for i := 0; i < N; i++ {
349-
th := b.Pick(target, allTablets, nil)
349+
th := b.Pick(target, allTablets, PickOpts{})
350350

351351
allocation, totalAllocation := b.getAllocation(target, allTablets)
352352

@@ -359,7 +359,7 @@ func TestTopologyChanged(t *testing.T) {
359359
newTablet := createTestTablet("b")
360360
allTablets[2] = newTablet
361361
for i := 0; i < N; i++ {
362-
th := b.Pick(target, allTablets, nil)
362+
th := b.Pick(target, allTablets, PickOpts{})
363363

364364
allocation, totalAllocation := b.getAllocation(target, allTablets)
365365

‎go/vt/vtgate/balancer/session.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ func NewSessionBalancer(ctx context.Context, localCell string, topoServer srvtop
9393
//
9494
// For a given session, it will return the same tablet for its duration, with preference to tablets
9595
// in the local cell.
96-
func (b *SessionBalancer) Pick(target *querypb.Target, _ []*discovery.TabletHealth, opts *PickOpts) *discovery.TabletHealth {
97-
if opts == nil {
96+
func (b *SessionBalancer) Pick(target *querypb.Target, _ []*discovery.TabletHealth, opts PickOpts) *discovery.TabletHealth {
97+
if opts.SessionUUID == "" {
9898
return nil
9999
}
100100

‎go/vt/vtgate/balancer/session_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ func TestPickNoOpts(t *testing.T) {
508508
// Give a moment for the worker to process the tablets
509509
time.Sleep(10 * time.Millisecond)
510510

511-
// Test with nil opts
512-
result := b.Pick(target, nil, nil)
511+
// Test with empty opts
512+
result := b.Pick(target, nil, PickOpts{})
513513
require.Nil(t, result)
514514
}
515515

@@ -681,6 +681,6 @@ func TestTabletTypesToWatch(t *testing.T) {
681681
}
682682
}
683683

684-
func buildOpts(uuid string) *PickOpts {
685-
return &PickOpts{SessionUUID: uuid}
684+
func buildOpts(uuid string) PickOpts {
685+
return PickOpts{SessionUUID: uuid}
686686
}

‎go/vt/vtgate/tabletgateway.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func (gw *TabletGateway) getBalancerTablet(target *querypb.Target, tablets []*di
436436
})
437437
}
438438

439-
opts := &balancer.PickOpts{SessionUUID: opts.Options.SessionUUID, InvalidTablets: invalidTablets}
439+
opts := balancer.PickOpts{SessionUUID: opts.Options.SessionUUID, InvalidTablets: invalidTablets}
440440
tablet = gw.balancer.Pick(target, tablets, opts)
441441
}
442442

0 commit comments

Comments
 (0)