Skip to content

Commit

Permalink
changefeedccl: Fix data race in lagging spans metric
Browse files Browse the repository at this point in the history
Fix a race bug in lagging spans metric.

Fixes: #110235

Release note: None
  • Loading branch information
Yevgeniy Miretskiy authored and jayshrivastava committed Sep 20, 2023
1 parent ad85452 commit 97f7793
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/ccl/changefeedccl/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,8 @@ func TestNoBackfillAfterNonTargetColumnDrop(t *testing.T) {

func TestChangefeedColumnDropsWithFamilyAndNonFamilyTargets(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

testFn := func(t *testing.T, s TestServer, f cdctest.TestFeedFactory) {
sqlDB := sqlutils.MakeSQLRunner(s.DB)

Expand Down
11 changes: 8 additions & 3 deletions pkg/ccl/changefeedccl/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,15 @@ func (s *sliMetrics) getLaggingRangesCallback() func(int64) {
// If 3 ranges catch up, last=10,i=7: X.Dec(10 - 7) = X.Dec(3)
// If 4 ranges fall behind, last=7,i=11: X.Dec(7 - 11) = X.Inc(4)
// If 1 lagging range is deleted, last=7,i=10: X.Dec(11-10) = X.Dec(1)
var last int64
last := struct {
syncutil.Mutex
v int64
}{}
return func(i int64) {
s.LaggingRanges.Dec(last - i)
last = i
last.Lock()
defer last.Unlock()
s.LaggingRanges.Dec(last.v - i)
last.v = i
}
}

Expand Down

0 comments on commit 97f7793

Please sign in to comment.