Skip to content
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

*:Record the time consuming of memory operation of Insert Executor in Runtime Information #19574

Merged
merged 54 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d4d75a8
init
jyz0309 Aug 28, 2020
7b7b7c8
update trace
jyz0309 Aug 28, 2020
c8287b9
update trace batchCheckAndInsert
jyz0309 Aug 28, 2020
278fc96
check-dev
jyz0309 Aug 28, 2020
6112068
update comment
jyz0309 Aug 28, 2020
ffec1b5
init
jyz0309 Aug 28, 2020
27b4732
update the duration about check and insert
jyz0309 Aug 28, 2020
09959fa
test and make ci good
jyz0309 Aug 28, 2020
5bc2779
get line
jyz0309 Aug 28, 2020
b295c62
init
jyz0309 Sep 1, 2020
b76a420
debug and pass the unit-test
jyz0309 Sep 2, 2020
9182f03
pass the test
jyz0309 Sep 2, 2020
abd58cf
init
jyz0309 Sep 3, 2020
a9bfd2f
init
jyz0309 Sep 8, 2020
9a5dc57
add insertRuntimeStat
jyz0309 Sep 8, 2020
b1a7704
pass check_dev
jyz0309 Sep 9, 2020
56179e3
add GetTime func
jyz0309 Sep 9, 2020
c945b83
avoid panic
jyz0309 Sep 9, 2020
841d1ad
init stats try
jyz0309 Sep 10, 2020
cd1f440
make ci good
jyz0309 Sep 10, 2020
23dc5eb
test before update
jyz0309 Sep 10, 2020
83054f5
test
jyz0309 Sep 10, 2020
c4254c1
Merge branch 'master' into issue-19512
crazycs520 Sep 10, 2020
087e24e
init
jyz0309 Sep 10, 2020
6821421
Merge branch 'issue-19512' of github.com:jyz0309/tidb into issue-19512
jyz0309 Sep 10, 2020
7482a8d
update time way
jyz0309 Sep 11, 2020
2c3bbc6
change var name
jyz0309 Sep 11, 2020
79f6265
Merge branch 'master' into issue-19512
jyz0309 Sep 11, 2020
9f948e3
init
jyz0309 Sep 11, 2020
0fb6abe
update test
jyz0309 Sep 11, 2020
a8aa56b
update
jyz0309 Sep 11, 2020
8229bdf
Merge branch 'master' into issue-19512
jyz0309 Sep 11, 2020
84ad780
make ci happy
jyz0309 Sep 11, 2020
c884b60
Merge branch 'issue-19512' of github.com:jyz0309/tidb into issue-19512
jyz0309 Sep 11, 2020
e2cc549
add method
jyz0309 Sep 12, 2020
20cd97d
add method
jyz0309 Sep 12, 2020
d169dcd
add test
jyz0309 Sep 13, 2020
d5678c7
remove useless line
jyz0309 Sep 13, 2020
fe83e3b
update the String()
jyz0309 Sep 15, 2020
29f5893
Merge branch 'master' into issue-19512
jyz0309 Sep 15, 2020
59cde1b
make ci happy
jyz0309 Sep 15, 2020
91e3483
update the insert ignore
jyz0309 Sep 15, 2020
519c894
Merge branch 'master' into issue-19512
jyz0309 Sep 15, 2020
d3fb5d1
optimize
jyz0309 Sep 16, 2020
4ab1d43
Merge branch 'issue-19512' of github.com:jyz0309/tidb into issue-19512
jyz0309 Sep 16, 2020
158a73f
update test
jyz0309 Sep 16, 2020
a5f4161
to avoid panic
jyz0309 Sep 17, 2020
29dde7c
change var name
jyz0309 Sep 17, 2020
ca4b1e4
Merge branch 'master' into issue-19512
crazycs520 Sep 17, 2020
a49c881
Merge branch 'master' into issue-19512
qw4990 Sep 17, 2020
7ad372e
add replace and insert ignore on duplicate key test
jyz0309 Sep 18, 2020
8b12410
Merge branch 'issue-19512' of github.com:jyz0309/tidb into issue-19512
jyz0309 Sep 18, 2020
648c7e6
Merge branch 'master' into issue-19512
crazycs520 Sep 21, 2020
ad377c1
Merge branch 'master' into issue-19512
qw4990 Sep 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions executor/insert_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package executor
import (
"context"
"math"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/parser/ast"
Expand Down Expand Up @@ -947,7 +948,7 @@ func (e *InsertValues) collectRuntimeStatsEnabled() bool {
func (e *InsertValues) batchCheckAndInsert(ctx context.Context, rows [][]types.Datum, addRecord func(ctx context.Context, row []types.Datum) error) error {
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
// all the rows will be checked, so it is safe to set BatchCheck = true
e.ctx.GetSessionVars().StmtCtx.BatchCheck = true

start := time.Now()
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
// Get keys need to be checked.
toBeCheckedRows, err := getKeysNeedCheck(ctx, e.ctx, e.Table, rows)
if err != nil {
Expand All @@ -971,9 +972,9 @@ func (e *InsertValues) batchCheckAndInsert(ctx context.Context, rows [][]types.D
return err
}

skiplist := make([]bool, len(toBeCheckedRows))
// append warnings and get no duplicated error rows
for i, r := range toBeCheckedRows {
skip := false
if r.handleKey != nil {
_, err := txn.Get(ctx, r.handleKey.newKV.key)
if err == nil {
Expand All @@ -989,24 +990,29 @@ func (e *InsertValues) batchCheckAndInsert(ctx context.Context, rows [][]types.D
if err == nil {
// If duplicate keys were found in BatchGet, mark row = nil.
e.ctx.GetSessionVars().StmtCtx.AppendWarning(uk.dupErr)
skip = true
skiplist[i] = true
break
}
if !kv.IsErrNotFound(err) {
return err
}
}
// If row was checked with no duplicate keys,
// it should be add to values map for the further row check.
// There may be duplicate keys inside the insert statement.
}
end := time.Now()
e.stats.check = end.Sub(start)
// If row was checked with no duplicate keys,
// it should be add to values map for the further` row check.
// There may be duplicate keys inside the insert statement.
for index, skip := range skiplist {
if !skip {
e.ctx.GetSessionVars().StmtCtx.AddCopiedRows(1)
err = addRecord(ctx, rows[i])
err = addRecord(ctx, rows[index])
if err != nil {
return err
}
}
}
e.stats.insert = time.Since(end)
return nil
}

Expand Down
13 changes: 11 additions & 2 deletions executor/point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package executor

import (
"context"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
Expand Down Expand Up @@ -468,21 +469,29 @@ func getColInfoByID(tbl *model.TableInfo, colID int64) *model.ColumnInfo {
type runtimeStatsWithSnapshot struct {
*execdetails.BasicRuntimeStats
*tikv.SnapshotRuntimeStats
check time.Duration
insert time.Duration
}

func (e *runtimeStatsWithSnapshot) String() string {
var basic, rpcStatsStr string
var basic, rpcStatsStr, checkStr, insertStr string
if e.BasicRuntimeStats != nil {
basic = e.BasicRuntimeStats.String()
}
if e.SnapshotRuntimeStats != nil {
rpcStatsStr = e.SnapshotRuntimeStats.String()
}
if e.check != 0 {
checkStr = "check use:" + e.check.String()
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
}
if e.insert != 0 {
insertStr = "insert use:" + e.insert.String()
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
}
if rpcStatsStr == "" {
return basic
}
if basic == "" {
return rpcStatsStr
}
return basic + ", " + rpcStatsStr
return basic + ", " + rpcStatsStr + "," + checkStr + "," + insertStr
}
3 changes: 2 additions & 1 deletion store/tikv/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ func (s *Scanner) startTS() uint64 {
}

func (s *Scanner) resolveCurrentLock(bo *Backoffer, current *pb.KvPair) error {
val, err := s.snapshot.get(bo, current.Key)
ctx := context.Background()
val, err := s.snapshot.get(ctx, bo, current.Key)
if err != nil {
return errors.Trace(err)
}
Expand Down
15 changes: 7 additions & 8 deletions store/tikv/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,14 @@ func (s *tikvSnapshot) batchGetSingleRegion(bo *Backoffer, batch batchKeys, coll

// Get gets the value for key k from snapshot.
func (s *tikvSnapshot) Get(ctx context.Context, k kv.Key) ([]byte, error) {
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
span1 := span.Tracer().StartSpan("tikvSnapshot.get", opentracing.ChildOf(span.Context()))
defer span1.Finish()
ctx = opentracing.ContextWithSpan(ctx, span1)
}

defer func(start time.Time) {
tikvTxnCmdHistogramWithGet.Observe(time.Since(start).Seconds())
}(time.Now())

ctx = context.WithValue(ctx, txnStartKey, s.version.Ver)
bo := NewBackofferWithVars(ctx, getMaxBackoff, s.vars)
val, err := s.get(bo, k)
val, err := s.get(ctx, bo, k)
s.recordBackoffInfo(bo)
if err != nil {
return nil, errors.Trace(err)
Expand All @@ -344,7 +339,7 @@ func (s *tikvSnapshot) Get(ctx context.Context, k kv.Key) ([]byte, error) {
return val, nil
}

func (s *tikvSnapshot) get(bo *Backoffer, k kv.Key) ([]byte, error) {
func (s *tikvSnapshot) get(ctx context.Context, bo *Backoffer, k kv.Key) ([]byte, error) {
// Check the cached values first.
s.mu.RLock()
if s.mu.cached != nil {
Expand All @@ -355,7 +350,11 @@ func (s *tikvSnapshot) get(bo *Backoffer, k kv.Key) ([]byte, error) {
}
}
s.mu.RUnlock()

if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
span1 := span.Tracer().StartSpan("tikvSnapshot.get", opentracing.ChildOf(span.Context()))
defer span1.Finish()
opentracing.ContextWithSpan(ctx, span1)
}
failpoint.Inject("snapshot-get-cache-fail", func(_ failpoint.Value) {
if bo.ctx.Value("TestSnapshotCache") != nil {
panic("cache miss")
Expand Down