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

processor,sink(cdc): let sink report resolved ts and do not skip buffer sink flush (#3540) #3562

Merged
Merged
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
33 changes: 28 additions & 5 deletions cdc/sink/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ func (m *Manager) flushBackendSink(ctx context.Context) (model.Ts, error) {
// NOTICE: Because all table sinks will try to flush backend sink,
// which will cause a lot of lock contention and blocking in high concurrency cases.
// So here we use flushing as a lightweight lock to improve the lock competition problem.
if !atomic.CompareAndSwapInt64(&m.flushing, 0, 1) {
return m.getCheckpointTs(), nil
}
//
// Do not skip flushing for resolving #3503.
// TODO uncomment the following return.
// if !atomic.CompareAndSwapInt64(&m.flushing, 0, 1) {
// return m.getCheckpointTs(), nil
// }
m.flushMu.Lock()
defer func() {
m.flushMu.Unlock()
Expand Down Expand Up @@ -174,12 +177,27 @@ func (t *tableSink) EmitDDLEvent(ctx context.Context, ddl *model.DDLEvent) error
}

func (t *tableSink) FlushRowChangedEvents(ctx context.Context, resolvedTs uint64) (uint64, error) {
// Log abnormal checkpoint that is large than resolved ts.
logAbnormalCheckpoint := func(ckpt uint64) {
if ckpt > resolvedTs {
log.L().WithOptions(zap.AddCallerSkip(1)).
Warn("checkpoint ts > resolved ts, flushed more than emitted",
zap.Int64("tableID", t.tableID),
zap.Uint64("resolvedTs", resolvedTs),
zap.Uint64("checkpointTs", ckpt))
}
}
i := sort.Search(len(t.buffer), func(i int) bool {
return t.buffer[i].CommitTs > resolvedTs
})
if i == 0 {
atomic.StoreUint64(&t.emittedTs, resolvedTs)
return t.manager.flushBackendSink(ctx)
ckpt, err := t.manager.flushBackendSink(ctx)
if err != nil {
return ckpt, err
}
logAbnormalCheckpoint(ckpt)
return ckpt, err
}
resolvedRows := t.buffer[:i]
t.buffer = append(make([]*model.RowChangedEvent, 0, len(t.buffer[i:])), t.buffer[i:]...)
Expand All @@ -189,7 +207,12 @@ func (t *tableSink) FlushRowChangedEvents(ctx context.Context, resolvedTs uint64
return t.manager.getCheckpointTs(), errors.Trace(err)
}
atomic.StoreUint64(&t.emittedTs, resolvedTs)
return t.manager.flushBackendSink(ctx)
ckpt, err := t.manager.flushBackendSink(ctx)
if err != nil {
return ckpt, err
}
logAbnormalCheckpoint(ckpt)
return ckpt, err
}

func (t *tableSink) getEmittedTs() uint64 {
Expand Down