-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
txn: fix the ttlmanager and cleanup logic for 1pc and async commit #23342
Changes from 4 commits
1a28404
c03ff28
0c2c984
974f58e
e239169
76838b2
bfc116e
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 |
---|---|---|
|
@@ -899,15 +899,20 @@ func (c *twoPhaseCommitter) cleanup(ctx context.Context) { | |
}) | ||
|
||
cleanupKeysCtx := context.WithValue(context.Background(), TxnStartKey, ctx.Value(TxnStartKey)) | ||
err := c.cleanupMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations) | ||
var err error | ||
if c.isPessimistic && c.isOnePC() { | ||
err = c.pessimisticRollbackMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations) | ||
} else { | ||
err = c.cleanupMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations) | ||
} | ||
if err != nil { | ||
metrics.SecondaryLockCleanupFailureCounterRollback.Inc() | ||
logutil.Logger(ctx).Info("2PC cleanup failed", | ||
zap.Error(err), | ||
zap.Uint64("txnStartTS", c.startTS)) | ||
logutil.Logger(ctx).Info("2PC cleanup failed", zap.Error(err), zap.Uint64("txnStartTS", c.startTS), | ||
zap.Bool("isPessimistic", c.isPessimistic), zap.Bool("isOnePC", c.isOnePC())) | ||
} else { | ||
logutil.Logger(ctx).Info("2PC clean up done", | ||
zap.Uint64("txnStartTS", c.startTS)) | ||
zap.Uint64("txnStartTS", c.startTS), zap.Bool("isPessimistic", c.isPessimistic), | ||
zap.Bool("isOnePC", c.isOnePC())) | ||
} | ||
c.cleanWg.Done() | ||
}() | ||
|
@@ -920,6 +925,9 @@ func (c *twoPhaseCommitter) execute(ctx context.Context) (err error) { | |
if c.isOnePC() { | ||
// The error means the 1PC transaction failed. | ||
if err != nil { | ||
if c.getUndeterminedErr() == nil { | ||
c.cleanup(ctx) | ||
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. Should we just use something like 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 think there won't be too much difference, but maybe we can skip this for optimistic 1pc transactions. @sticnarf How do you think? 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. We can always use pessimistic rollback because an optimistic one pc won't leave any waste. 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. How about changing cleanupKeysCtx := context.WithValue(context.Background(), TxnStartKey, ctx.Value(TxnStartKey))
var err error
if c.isPessimistic && c.isOnePC() {
err = c.pessimisticRollbackMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations)
} else {
err = c.cleanupMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations)
}
if 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. @youjiali1995 We needn't do cleanup for optimistic 1PC, so I suggest this: if !c.isOnePC() {
err = c.cleanupMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations)
} else if c.isPessimistic {
err = c.pessimisticRollbackMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations)
} 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. My mistake. |
||
} | ||
metrics.OnePCTxnCounterError.Inc() | ||
} else { | ||
metrics.OnePCTxnCounterOk.Inc() | ||
|
@@ -1376,6 +1384,12 @@ func (c *twoPhaseCommitter) getCommitTS(ctx context.Context, commitDetail *execd | |
// this transaction using the related schema changes. | ||
func (c *twoPhaseCommitter) checkSchemaValid(ctx context.Context, checkTS uint64, startInfoSchema SchemaVer, | ||
tryAmend bool) (*RelatedSchemaChange, bool, error) { | ||
failpoint.Inject("failCheckSchemaValid", func() { | ||
logutil.Logger(ctx).Info("[failpoint] injected fail schema check", | ||
zap.Uint64("txnStartTS", c.startTS)) | ||
err := errors.Errorf("mock check schema valid failure") | ||
failpoint.Return(nil, false, err) | ||
}) | ||
checker, ok := c.txn.us.GetOption(kv.SchemaChecker).(schemaLeaseChecker) | ||
if !ok { | ||
if c.sessionID > 0 { | ||
|
@@ -1411,7 +1425,7 @@ func (c *twoPhaseCommitter) calculateMaxCommitTS(ctx context.Context) error { | |
currentTS := oracle.EncodeTSO(int64(time.Since(c.txn.startTime)/time.Millisecond)) + c.startTS | ||
_, _, err := c.checkSchemaValid(ctx, currentTS, c.txn.txnInfoSchema, true) | ||
if err != nil { | ||
logutil.Logger(ctx).Error("Schema changed for async commit txn", | ||
logutil.Logger(ctx).Info("Schema changed for async commit txn", | ||
zap.Error(err), | ||
zap.Uint64("startTS", c.startTS)) | ||
return errors.Trace(err) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about skipping cleanup for optimistic one pc? https://github.com/pingcap/tidb/pull/23342/files#r596528085