crdb代码sql到kv调用堆栈

跟踪insert和select语句对应的从sql层到kv层的调度堆栈

insert into t1 values(1) 从请求到kv rpc堆栈

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
0 0x00000000057d7b43 in github.com/cockroachdb/cockroach/pkg/server.(*Node).batchInternal.func1
at ./pkg/server/node.go:851
1 0x0000000004aacfe8 in github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).RunTaskWithErr
at ./pkg/util/stop/stopper.go:246
2 0x00000000057bc9a2 in github.com/cockroachdb/cockroach/pkg/server.(*Node).batchInternal
at ./pkg/server/node.go:837
3 0x00000000057bcd2c in github.com/cockroachdb/cockroach/pkg/server.(*Node).Batch
at ./pkg/server/node.go:878
4 0x00000000054dbd76 in github.com/cockroachdb/cockroach/pkg/kv.(*grpcTransport).send.func1
at ./pkg/kv/transport.go:229
5 0x00000000054cfa7c in github.com/cockroachdb/cockroach/pkg/kv.(*grpcTransport).send
at ./pkg/kv/transport.go:242
6 0x00000000054cf613 in github.com/cockroachdb/cockroach/pkg/kv.(*grpcTransport).SendNext
at ./pkg/kv/transport.go:194
7 0x00000000054c50b0 in github.com/cockroachdb/cockroach/pkg/kv.(*DistSender).sendToReplicas
at ./pkg/kv/dist_sender.go:1229
8 0x00000000054bd7bf in github.com/cockroachdb/cockroach/pkg/kv.(*DistSender).sendRPC
at ./pkg/kv/dist_sender.go:383
9 0x00000000054bde64 in github.com/cockroachdb/cockroach/pkg/kv.(*DistSender).sendSingleRange
at ./pkg/kv/dist_sender.go:447
10 0x00000000054c2608 in github.com/cockroachdb/cockroach/pkg/kv.(*DistSender).sendPartialBatch
at ./pkg/kv/dist_sender.go:1013
11 0x00000000054c1b0b in github.com/cockroachdb/cockroach/pkg/kv.(*DistSender).divideAndSendBatchToRanges
at ./pkg/kv/dist_sender.go:689
12 0x00000000054bf76d in github.com/cockroachdb/cockroach/pkg/kv.(*DistSender).Send
at ./pkg/kv/dist_sender.go:619
13 0x00000000054d2f75 in github.com/cockroachdb/cockroach/pkg/kv.(*TxnCoordSender).Send
at ./pkg/kv/txn_coord_sender.go:444
14 0x0000000004b4a336 in github.com/cockroachdb/cockroach/pkg/internal/client.(*DB).send
at ./pkg/internal/client/db.go:551
15 0x0000000004b58fc1 in github.com/cockroachdb/cockroach/pkg/internal/client.(*Txn).Send
at ./pkg/internal/client/txn.go:959
16 0x0000000004b5ee06 in github.com/cockroachdb/cockroach/pkg/internal/client.(*Txn).Send-fm
at ./pkg/internal/client/txn.go:510
17 0x0000000004b497f3 in github.com/cockroachdb/cockroach/pkg/internal/client.sendAndFill
at ./pkg/internal/client/db.go:457
18 0x0000000004b55e3d in github.com/cockroachdb/cockroach/pkg/internal/client.(*Txn).Run
at ./pkg/internal/client/txn.go:510
19 0x0000000004b56815 in github.com/cockroachdb/cockroach/pkg/internal/client.(*Txn).CommitInBatch
at ./pkg/internal/client/txn.go:575
20 0x00000000056adb85 in github.com/cockroachdb/cockroach/pkg/sql.(*tableInserter).finalize
at ./pkg/sql/tablewriter.go:123
21 0x00000000056494d2 in github.com/cockroachdb/cockroach/pkg/sql.(*insertNode).internalNext
at ./pkg/sql/insert.go:357
22 0x0000000005649276 in github.com/cockroachdb/cockroach/pkg/sql.(*insertNode).Next
at ./pkg/sql/insert.go:333
23 0x000000000561e6f6 in github.com/cockroachdb/cockroach/pkg/sql.forEachRow
at ./pkg/sql/executor.go:2026
24 0x000000000561e897 in github.com/cockroachdb/cockroach/pkg/sql.countRowsAffected
at ./pkg/sql/executor.go:2049
25 0x000000000561e572 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execClassic
at ./pkg/sql/executor.go:1995
26 0x000000000561f529 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execStmt
at ./pkg/sql/executor.go:2156
27 0x000000000561c7ba in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execStmtInOpenTxn
at ./pkg/sql/executor.go:1795
28 0x000000000561af78 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execSingleStatement
at ./pkg/sql/executor.go:1315
29 0x000000000561a45c in github.com/cockroachdb/cockroach/pkg/sql.runTxnAttempt
at ./pkg/sql/executor.go:1190
30 0x00000000056191bc in github.com/cockroachdb/cockroach/pkg/sql.runWithAutoRetry
at ./pkg/sql/executor.go:1016
31 0x0000000005617f3e in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execParsed
at ./pkg/sql/executor.go:833
32 0x0000000005617aa1 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execRequest
at ./pkg/sql/executor.go:744
33 0x0000000005616ecb in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).ExecuteStatements
at ./pkg/sql/executor.go:629
34 0x0000000005777ec7 in github.com/cockroachdb/cockroach/pkg/sql/pgwire.(*v3Conn).handleSimpleQuery
at ./pkg/sql/pgwire/v3.go:622
35 0x0000000005777024 in github.com/cockroachdb/cockroach/pkg/sql/pgwire.(*v3Conn).serve
at ./pkg/sql/pgwire/v3.go:511
36 0x000000000576de53 in github.com/cockroachdb/cockroach/pkg/sql/pgwire.(*Server).ServeConn
at ./pkg/sql/pgwire/server.go:422
37 0x00000000057d9e39 in github.com/cockroachdb/cockroach/pkg/server.(*Server).Start.func17.1
at ./pkg/server/server.go:1188
38 0x0000000004e6dabf in github.com/cockroachdb/cockroach/pkg/util/netutil.(*Server).ServeWith.func1

select * from t1 到kv层面堆栈

set distsql='off' 便于跟踪。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
0 0x00000000054bf1db in github.com/cockroachdb/cockroach/pkg/kv.(*DistSender).Send
at ./pkg/kv/dist_sender.go:586
1 0x00000000054d2f75 in github.com/cockroachdb/cockroach/pkg/kv.(*TxnCoordSender).Send
at ./pkg/kv/txn_coord_sender.go:444
2 0x0000000004b4a336 in github.com/cockroachdb/cockroach/pkg/internal/client.(*DB).send
at ./pkg/internal/client/db.go:551
3 0x0000000004b58fc1 in github.com/cockroachdb/cockroach/pkg/internal/client.(*Txn).Send
at ./pkg/internal/client/txn.go:959
4 0x00000000052830e3 in github.com/cockroachdb/cockroach/pkg/sql/sqlbase.(*txnKVFetcher).fetch
at ./pkg/sql/sqlbase/kvfetcher.go:241
5 0x000000000528406e in github.com/cockroachdb/cockroach/pkg/sql/sqlbase.(*txnKVFetcher).nextKV
at ./pkg/sql/sqlbase/kvfetcher.go:310
6 0x000000000528f95a in github.com/cockroachdb/cockroach/pkg/sql/sqlbase.(*RowFetcher).NextKey
at ./pkg/sql/sqlbase/rowfetcher.go:259
7 0x000000000528f809 in github.com/cockroachdb/cockroach/pkg/sql/sqlbase.(*RowFetcher).StartScanFrom
at ./pkg/sql/sqlbase/rowfetcher.go:249
8 0x000000000528f686 in github.com/cockroachdb/cockroach/pkg/sql/sqlbase.(*RowFetcher).StartScan
at ./pkg/sql/sqlbase/rowfetcher.go:240
9 0x0000000005681db0 in github.com/cockroachdb/cockroach/pkg/sql.(*scanNode).initScan
at ./pkg/sql/scan.go:144
10 0x000000000568205a in github.com/cockroachdb/cockroach/pkg/sql.(*scanNode).Next
at ./pkg/sql/scan.go:172
11 0x000000000561e6b3 in github.com/cockroachdb/cockroach/pkg/sql.forEachRow
at ./pkg/sql/executor.go:2025
12 0x000000000561e4fa in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execClassic
at ./pkg/sql/executor.go:2002
13 0x000000000561f529 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execStmt
at ./pkg/sql/executor.go:2156
14 0x000000000561c7ba in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execStmtInOpenTxn
at ./pkg/sql/executor.go:1795
15 0x000000000561af78 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execSingleStatement
at ./pkg/sql/executor.go:1315
16 0x000000000561a45c in github.com/cockroachdb/cockroach/pkg/sql.runTxnAttempt
at ./pkg/sql/executor.go:1190
17 0x00000000056191bc in github.com/cockroachdb/cockroach/pkg/sql.runWithAutoRetry
at ./pkg/sql/executor.go:1016
18 0x0000000005617f3e in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execParsed
at ./pkg/sql/executor.go:833
19 0x0000000005617aa1 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execRequest
at ./pkg/sql/executor.go:744
20 0x0000000005616ecb in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).ExecuteStatements
at ./pkg/sql/executor.go:629
21 0x0000000005777ec7 in github.com/cockroachdb/cockroach/pkg/sql/pgwire.(*v3Conn).handleSimpleQuery
at ./pkg/sql/pgwire/v3.go:622
22 0x0000000005777024 in github.com/cockroachdb/cockroach/pkg/sql/pgwire.(*v3Conn).serve
at ./pkg/sql/pgwire/v3.go:511
23 0x000000000576de53 in github.com/cockroachdb/cockroach/pkg/sql/pgwire.(*Server).ServeConn

本文标题:crdb代码sql到kv调用堆栈

文章作者:Louis

发布时间:2017年11月15日 - 14:11

最后更新:2017年11月17日 - 15:11

原始链接:/2017/11/15/crdb-stack/

许可协议: Louis-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。