Skip to content

Commit 0f40692

Browse files
committed
Replace aotmic.Int64 with atomic.(Load|Store)Int64 to avoid CI issues
Signed-off-by: Eduardo J. Ortega U <5791035+ejortegau@users.noreply.github.com>
1 parent 01095bc commit 0f40692

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

go/vt/vttablet/tabletserver/txthrottler/tx_throttler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ type txThrottlerStateImpl struct {
187187
healthCheck discovery.LegacyHealthCheck
188188
topologyWatchers []TopologyWatcherInterface
189189

190-
shardMaxLag atomic.Int64
190+
shardMaxLag int64
191191
endChannel chan bool
192192
}
193193

@@ -369,7 +369,7 @@ func (ts *txThrottlerStateImpl) throttle() bool {
369369
ts.throttleMu.Lock()
370370
defer ts.throttleMu.Unlock()
371371

372-
maxLag := ts.shardMaxLag.Load()
372+
maxLag := atomic.LoadInt64(&ts.shardMaxLag)
373373

374374
return ts.throttler.Throttle(0 /* threadId */) > 0 &&
375375
maxLag > ts.config.throttlerConfig.TargetReplicationLagSec
@@ -389,7 +389,7 @@ func (ts *txThrottlerStateImpl) updateMaxShardLag() {
389389
maxLag = maxLagPerTabletType
390390
}
391391
}
392-
ts.shardMaxLag.Store(int64(maxLag))
392+
atomic.StoreInt64(&ts.shardMaxLag, int64(maxLag))
393393
case _ = <-ts.endChannel:
394394
break
395395
}

go/vt/vttablet/tabletserver/txthrottler/tx_throttler_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package txthrottler
2222
//go:generate mockgen -destination mock_topology_watcher_test.go -package txthrottler vitess.io/vitess/go/vt/vttablet/tabletserver/txthrottler TopologyWatcherInterface
2323

2424
import (
25+
"sync/atomic"
2526
"testing"
2627
"time"
2728

@@ -148,9 +149,12 @@ func TestEnabledThrottler(t *testing.T) {
148149

149150
throttlerImpl, ok := throttler.state.(*txThrottlerStateImpl)
150151
assert.True(t, ok)
152+
// Stop the go routine that keeps updating the cached shard's max lag to preventi it from changing the value in a
153+
// way that will interfere with how we manipulate that value in our tests to evaluate different cases:
154+
throttlerImpl.endChannel <- true
151155

152156
// 1 should not throttle due to return value of underlying Throttle(), despite high lag
153-
throttlerImpl.shardMaxLag.Store(20)
157+
atomic.StoreInt64(&throttlerImpl.shardMaxLag, 20)
154158
assert.False(t, throttler.Throttle(100, "some-workload"))
155159
assert.Equal(t, int64(1), throttler.requestsTotal.Counts()["some-workload"])
156160
assert.Zero(t, throttler.requestsThrottled.Counts()["some-workload"])
@@ -175,7 +179,7 @@ func TestEnabledThrottler(t *testing.T) {
175179
assert.Equal(t, int64(1), throttler.requestsThrottled.Counts()["some-workload"])
176180

177181
// 4 should not throttle despite return value of underlying Throttle() and priority = 100, due to low lag
178-
throttlerImpl.shardMaxLag.Store(1)
182+
atomic.StoreInt64(&throttlerImpl.shardMaxLag, 1)
179183
assert.False(t, throttler.Throttle(100, "some-workload"))
180184
assert.Equal(t, int64(4), throttler.requestsTotal.Counts()["some-workload"])
181185
assert.Equal(t, int64(1), throttler.requestsThrottled.Counts()["some-workload"])

0 commit comments

Comments
 (0)