crdb session变量维护堆栈

session默认事务隔离级别

pkg/storage/engine/enginepb/mvcc3.pb.go

1
2
3
4
5
6
7
8
9
10
11
type IsolationType int32
const (
SERIALIZABLE IsolationType = 0
SNAPSHOT IsolationType = 1
)
var IsolationType_name = map[int32]string{
0: "SERIALIZABLE",
1: "SNAPSHOT",
}

pkg/sql/pgwire/v3.go
pkg/sql/session.go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
func NewSession(
ctx context.Context, args SessionArgs, e *Executor, remote net.Addr, memMetrics *MemoryMetrics,
) *Session {
ctx = e.AnnotateCtx(ctx)
distSQLMode := DistSQLExecMode(DistSQLClusterExecMode.Get(&e.cfg.Settings.SV))
s := &Session{
Database: args.Database,
DefaultIsolationLevel: enginepb.SNAPSHOT,
DistSQLMode: distSQLMode,
SearchPath: sqlbase.DefaultSearchPath,
Location: time.UTC,
User: args.User,
virtualSchemas: e.virtualSchemas,
execCfg: &e.cfg,

初始化session时,不指定DefaultIsolationLevel,即DefaultIsolationLevel=0.

pkg/sql/executor.go

1
2
3
4
5
6
7
8
txnState.resetForNewSQLTxn(
e, session,
autoCommit, /* implicitTxn */
false, /* retryIntent */
e.cfg.Clock.PhysicalTime(), /* sqlTimestamp */
session.DefaultIsolationLevel,
roachpb.NormalUserPriority,
)

执行语句之前,如果语句不在trx中,则reset其隔离级别为session.DefaultIsolationLevel

set default_transaction_isolation=‘SERIALIZABLE’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0 0x00000000056e1bb7 in github.com/cockroachdb/cockroach/pkg/sql.glob..func82
at ./pkg/sql/vars.go:169
1 0x00000000056918ef in github.com/cockroachdb/cockroach/pkg/sql.(*setNode).Start
at ./pkg/sql/set.go:106
2 0x000000000566863c in github.com/cockroachdb/cockroach/pkg/sql.(*planner).startPlan
at ./pkg/sql/plan.go:225
3 0x000000000561e361 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execClassic
at ./pkg/sql/executor.go:1984
4 0x000000000561f529 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execStmt
at ./pkg/sql/executor.go:2156
5 0x000000000561c7ba in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execStmtInOpenTxn
at ./pkg/sql/executor.go:1795
6 0x000000000561af78 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execSingleStatement
at ./pkg/sql/executor.go:1315
7 0x000000000561a45c in github.com/cockroachdb/cockroach/pkg/sql.runTxnAttempt
at ./pkg/sql/executor.go:1190
8 0x00000000056191bc in github.com/cockroachdb/cockroach/pkg/sql.runWithAutoRetry
at ./pkg/sql/executor.go:1016
9 0x0000000005617f3e in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execParsed
at ./pkg/sql/executor.go:833
10 0x0000000005617aa1 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execRequest

show all

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
0 0x00000000056e1edf in github.com/cockroachdb/cockroach/pkg/sql.glob..func83
at ./pkg/sql/vars.go:184
1 0x00000000056d960a in github.com/cockroachdb/cockroach/pkg/sql.glob..func18
at ./pkg/sql/crdb_internal.go:626
2 0x00000000056f73c0 in github.com/cockroachdb/cockroach/pkg/sql.virtualTableEntry.getPlanInfo.func1
at ./pkg/sql/virtual_schema.go:121
3 0x00000000056e5bd5 in github.com/cockroachdb/cockroach/pkg/sql.(*planner).getVirtualDataSource.func1
at ./pkg/sql/data_source.go:321
4 0x0000000005624744 in github.com/cockroachdb/cockroach/pkg/sql.doExpandPlan
at ./pkg/sql/expand_plan.go:238
5 0x000000000562580a in github.com/cockroachdb/cockroach/pkg/sql.expandRenderNode
at ./pkg/sql/expand_plan.go:330
6 0x0000000005623a98 in github.com/cockroachdb/cockroach/pkg/sql.doExpandPlan
at ./pkg/sql/expand_plan.go:234
7 0x00000000056225e3 in github.com/cockroachdb/cockroach/pkg/sql.(*planner).expandPlan
at ./pkg/sql/expand_plan.go:33
8 0x000000000565e9eb in github.com/cockroachdb/cockroach/pkg/sql.(*planner).optimizePlan
at ./pkg/sql/optimize.go:46
9 0x00000000056681f9 in github.com/cockroachdb/cockroach/pkg/sql.(*planner).makePlan
at ./pkg/sql/plan.go:202
10 0x000000000561efea in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execStmt
at ./pkg/sql/executor.go:2129
11 0x000000000561c7ba in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execStmtInOpenTxn
at ./pkg/sql/executor.go:1795
12 0x000000000561af78 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execSingleStatement
at ./pkg/sql/executor.go:1315
13 0x000000000561a45c in github.com/cockroachdb/cockroach/pkg/sql.runTxnAttempt
at ./pkg/sql/executor.go:1190
14 0x00000000056191bc in github.com/cockroachdb/cockroach/pkg/sql.runWithAutoRetry
at ./pkg/sql/executor.go:1016
15 0x0000000005617f3e in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execParsed
at ./pkg/sql/executor.go:833
16 0x0000000005617aa1 in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).execRequest
at ./pkg/sql/executor.go:744
17 0x0000000005616ecb in github.com/cockroachdb/cockroach/pkg/sql.(*Executor).ExecuteStatements
at ./pkg/sql/executor.go:629
18 0x0000000005777ec7 in github.com/cockroachdb/cockroach/pkg/sql/pgwire.(*v3Conn).handleSimpleQuery

本文标题:crdb session变量维护堆栈

文章作者:Louis

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

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

原始链接:/2017/11/15/crdb-set-session-vars/

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