-
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
*: avoid pass session ID by context & fix no schemaChecker error log #24696
Changes from all commits
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 | ||
---|---|---|---|---|
|
@@ -88,6 +88,7 @@ type KVTxn struct { | |||
causalConsistency bool | ||||
scope string | ||||
kvFilter KVFilter | ||||
sessionID uint64 | ||||
} | ||||
|
||||
func extractStartTs(store *KVStore, options kv.TransactionOption) (uint64, error) { | ||||
|
@@ -285,6 +286,11 @@ func (txn *KVTxn) SetKVFilter(filter KVFilter) { | |||
txn.kvFilter = filter | ||||
} | ||||
|
||||
// SetSessionID sets the session ID for this transaction. | ||||
func (txn *KVTxn) SetSessionID(id uint64) { | ||||
txn.sessionID = id | ||||
} | ||||
|
||||
// IsPessimistic returns true if it is pessimistic. | ||||
func (txn *KVTxn) IsPessimistic() bool { | ||||
return txn.isPessimistic | ||||
|
@@ -325,18 +331,11 @@ func (txn *KVTxn) Commit(ctx context.Context) error { | |||
start := time.Now() | ||||
defer func() { metrics.TxnCmdHistogramWithCommit.Observe(time.Since(start).Seconds()) }() | ||||
|
||||
// sessionID is used for log. | ||||
var sessionID uint64 | ||||
val := ctx.Value(util.SessionID) | ||||
if val != nil { | ||||
sessionID = val.(uint64) | ||||
} | ||||
|
||||
var err error | ||||
// If the txn use pessimistic lock, committer is initialized. | ||||
committer := txn.committer | ||||
if committer == nil { | ||||
committer, err = newTwoPhaseCommitter(txn, sessionID) | ||||
committer, err = newTwoPhaseCommitter(txn, txn.sessionID) | ||||
if err != nil { | ||||
return errors.Trace(err) | ||||
} | ||||
|
@@ -369,9 +368,7 @@ func (txn *KVTxn) Commit(ctx context.Context) error { | |||
// pessimistic transaction should also bypass latch. | ||||
if txn.store.txnLatches == nil || txn.IsPessimistic() { | ||||
err = committer.execute(ctx) | ||||
if val == nil || sessionID > 0 { | ||||
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. Will this make the following logic executed unexpected for the inner session statements whose session id is 0? 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 internal queries, 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. Now I've change it to: The original author means to call 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. maybe it's hard to distinguish external from internal queries form InRestrictedSQL also can call doCommit Line 521 in c3f9b08
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. If we take a session from the session pool to execute the SQL, |
||||
txn.onCommitted(err) | ||||
} | ||||
txn.onCommitted(err) | ||||
logutil.Logger(ctx).Debug("[kv] txnLatches disabled, 2pc directly", zap.Error(err)) | ||||
return errors.Trace(err) | ||||
} | ||||
|
@@ -390,9 +387,7 @@ func (txn *KVTxn) Commit(ctx context.Context) error { | |||
return &tikverr.ErrWriteConflictInLatch{StartTS: txn.startTS} | ||||
} | ||||
err = committer.execute(ctx) | ||||
if val == nil || sessionID > 0 { | ||||
txn.onCommitted(err) | ||||
} | ||||
txn.onCommitted(err) | ||||
if err == nil { | ||||
lock.SetCommitTS(committer.commitTS) | ||||
} | ||||
|
@@ -548,14 +543,7 @@ func (txn *KVTxn) LockKeys(ctx context.Context, lockCtx *tikv.LockCtx, keysInput | |||
keys = deduplicateKeys(keys) | ||||
if txn.IsPessimistic() && lockCtx.ForUpdateTS > 0 { | ||||
if txn.committer == nil { | ||||
// sessionID is used for log. | ||||
var sessionID uint64 | ||||
var err error | ||||
val := ctx.Value(util.SessionID) | ||||
if val != nil { | ||||
sessionID = val.(uint64) | ||||
} | ||||
txn.committer, err = newTwoPhaseCommitter(txn, sessionID) | ||||
txn.committer, err = newTwoPhaseCommitter(txn, txn.sessionID) | ||||
if err != nil { | ||||
return 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.
it seems some other test case
tidb/store/tikv/region_request.go
Line 413 in 18cbfaa
@MyonKeminta PTAL
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.
I have updated the test, you can see the
_test.go
file changes in this PRThere 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.
it seems the previous
tidb/store/tikv/region_request.go
Line 465 in 18cbfaa
will be used in some test case that out of tidb repo
https://github.com/pingcap/automated-tests/blob/cc44a56fd59cfdb71eaf37210e0861ba7acdc925/ticases/transaction/asynccommit/linearizability.go#L445
I'm not sure whether it works 😞
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.
Seems we may change the session id related logic too or abstract a
isInnerExecution
accordingly.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.
Yes that's a problem. Some failpoints that's used by tests outside the repo checks the session id and works only when session id != 0. These kind of usages also occurs in 2pc.go, prewrite.go, etc.