Skip to content

Commit

Permalink
distinguish memory usage of selectResult & copIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
SunRunAway committed Jul 29, 2020
1 parent 4db32ba commit 65bd1b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion distsql/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/stringutil"
"github.com/pingcap/tipb/go-tipb"
)

Expand Down Expand Up @@ -75,6 +77,11 @@ func Select(ctx context.Context, sctx sessionctx.Context, kvReq *kv.Request, fie
if canUseChunkRPC(sctx) {
encodetype = tipb.EncodeType_TypeChunk
}
t := kvReq.MemTracker
if kvReq.MemTracker != nil {
t = memory.NewTracker(stringutil.StringerStr("selectResult"), -1)
t.AttachTo(kvReq.MemTracker)
}
return &selectResult{
label: "dag",
resp: resp,
Expand All @@ -83,7 +90,7 @@ func Select(ctx context.Context, sctx sessionctx.Context, kvReq *kv.Request, fie
ctx: sctx,
feedback: fb,
sqlType: label,
memTracker: kvReq.MemTracker,
memTracker: t,
encodeType: encodetype,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion executor/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ func (w *tableWorker) pickAndExecTask(ctx context.Context) {
buf := make([]byte, 4096)
stackSize := runtime.Stack(buf, false)
buf = buf[:stackSize]
logutil.Logger(ctx).Error("tableWorker in IndexLookUpExecutor panicked", zap.String("stack", string(buf)))
logutil.Logger(ctx).Error("tableWorker in IndexLookUpExecutor panicked", zap.String("r", fmt.Sprint(r)), zap.String("stack", string(buf)))
task.doneCh <- errors.Errorf("%v", r)
}
}()
Expand Down
8 changes: 7 additions & 1 deletion store/tikv/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/stringutil"
"github.com/pingcap/tipb/go-tipb"
"go.uber.org/zap"
)
Expand All @@ -67,13 +68,18 @@ func (c *CopClient) Send(ctx context.Context, req *kv.Request, vars *kv.Variable
if err != nil {
return copErrorResponse{err}
}
t := req.MemTracker
if req.MemTracker != nil {
t = memory.NewTracker(stringutil.StringerStr("copIterator"), -1)
t.AttachTo(req.MemTracker)
}
it := &copIterator{
store: c.store,
req: req,
concurrency: req.Concurrency,
finishCh: make(chan struct{}),
vars: vars,
memTracker: req.MemTracker,
memTracker: t,
replicaReadSeed: c.replicaReadSeed,
rpcCancel: NewRPCanceller(),
}
Expand Down

0 comments on commit 65bd1b3

Please sign in to comment.