From 8b6db41c16fa2b204ab602c9b2f7c8bb25f58a9e Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 26 Jun 2024 02:03:05 +0200 Subject: [PATCH] rename cancel func Signed-off-by: Tim Vaillancourt --- .../tabletserver/txthrottler/tx_throttler.go | 24 +++++++++---------- .../txthrottler/tx_throttler_test.go | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/go/vt/vttablet/tabletserver/txthrottler/tx_throttler.go b/go/vt/vttablet/tabletserver/txthrottler/tx_throttler.go index 8259c3945e5..11615d52af5 100644 --- a/go/vt/vttablet/tabletserver/txthrottler/tx_throttler.go +++ b/go/vt/vttablet/tabletserver/txthrottler/tx_throttler.go @@ -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 @@ -241,7 +241,7 @@ 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() @@ -249,7 +249,7 @@ func (t *txThrottler) 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() @@ -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) { @@ -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) @@ -386,7 +387,6 @@ func (ts *txThrottlerStateImpl) makePrimary() { func (ts *txThrottlerStateImpl) makeNonPrimary() { ts.closeHealthCheck() - ts.maxLag = 0 } func (ts *txThrottlerStateImpl) throttle() bool { diff --git a/go/vt/vttablet/tabletserver/txthrottler/tx_throttler_test.go b/go/vt/vttablet/tabletserver/txthrottler/tx_throttler_test.go index 66a32b7d832..da761855c38 100644 --- a/go/vt/vttablet/tabletserver/txthrottler/tx_throttler_test.go +++ b/go/vt/vttablet/tabletserver/txthrottler/tx_throttler_test.go @@ -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)