Skip to content

Commit

Permalink
Merge branch 'cherrypick/2.0-uservar' of https://github.com/zz-jason/…
Browse files Browse the repository at this point in the history
…tidb into cherrypick/2.0-uservar
  • Loading branch information
zz-jason committed Nov 28, 2018
2 parents 21a6efd + e8f7ee7 commit f0254b9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion parser/opcode/opcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ var opsLiteral = map[Op]string{

// Format the ExprNode into a Writer.
func (o Op) Format(w io.Writer) {
fmt.Fprintf(w, opsLiteral[o])
fmt.Fprintf(w, "%s", opsLiteral[o])
}
17 changes: 16 additions & 1 deletion parser/opcode/opcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,29 @@

package opcode

import "testing"
import (
"bytes"
"testing"
)

func TestT(t *testing.T) {
op := Plus
if op.String() != "plus" {
t.Fatalf("invalid op code")
}

if len(Ops) != len(opsLiteral) {
t.Error("inconsistent count ops and opsliteral")
}
var buf bytes.Buffer
for op := range Ops {
op.Format(&buf)
if buf.String() != opsLiteral[op] {
t.Error("format op fail", op)
}
buf.Reset()
}

// Test invalid opcode
defer func() {
recover()
Expand Down
2 changes: 2 additions & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ func (s *session) CommitTxn(ctx context.Context) error {
if err != nil {
label = metrics.LblError
}
s.sessionVars.TxnCtx.Cleanup()
metrics.TransactionCounter.WithLabelValues(label).Inc()
return errors.Trace(err)
}
Expand All @@ -418,6 +419,7 @@ func (s *session) RollbackTxn(ctx context.Context) error {
}
s.cleanRetryInfo()
s.txn.changeToInvalid()
s.sessionVars.TxnCtx.Cleanup()
s.sessionVars.SetStatusFlag(mysql.ServerStatusInTrans, false)
return errors.Trace(err)
}
Expand Down
4 changes: 4 additions & 0 deletions session/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func (st *TxnState) cleanup() {
delete(st.mutations, key)
}
if st.dirtyTableOP != nil {
empty := dirtyTableOperation{}
for i := 0; i < len(st.dirtyTableOP); i++ {
st.dirtyTableOP[i] = empty
}
st.dirtyTableOP = st.dirtyTableOP[:0]
}
}
Expand Down
9 changes: 9 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ func (tc *TransactionContext) UpdateDeltaForTable(tableID int64, delta int64, co
tc.TableDeltaMap[tableID] = item
}

// Cleanup clears up transaction info that no longer use.
func (tc *TransactionContext) Cleanup() {
//tc.InfoSchema = nil; we cannot do it now, because some operation like handleFieldList depend on this.
tc.DirtyDB = nil
tc.Binlog = nil
tc.Histroy = nil
tc.TableDeltaMap = nil
}

// ClearDelta clears the delta map.
func (tc *TransactionContext) ClearDelta() {
tc.TableDeltaMap = nil
Expand Down

0 comments on commit f0254b9

Please sign in to comment.