diff --git a/distsql/distsql.go b/distsql/distsql.go index 80d4960a3328e..21806d3b9eb51 100644 --- a/distsql/distsql.go +++ b/distsql/distsql.go @@ -56,9 +56,9 @@ func Select(ctx context.Context, sctx sessionctx.Context, kvReq *kv.Request, fie label = metrics.LblInternal } - // kvReq.MemTracker is used to trace and control memory usage in DistSQL layer; + // kvReq.memTracker is used to trace and control memory usage in DistSQL layer; // for streamResult, since it is a pipeline which has no buffer, it's not necessary to trace it; - // for selectResult, we just use the kvReq.MemTracker prepared for co-processor + // for selectResult, we just use the kvReq.memTracker prepared for co-processor // instead of creating a new one for simplification. if kvReq.Streaming { return &streamResult{ diff --git a/executor/distsql.go b/executor/distsql.go index b4f4cd35d9f36..82e71a9b7c199 100644 --- a/executor/distsql.go +++ b/executor/distsql.go @@ -76,13 +76,13 @@ type lookupTableTask struct { duplicatedIndexOrder map[int64]int // memUsage records the memory usage of this task calculated by table worker. - // MemTracker is used to release memUsage after task is done and unused. + // memTracker is used to release memUsage after task is done and unused. // // The sequence of function calls are: // 1. calculate task.memUsage. - // 2. task.MemTracker = tableWorker.MemTracker - // 3. task.MemTracker.Consume(task.memUsage) - // 4. task.MemTracker.Consume(-task.memUsage) + // 2. task.memTracker = tableWorker.memTracker + // 3. task.memTracker.Consume(task.memUsage) + // 4. task.memTracker.Consume(-task.memUsage) // // Step 1~3 are completed in "tableWorker.executeTask". // Step 4 is completed in "IndexLookUpExecutor.Next". @@ -345,7 +345,7 @@ type IndexLookUpExecutor struct { resultCurr *lookupTableTask feedback *statistics.QueryFeedback - // MemTracker is used to track the memory usage of this executor. + // memTracker is used to track the memory usage of this executor. memTracker *memory.Tracker // checkIndexValue is used to check the consistency of the index data. @@ -390,7 +390,7 @@ func (e *IndexLookUpExecutor) Open(ctx context.Context) error { } func (e *IndexLookUpExecutor) open(ctx context.Context) error { - // We have to initialize "MemTracker" and other execution resources in here + // We have to initialize "memTracker" and other execution resources in here // instead of in function "Open", because this "IndexLookUpExecutor" may be // constructed by a "IndexLookUpJoin" and "Open" will not be called in that // situation. @@ -787,7 +787,7 @@ type tableWorker struct { keepOrder bool handleIdx int - // MemTracker is used to track the memory usage of this executor. + // memTracker is used to track the memory usage of this executor. memTracker *memory.Tracker // checkIndexValue is used to check the consistency of the index data. diff --git a/executor/hash_table.go b/executor/hash_table.go index 0c24a0de97b7a..c453e781efd21 100644 --- a/executor/hash_table.go +++ b/executor/hash_table.go @@ -86,7 +86,7 @@ type hashRowContainer struct { // hashTable stores the map of hashKey and RowPtr hashTable *rowHashMap - // MemTracker is the reference of records.GetMemTracker(). + // memTracker is the reference of records.GetMemTracker(). // records would be set to nil for garbage collection when spilling is activated // so we need this reference. memTracker *memory.Tracker diff --git a/executor/insert.go b/executor/insert.go index d5df351c77605..812a617e234ba 100644 --- a/executor/insert.go +++ b/executor/insert.go @@ -42,7 +42,7 @@ type InsertExec struct { row4Update []types.Datum Priority mysql.PriorityEnum - MemTracker *memory.Tracker + memTracker *memory.Tracker } func (e *InsertExec) exec(ctx context.Context, rows [][]types.Datum, memTracker *memory.Tracker) error { @@ -269,8 +269,8 @@ func (e *InsertExec) Close() error { // Open implements the Executor Open interface. func (e *InsertExec) Open(ctx context.Context) error { - e.MemTracker = memory.NewTracker(e.id, -1) - e.MemTracker.AttachTo(e.ctx.GetSessionVars().StmtCtx.MemTracker) + e.memTracker = memory.NewTracker(e.id, -1) + e.memTracker.AttachTo(e.ctx.GetSessionVars().StmtCtx.MemTracker) if e.OnDuplicate != nil { e.initEvalBuffer4Dup() diff --git a/executor/insert_common.go b/executor/insert_common.go index 563c8501f3b07..186a97c832e3d 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -203,7 +203,7 @@ func insertRows(ctx context.Context, base insertCommon) (err error) { } var memTracker *memory.Tracker if insertExec, ok := base.(*InsertExec); ok { - memTracker = insertExec.MemTracker + memTracker = insertExec.memTracker } else { replaceExec := base.(*ReplaceExec) memTracker = replaceExec.MemTracker @@ -401,7 +401,7 @@ func insertRowsFromSelect(ctx context.Context, base insertCommon) error { rows := make([][]types.Datum, 0, chk.Capacity()) var memTracker *memory.Tracker if insertExec, ok := base.(*InsertExec); ok { - memTracker = insertExec.MemTracker + memTracker = insertExec.memTracker } else { replaceExec := base.(*ReplaceExec) memTracker = replaceExec.MemTracker diff --git a/kv/kv.go b/kv/kv.go index 0f3a75fa61425..e64441da99623 100644 --- a/kv/kv.go +++ b/kv/kv.go @@ -264,7 +264,7 @@ type Request struct { IsolationLevel IsoLevel // Priority is the priority of this KV request, its value may be PriorityNormal/PriorityLow/PriorityHigh. Priority int - // MemTracker is used to trace and control memory usage in co-processor layer. + // memTracker is used to trace and control memory usage in co-processor layer. MemTracker *memory.Tracker // KeepOrder is true, if the response should be returned in order. KeepOrder bool diff --git a/session/session.go b/session/session.go index 2fab4a1bb05c5..2043e8aeaa925 100644 --- a/session/session.go +++ b/session/session.go @@ -70,7 +70,6 @@ import ( "github.com/pingcap/tidb/util/timeutil" "github.com/pingcap/tipb/go-binlog" "go.uber.org/zap" - "github.com/pingcap/tidb/util/memory" ) var ( diff --git a/session/tidb.go b/session/tidb.go index 7fa271cdbed09..3cfaea52bf6f9 100644 --- a/session/tidb.go +++ b/session/tidb.go @@ -277,7 +277,7 @@ func runStmt(ctx context.Context, sctx sessionctx.Context, s sqlexec.Statement) if err != nil { sctx.StmtRollback() } else { - err = sctx.StmtCommit(nil) + err = sctx.StmtCommit(sctx.GetSessionVars().StmtCtx.MemTracker) } } } else { diff --git a/table/tables/tables_test.go b/table/tables/tables_test.go index 8912df5846b2f..465f5cb3c42de 100644 --- a/table/tables/tables_test.go +++ b/table/tables/tables_test.go @@ -319,7 +319,7 @@ func (ts *testSuite) TestUnsignedPK(c *C) { c.Assert(err, IsNil) c.Assert(len(row), Equals, 2) c.Assert(row[0].Kind(), Equals, types.KindUint64) - c.Assert(ts.se.StmtCommit(), IsNil) + c.Assert(ts.se.StmtCommit(nil), IsNil) txn, err := ts.se.Txn(true) c.Assert(err, IsNil) c.Assert(txn.Commit(context.Background()), IsNil)