-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LockCtx: add memTracker for InitCheckExistence in LockCtx #52739
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,11 +76,13 @@ import ( | |
"github.com/pingcap/tidb/pkg/util/deadlockhistory" | ||
"github.com/pingcap/tidb/pkg/util/disk" | ||
"github.com/pingcap/tidb/pkg/util/execdetails" | ||
"github.com/pingcap/tidb/pkg/util/hack" | ||
"github.com/pingcap/tidb/pkg/util/intest" | ||
"github.com/pingcap/tidb/pkg/util/logutil" | ||
"github.com/pingcap/tidb/pkg/util/logutil/consistency" | ||
"github.com/pingcap/tidb/pkg/util/memory" | ||
"github.com/pingcap/tidb/pkg/util/resourcegrouptag" | ||
"github.com/pingcap/tidb/pkg/util/set" | ||
"github.com/pingcap/tidb/pkg/util/sqlexec" | ||
"github.com/pingcap/tidb/pkg/util/syncutil" | ||
"github.com/pingcap/tidb/pkg/util/topsql" | ||
|
@@ -1210,6 +1212,8 @@ func (e *SelectLockExec) Next(ctx context.Context, req *chunk.Chunk) error { | |
|
||
func newLockCtx(sctx sessionctx.Context, lockWaitTime int64, numKeys int) (*tikvstore.LockCtx, error) { | ||
seVars := sctx.GetSessionVars() | ||
memTracker := memory.NewTracker(memory.LabelForLock, -1) | ||
memTracker.AttachTo(seVars.MemTracker) | ||
forUpdateTS, err := sessiontxn.GetTxnManager(sctx).GetStmtForUpdateTS() | ||
if err != nil { | ||
return nil, err | ||
|
@@ -1246,8 +1250,16 @@ func newLockCtx(sctx sessionctx.Context, lockWaitTime int64, numKeys int) (*tikv | |
rec := deadlockhistory.ErrDeadlockToDeadlockRecord(deadlock) | ||
deadlockhistory.GlobalDeadlockHistory.Push(rec) | ||
} | ||
lockCtx.OnMemChange = func(capacity int) uint64 { | ||
bucketMemoryUsage := hack.EstimateBucketMemoryUsageWithKVSize(lockCtx.GetValuesKSize(), lockCtx.GetValuesVSize()) | ||
mapSize := set.EstimateMapSize(capacity, bucketMemoryUsage) | ||
return mapSize | ||
} | ||
if lockCtx.ForUpdateTS > 0 && seVars.AssertionLevel != variable.AssertionLevelOff { | ||
lockCtx.InitCheckExistence(numKeys) | ||
if lockCtx.OnMemChange != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OnMemChange is defined in this function and only used here. So it seems to me that it is redundant to have a OnMemChange field in LockCtx. So you are only recording the initial usage of the struct. That leads to a question: should we dynamically track the structure, or is the initial usage is enough? Anyway it's a good start and better than tracking nothing. |
||
memTracker.Consume(lockCtx.OnMemChange(numKeys)) | ||
} | ||
} | ||
return lockCtx, nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some test cases for it.