-
Notifications
You must be signed in to change notification settings - Fork 6k
ddl notifier: use pessimistic txn and fix updating memory state too early | tidb-test=pr/2477 #59157
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
ddl notifier: use pessimistic txn and fix updating memory state too early | tidb-test=pr/2477 #59157
Changes from all commits
412f4ef
d0839aa
d89ecf4
bef13bf
de30719
c600f88
c7a8985
e2cd37f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,15 +268,20 @@ func (n *DDLNotifier) processEventForHandler( | |
if (change.processedByFlag & (1 << handlerID)) != 0 { | ||
return nil | ||
} | ||
newFlag := change.processedByFlag | (1 << handlerID) | ||
|
||
if err = session.Begin(ctx); err != nil { | ||
if err = session.BeginPessimistic(ctx); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the target issue of using pessimistic txn ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in pessimistic txn, errors can be found earlier, such as when execute the SQL. So handler can see the error and process it. Otherwise the error is reported when COMMIT, and in current handler interface it can't be proccessed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
for update, if there is no check about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original problem is handler uses the txn to insert some duplicate rows. In optimistic txn, there's no error after execute the INSERT. Using pessimistic txn handler can see "duplicate entry" error. #58980 is related There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also checked the affected rows in bef13bf . It's revealed by old UT after switching to pessimistic txn. |
||
return errors.Trace(err) | ||
} | ||
defer func() { | ||
if err == nil { | ||
err = errors.Trace(session.Commit(ctx)) | ||
} else { | ||
if err != nil { | ||
session.Rollback() | ||
return | ||
} | ||
|
||
err = errors.Trace(session.Commit(ctx)) | ||
if err == nil { | ||
change.processedByFlag = newFlag | ||
} | ||
}() | ||
|
||
|
@@ -293,19 +298,14 @@ func (n *DDLNotifier) processEventForHandler( | |
zap.Duration("duration", time.Since(now))) | ||
} | ||
|
||
newFlag := change.processedByFlag | (1 << handlerID) | ||
if err = n.store.UpdateProcessed( | ||
return errors.Trace(n.store.UpdateProcessed( | ||
ctx, | ||
session, | ||
change.ddlJobID, | ||
change.subJobID, | ||
change.processedByFlag, | ||
newFlag, | ||
); err != nil { | ||
return errors.Trace(err) | ||
} | ||
change.processedByFlag = newFlag | ||
|
||
return nil | ||
)) | ||
} | ||
|
||
// Stop stops the background loop. | ||
|
Uh oh!
There was an error while loading. Please reload this page.