Skip to content

Commit

Permalink
rename cancel func
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Jun 26, 2024
1 parent 188aa0d commit 8b6db41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions go/vt/vttablet/tabletserver/txthrottler/tx_throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ type txThrottlerStateImpl struct {
throttleMu sync.Mutex
throttler ThrottlerInterface

cellsFromTopo bool
healthCheck discovery.HealthCheck
healthCheckCells []string
healthCheckChan chan *discovery.TabletHealth
lagChecksCancelFunc context.CancelFunc
maxLag int64
wg sync.WaitGroup
cellsFromTopo bool
healthCheck discovery.HealthCheck
healthCheckCancel context.CancelFunc
healthCheckCells []string
healthCheckChan chan *discovery.TabletHealth
maxLag int64
wg sync.WaitGroup

// tabletTypes stores the tablet types for throttling
tabletTypes map[topodatapb.TabletType]bool
Expand Down Expand Up @@ -241,15 +241,15 @@ func (t *txThrottler) Close() {
}

// MakePrimary performs a transition to a primary tablet. This will enable healthchecks to
// enable live replication lag state.
// watch the replication lag state of other tablets.
func (t *txThrottler) MakePrimary() {
if t.state != nil {
t.state.makePrimary()
}
}

// MakePrimary performs a transition to a non-primary tablet. This disables healthchecks
// (for replication state) if they exist.
// for replication lag state if we were primary.
func (t *txThrottler) MakeNonPrimary() {
if t.state != nil {
t.state.makeNonPrimary()
Expand Down Expand Up @@ -333,10 +333,11 @@ func (ts *txThrottlerStateImpl) closeHealthCheck() {
if ts.healthCheck == nil {
return
}
ts.lagChecksCancelFunc()
ts.healthCheckCancel()
ts.wg.Wait()
ts.healthCheck.Close()
ts.healthCheck = nil
ts.maxLag = 0
}

func (ts *txThrottlerStateImpl) updateHealthCheckCells(ctx context.Context) {
Expand Down Expand Up @@ -375,7 +376,7 @@ func (ts *txThrottlerStateImpl) healthCheckProcessor(ctx context.Context) {
func (ts *txThrottlerStateImpl) makePrimary() {
ts.initHealthCheck()
var ctx context.Context
ctx, ts.lagChecksCancelFunc = context.WithCancel(context.Background())
ctx, ts.healthCheckCancel = context.WithCancel(context.Background())

ts.wg.Add(1)
go ts.healthCheckProcessor(ctx)
Expand All @@ -386,7 +387,6 @@ func (ts *txThrottlerStateImpl) makePrimary() {

func (ts *txThrottlerStateImpl) makeNonPrimary() {
ts.closeHealthCheck()
ts.maxLag = 0
}

func (ts *txThrottlerStateImpl) throttle() bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestEnabledThrottler(t *testing.T) {

// Stop the lag/healthcheck go routines that keeps updating the cached shard's max lag to prevent it from changing the value in a
// way that will interfere with how we manipulate that value in our tests to evaluate different cases:
throttlerStateImpl.lagChecksCancelFunc()
throttlerStateImpl.healthCheckCancel()

// 1 should not throttle due to return value of underlying Throttle(), despite high lag
atomic.StoreInt64(&throttlerStateImpl.maxLag, 20)
Expand Down

0 comments on commit 8b6db41

Please sign in to comment.