Skip to content

Commit

Permalink
*: clear delta info when roll back transaction (pingcap#5390)
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx authored and Haibin Xie committed Dec 13, 2017
1 parent a05e014 commit 34b8abb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (e *SimpleExec) executeRollback(s *ast.RollbackStmt) error {
log.Infof("[%d] execute rollback statement", sessVars.ConnectionID)
sessVars.SetStatusFlag(mysql.ServerStatusInTrans, false)
if e.ctx.Txn().Valid() {
e.ctx.GetSessionVars().TxnCtx.ClearDelta()
return e.ctx.Txn().Rollback()
}
return nil
Expand Down
5 changes: 5 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func (tc *TransactionContext) UpdateDeltaForTable(tableID int64, delta int64, co
tc.TableDeltaMap[tableID] = item
}

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

// SessionVars is to handle user-defined or global variables in the current session.
type SessionVars struct {
// UsersLock is a lock for user defined variables.
Expand Down
23 changes: 23 additions & 0 deletions statistics/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ func (s *testStatsUpdateSuite) TestSingleSessionInsert(c *C) {
rs.Check(testkit.Rows("40", "70"))
}

func (s *testStatsUpdateSuite) TestRollback(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("use test")
testKit.MustExec("create table t (a int, b int)")
testKit.MustExec("begin")
testKit.MustExec("insert into t values (1,2)")
testKit.MustExec("rollback")

is := s.do.InfoSchema()
tbl, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t"))
c.Assert(err, IsNil)
tableInfo := tbl.Meta()
h := s.do.StatsHandle()
h.HandleDDLEvent(<-h.DDLEventCh())
h.DumpStatsDeltaToKV()
h.Update(is)

stats := h.GetTableStats(tableInfo.ID)
c.Assert(stats.Count, Equals, int64(0))
c.Assert(stats.ModifyCount, Equals, int64(0))
}

func (s *testStatsUpdateSuite) TestMultiSession(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
Expand Down

0 comments on commit 34b8abb

Please sign in to comment.