Skip to content

Commit 702b551

Browse files
coocoodshenli
authored andcommitted
*: disable read committed isolation level (#7282)
1 parent 5ed9c62 commit 702b551

10 files changed

Lines changed: 20 additions & 68 deletions

File tree

distsql/request_builder.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"math"
1818

1919
"github.com/juju/errors"
20-
"github.com/pingcap/tidb/ast"
2120
"github.com/pingcap/tidb/kv"
2221
"github.com/pingcap/tidb/sessionctx/stmtctx"
2322
"github.com/pingcap/tidb/sessionctx/variable"
@@ -124,15 +123,9 @@ func (builder *RequestBuilder) SetKeepOrder(order bool) *RequestBuilder {
124123
return builder
125124
}
126125

127-
func (builder *RequestBuilder) getIsolationLevel(sv *variable.SessionVars) kv.IsoLevel {
128-
var isoLevel string
129-
if sv.TxnIsolationLevelOneShot.State == 2 {
130-
isoLevel = sv.TxnIsolationLevelOneShot.Value
131-
}
132-
if isoLevel == "" {
133-
isoLevel, _ = sv.GetSystemVar(variable.TxnIsolation)
134-
}
135-
if isoLevel == ast.ReadCommitted {
126+
func (builder *RequestBuilder) getIsolationLevel() kv.IsoLevel {
127+
switch builder.Tp {
128+
case kv.ReqTypeAnalyze:
136129
return kv.RC
137130
}
138131
return kv.SI
@@ -142,7 +135,7 @@ func (builder *RequestBuilder) getIsolationLevel(sv *variable.SessionVars) kv.Is
142135
// "Concurrency", "IsolationLevel", "NotFillCache".
143136
func (builder *RequestBuilder) SetFromSessionVars(sv *variable.SessionVars) *RequestBuilder {
144137
builder.Request.Concurrency = sv.DistSQLScanConcurrency
145-
builder.Request.IsolationLevel = builder.getIsolationLevel(sv)
138+
builder.Request.IsolationLevel = builder.getIsolationLevel()
146139
builder.Request.NotFillCache = sv.StmtCtx.NotFillCache
147140
return builder
148141
}

distsql/request_builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ func (s *testSuite) TestRequestBuilder5(c *C) {
507507
KeepOrder: true,
508508
Desc: false,
509509
Concurrency: 0,
510-
IsolationLevel: 0,
510+
IsolationLevel: kv.SI,
511511
Priority: 1,
512512
NotFillCache: true,
513513
SyncLog: false,

executor/analyze.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/juju/errors"
2222
"github.com/pingcap/tidb/distsql"
2323
"github.com/pingcap/tidb/domain"
24-
"github.com/pingcap/tidb/kv"
2524
"github.com/pingcap/tidb/metrics"
2625
"github.com/pingcap/tidb/model"
2726
"github.com/pingcap/tidb/mysql"
@@ -201,7 +200,6 @@ func (e *AnalyzeIndexExec) open() error {
201200
SetPriority(e.priority).
202201
Build()
203202
kvReq.Concurrency = e.concurrency
204-
kvReq.IsolationLevel = kv.RC
205203
ctx := context.TODO()
206204
e.result, err = distsql.Analyze(ctx, e.ctx.GetClient(), kvReq)
207205
if err != nil {
@@ -317,7 +315,6 @@ func (e *AnalyzeColumnsExec) buildResp(ranges []*ranger.NewRange) (distsql.Selec
317315
SetKeepOrder(e.keepOrder).
318316
SetPriority(e.priority).
319317
Build()
320-
kvReq.IsolationLevel = kv.RC
321318
kvReq.Concurrency = e.concurrency
322319
if err != nil {
323320
return nil, errors.Trace(err)

executor/set.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/pingcap/tidb/ast"
2323
"github.com/pingcap/tidb/domain"
2424
"github.com/pingcap/tidb/expression"
25-
"github.com/pingcap/tidb/kv"
2625
"github.com/pingcap/tidb/sessionctx"
2726
"github.com/pingcap/tidb/sessionctx/variable"
2827
"github.com/pingcap/tidb/terror"
@@ -181,13 +180,6 @@ func (e *SetExecutor) setSysVariable(name string, v *expression.VarAssignment) e
181180
log.Infof("con:%d %s=%s", sessionVars.ConnectionID, name, valStr)
182181
}
183182

184-
if name == variable.TxnIsolation {
185-
isoLevel, _ := sessionVars.GetSystemVar(variable.TxnIsolation)
186-
if isoLevel == ast.ReadCommitted {
187-
e.ctx.Txn().SetOption(kv.IsolationLevel, kv.RC)
188-
}
189-
}
190-
191183
return nil
192184
}
193185

session/session.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,10 +1360,6 @@ func (s *session) ActivePendingTxn() error {
13601360
return errors.Trace(err)
13611361
}
13621362
s.sessionVars.TxnCtx.StartTS = s.txn.StartTS()
1363-
isoLevel, _ := s.sessionVars.GetSystemVar(variable.TxnIsolation)
1364-
if isoLevel == ast.ReadCommitted {
1365-
s.txn.SetOption(kv.IsolationLevel, kv.RC)
1366-
}
13671363
return nil
13681364
}
13691365

session/session_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ func (s *testSessionSuite) TestSetTransactionIsolationOneShot(c *C) {
19851985

19861986
// Check isolation level is set to read committed.
19871987
ctx := context.WithValue(context.Background(), "CheckSelectRequestHook", func(req *kv.Request) {
1988-
c.Assert(req.IsolationLevel, Equals, kv.RC)
1988+
c.Assert(req.IsolationLevel, Equals, kv.SI)
19891989
})
19901990
tk.Se.Execute(ctx, "select * from t where k = 1")
19911991

store/tikv/lock_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,6 @@ func (s *testLockSuite) TestGetTxnStatus(c *C) {
181181
c.Assert(status.IsCommitted(), IsFalse)
182182
}
183183

184-
func (s *testLockSuite) TestRC(c *C) {
185-
s.putKV(c, []byte("key"), []byte("v1"))
186-
187-
txn, err := s.store.Begin()
188-
c.Assert(err, IsNil)
189-
txn.Set([]byte("key"), []byte("v2"))
190-
s.prewriteTxn(c, txn.(*tikvTxn))
191-
192-
txn2, err := s.store.Begin()
193-
c.Assert(err, IsNil)
194-
txn2.SetOption(kv.IsolationLevel, kv.RC)
195-
val, err := txn2.Get([]byte("key"))
196-
c.Assert(err, IsNil)
197-
c.Assert(string(val), Equals, "v1")
198-
}
199-
200184
func (s *testLockSuite) prewriteTxn(c *C, txn *tikvTxn) {
201185
committer, err := newTwoPhaseCommitter(txn, 0)
202186
c.Assert(err, IsNil)

store/tikv/scan.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ func (s *Scanner) getData(bo *Backoffer) error {
146146
Version: s.startTS(),
147147
},
148148
Context: pb.Context{
149-
IsolationLevel: pbIsolationLevel(s.snapshot.isolationLevel),
150-
Priority: s.snapshot.priority,
151-
NotFillCache: s.snapshot.notFillCache,
149+
Priority: s.snapshot.priority,
150+
NotFillCache: s.snapshot.notFillCache,
152151
},
153152
}
154153
resp, err := sender.SendReq(bo, req, loc.Region, ReadTimeoutMedium)

store/tikv/snapshot.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,21 @@ const (
3939

4040
// tikvSnapshot implements the kv.Snapshot interface.
4141
type tikvSnapshot struct {
42-
store *tikvStore
43-
version kv.Version
44-
isolationLevel kv.IsoLevel
45-
priority pb.CommandPri
46-
notFillCache bool
47-
syncLog bool
42+
store *tikvStore
43+
version kv.Version
44+
priority pb.CommandPri
45+
notFillCache bool
46+
syncLog bool
4847
}
4948

5049
var snapshotGP = gp.New(time.Minute)
5150

5251
// newTiKVSnapshot creates a snapshot of an TiKV store.
5352
func newTiKVSnapshot(store *tikvStore, ver kv.Version) *tikvSnapshot {
5453
return &tikvSnapshot{
55-
store: store,
56-
version: ver,
57-
isolationLevel: kv.SI,
58-
priority: pb.CommandPri_Normal,
54+
store: store,
55+
version: ver,
56+
priority: pb.CommandPri_Normal,
5957
}
6058
}
6159

@@ -146,9 +144,8 @@ func (s *tikvSnapshot) batchGetSingleRegion(bo *Backoffer, batch batchKeys, coll
146144
Version: s.version.Ver,
147145
},
148146
Context: pb.Context{
149-
Priority: s.priority,
150-
IsolationLevel: pbIsolationLevel(s.isolationLevel),
151-
NotFillCache: s.notFillCache,
147+
Priority: s.priority,
148+
NotFillCache: s.notFillCache,
152149
},
153150
}
154151
resp, err := sender.SendReq(bo, req, batch.region, ReadTimeoutMedium)
@@ -228,9 +225,8 @@ func (s *tikvSnapshot) get(bo *Backoffer, k kv.Key) ([]byte, error) {
228225
Version: s.version.Ver,
229226
},
230227
Context: pb.Context{
231-
Priority: s.priority,
232-
IsolationLevel: pbIsolationLevel(s.isolationLevel),
233-
NotFillCache: s.notFillCache,
228+
Priority: s.priority,
229+
NotFillCache: s.notFillCache,
234230
},
235231
}
236232
for {

store/tikv/txn.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ func (txn *tikvTxn) Delete(k kv.Key) error {
138138
func (txn *tikvTxn) SetOption(opt kv.Option, val interface{}) {
139139
txn.us.SetOption(opt, val)
140140
switch opt {
141-
case kv.IsolationLevel:
142-
txn.snapshot.isolationLevel = val.(kv.IsoLevel)
143141
case kv.Priority:
144142
txn.snapshot.priority = kvPriorityToCommandPri(val.(int))
145143
case kv.NotFillCache:
@@ -151,9 +149,6 @@ func (txn *tikvTxn) SetOption(opt kv.Option, val interface{}) {
151149

152150
func (txn *tikvTxn) DelOption(opt kv.Option) {
153151
txn.us.DelOption(opt)
154-
if opt == kv.IsolationLevel {
155-
txn.snapshot.isolationLevel = kv.SI
156-
}
157152
}
158153

159154
func (txn *tikvTxn) Commit(ctx context.Context) error {

0 commit comments

Comments
 (0)