Skip to content

Commit

Permalink
Address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
MyonKeminta committed May 26, 2021
1 parent bfe9733 commit e5921e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions session/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (txn *LazyTxn) onStmtStart(currentSQLDigest string) {
return
}

info := txn.txnInfo.Clone()
info := txn.txnInfo.GetSnapInfo()
info.CurrentSQLDigest = currentSQLDigest
// Keeps at most 50 history sqls to avoid consuming too much memory.
const maxTransactionStmtHistory int = 50
Expand All @@ -285,7 +285,7 @@ func (txn *LazyTxn) onStmtStart(currentSQLDigest string) {
}

func (txn *LazyTxn) onStmtEnd() {
info := txn.txnInfo.Clone()
info := txn.txnInfo.GetSnapInfo()
info.CurrentSQLDigest = ""
txn.storeTxnInfo(info)
}
Expand Down Expand Up @@ -433,7 +433,7 @@ func keyNeedToLock(k, v []byte, flags kv.KeyFlags) bool {
// Info dump the TxnState to Datum for displaying in `TIDB_TRX`
// This function is supposed to be thread safe
func (txn *LazyTxn) Info() *txninfo.TxnInfo {
info := txn.loadTxnInfo().Clone()
info := txn.loadTxnInfo().GetSnapInfo()
if info.StartTS == 0 {
return nil
}
Expand Down
6 changes: 4 additions & 2 deletions session/txninfo/txn_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ type TxnInfo struct {
CurrentDB string
}

// Clone clones the TxnInfo. It's safe to call concurrently with the transaction.
func (info *TxnInfo) Clone() *TxnInfo {
// GetSnapInfo gets a snapshot of the TxnInfo for read. It's safe to call concurrently with the transaction.
// Note that this function doesn't do deep copy and some fields of the result may be unsafe to write. Use it at your own
// risk.
func (info *TxnInfo) GetSnapInfo() *TxnInfo {
return &TxnInfo{
StartTS: info.StartTS,
CurrentSQLDigest: info.CurrentSQLDigest,
Expand Down

0 comments on commit e5921e5

Please sign in to comment.