Skip to content

Commit

Permalink
fix data race in gc manager
Browse files Browse the repository at this point in the history
  • Loading branch information
sdojjy committed Mar 25, 2024
1 parent 99b3eb4 commit cc1804e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/txnutil/gc/gc_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type gcManager struct {

lastUpdatedTime time.Time
lastSucceededTime time.Time
lastSafePointTs uint64
lastSafePointTs atomic.Uint64
isTiCDCBlockGC atomic.Bool
}

Expand Down Expand Up @@ -101,7 +101,7 @@ func (m *gcManager) TryUpdateGCSafePoint(
// means that the service gc safe point set by TiCDC is the min service
// gc safe point
m.isTiCDCBlockGC.Store(actual == checkpointTs)
m.lastSafePointTs = actual
m.lastSafePointTs.Store(actual)
m.lastSucceededTime = time.Now()
minServiceGCSafePointGauge.Set(float64(oracle.ExtractPhysical(actual)))
cdcGCSafePointGauge.Set(float64(oracle.ExtractPhysical(checkpointTs)))
Expand All @@ -126,11 +126,11 @@ func (m *gcManager) CheckStaleCheckpointTs(
} else {
// if `isTiCDCBlockGC` is false, it means there is another service gc
// point less than the min checkpoint ts.
if gcSafepointUpperBound < m.lastSafePointTs {
if gcSafepointUpperBound < m.lastSafePointTs.Load() {
return cerror.ErrSnapshotLostByGC.
GenWithStackByArgs(
checkpointTs,
m.lastSafePointTs,
m.lastSafePointTs.Load(),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/txnutil/gc/gc_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestCheckStaleCheckpointTs(t *testing.T) {
err := gcManager.CheckStaleCheckpointTs(ctx, cfID, oracle.GoTimeToTS(time.Now()))
require.Nil(t, err)

gcManager.lastSafePointTs = 20
gcManager.lastSafePointTs.Store(20)
err = gcManager.CheckStaleCheckpointTs(ctx, cfID, 10)
require.True(t, cerror.ErrSnapshotLostByGC.Equal(errors.Cause(err)))
require.True(t, cerror.IsChangefeedGCFastFailError(err))
Expand Down

0 comments on commit cc1804e

Please sign in to comment.