Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gc(ticdc): fix data race in gc manager #10846

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading