Skip to content

Commit

Permalink
ddl: release memory cache for all tidb-servers when unlock tables (pi…
Browse files Browse the repository at this point in the history
…ngcap#21006)

Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
  • Loading branch information
jackysp authored Nov 13, 2020
1 parent 5aada1f commit 975bbaf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 0 additions & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5420,7 +5420,6 @@ func (d *ddl) UnlockTables(ctx sessionctx.Context, unlockTables []model.TableLoc
err := d.doDDLJob(ctx, job)
if err == nil {
ctx.ReleaseAllTableLocks()
ctx.GetStore().GetMemCache().Release()
}
err = d.callHookOnChanged(err)
return errors.Trace(err)
Expand Down
8 changes: 8 additions & 0 deletions domain/schema_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"sync"
"time"

"github.com/pingcap/parser/model"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/sessionctx/variable"
Expand Down Expand Up @@ -153,6 +154,13 @@ func (s *schemaValidator) Update(leaseGrantTS uint64, oldVer, currVer int64, cha
tblIDs = change.PhyTblIDS
actionTypes = change.ActionTypes
}
for _, ac := range actionTypes {
// NOTE: ac is not an action type, it is (1 << action type).
if ac == 1<<model.ActionUnlockTable {
// TODO: If we could unlock only one table, we should release parts of the cache.
s.do.Store().GetMemCache().Release()
}
}
logutil.BgLogger().Debug("update schema validator", zap.Int64("oldVer", oldVer),
zap.Int64("currVer", currVer), zap.Int64s("changedTableIDs", tblIDs), zap.Uint64s("changedActionTypes", actionTypes))
}
Expand Down
23 changes: 23 additions & 0 deletions executor/point_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,29 @@ func (s *testPointGetSuite) TestPointGetReadLock(c *C) {
c.Assert(len(rows), Equals, 1)
explain = fmt.Sprintf("%v", rows[0])
c.Assert(explain, Matches, ".*num_rpc.*")

// Test cache release after unlocking tables.
tk.MustExec("lock tables point read")
rows = tk.MustQuery("explain analyze select * from point where id = 1").Rows()
c.Assert(len(rows), Equals, 1)
explain = fmt.Sprintf("%v", rows[0])
c.Assert(explain, Matches, ".*num_rpc.*")

rows = tk.MustQuery("explain analyze select * from point where id = 1").Rows()
c.Assert(len(rows), Equals, 1)
explain = fmt.Sprintf("%v", rows[0])
ok = strings.Contains(explain, "num_rpc")
c.Assert(ok, IsFalse)

tk.MustExec("unlock tables")
tk.MustExec("lock tables point read")

rows = tk.MustQuery("explain analyze select * from point where id = 1").Rows()
c.Assert(len(rows), Equals, 1)
explain = fmt.Sprintf("%v", rows[0])
c.Assert(explain, Matches, ".*num_rpc.*")

tk.MustExec("unlock tables")
}

func (s *testPointGetSuite) TestPointGetWriteLock(c *C) {
Expand Down

0 comments on commit 975bbaf

Please sign in to comment.