Skip to content

DDL notifier does not guarantee delivery when internal SQL failed to COMMIT #59055

@lance6716

Description

@lance6716

Bug Report

defer func() {
if err == nil {
err = errors.Trace(session.Commit(ctx))
} else {
session.Rollback()
}
}()
now := time.Now()
if err = handler(ctx, session.Context, change.event); err != nil {
return errors.Trace(err)
}
if time.Since(now) > slowHandlerLogThreshold {
logutil.Logger(ctx).Warn("Slow process event",
zap.Stringer("handler", handlerID),
zap.Int64("ddlJobID", change.ddlJobID),
zap.Int64("subJobID", change.subJobID),
zap.Stringer("event", change.event),
zap.Duration("duration", time.Since(now)))
}
newFlag := change.processedByFlag | (1 << handlerID)

If handler runs without error, DDL notifier marks the in-memory structure change as processed in line 295. However the handler may still fail in line 277 when commits. The change uses the same SQL transaction so the wrong processed state is not persisted, but the memory state of change is used afterward and causes problems

if change.processedByFlag == n.handlersBitMap {
s3, err3 := n.sysSessionPool.Get()
if err3 != nil {
return errors.Trace(err3)
}
sess4Del := sess.NewSession(s3.(sessionctx.Context))
err3 = n.store.DeleteAndCommit(
ctx,
sess4Del,
change.ddlJobID,
int(change.subJobID),
)

1. Minimal reproduce step (Required)

Will add UT in fix PR

2. What did you expect to see? (Required)

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-8.5This bug affects the 8.5.x(LTS) versions.component/ddlThis issue is related to DDL of TiDB.severity/majortype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions