diff --git a/ddl/reorg.go b/ddl/reorg.go index e4b3116e8f32c..623ab8d2ecfc2 100644 --- a/ddl/reorg.go +++ b/ddl/reorg.go @@ -248,7 +248,6 @@ func (d *ddlCtx) buildDescTableScan(ctx context.Context, startTS uint64, tbl tab builder.Request.NotFillCache = true builder.Request.Priority = kv.PriorityLow - builder.Request.IsolationLevel = kv.SI kvReq, err := builder.Build() sctx := newContext(d.store) diff --git a/distsql/request_builder.go b/distsql/request_builder.go index 5e569a80d7bb3..5e5261bfb9a61 100644 --- a/distsql/request_builder.go +++ b/distsql/request_builder.go @@ -17,7 +17,6 @@ import ( "math" "github.com/juju/errors" - "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/sessionctx/stmtctx" @@ -125,15 +124,9 @@ func (builder *RequestBuilder) SetKeepOrder(order bool) *RequestBuilder { return builder } -func (builder *RequestBuilder) getIsolationLevel(sv *variable.SessionVars) kv.IsoLevel { - var isoLevel string - if sv.TxnIsolationLevelOneShot.State == 2 { - isoLevel = sv.TxnIsolationLevelOneShot.Value - } - if isoLevel == "" { - isoLevel, _ = sv.GetSystemVar(variable.TxnIsolation) - } - if isoLevel == ast.ReadCommitted { +func (builder *RequestBuilder) getIsolationLevel() kv.IsoLevel { + switch builder.Tp { + case kv.ReqTypeAnalyze: return kv.RC } return kv.SI @@ -155,7 +148,7 @@ func (builder *RequestBuilder) getKVPriority(sv *variable.SessionVars) int { // "Concurrency", "IsolationLevel", "NotFillCache". func (builder *RequestBuilder) SetFromSessionVars(sv *variable.SessionVars) *RequestBuilder { builder.Request.Concurrency = sv.DistSQLScanConcurrency - builder.Request.IsolationLevel = builder.getIsolationLevel(sv) + builder.Request.IsolationLevel = builder.getIsolationLevel() builder.Request.NotFillCache = sv.StmtCtx.NotFillCache builder.Request.Priority = builder.getKVPriority(sv) return builder diff --git a/distsql/request_builder_test.go b/distsql/request_builder_test.go index d9bf8f261c541..bfd233318c5d9 100644 --- a/distsql/request_builder_test.go +++ b/distsql/request_builder_test.go @@ -507,7 +507,7 @@ func (s *testSuite) TestRequestBuilder5(c *C) { KeepOrder: true, Desc: false, Concurrency: 15, - IsolationLevel: 0, + IsolationLevel: kv.RC, Priority: 1, NotFillCache: true, SyncLog: false, diff --git a/executor/analyze.go b/executor/analyze.go index 2c20de123867f..d9b08ece4fd15 100644 --- a/executor/analyze.go +++ b/executor/analyze.go @@ -20,7 +20,6 @@ import ( "github.com/juju/errors" "github.com/pingcap/tidb/distsql" "github.com/pingcap/tidb/domain" - "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/model" "github.com/pingcap/tidb/mysql" @@ -176,7 +175,6 @@ func (e *AnalyzeIndexExec) open() error { SetKeepOrder(true). Build() kvReq.Concurrency = e.concurrency - kvReq.IsolationLevel = kv.RC ctx := context.TODO() e.result, err = distsql.Analyze(ctx, e.ctx.GetClient(), kvReq, e.ctx.GetSessionVars().KVVars) if err != nil { @@ -291,7 +289,6 @@ func (e *AnalyzeColumnsExec) buildResp(ranges []*ranger.Range) (distsql.SelectRe SetAnalyzeRequest(e.analyzePB). SetKeepOrder(e.keepOrder). Build() - kvReq.IsolationLevel = kv.RC kvReq.Concurrency = e.concurrency if err != nil { return nil, errors.Trace(err) diff --git a/executor/set.go b/executor/set.go index 97509d766a458..29f783a96f47a 100644 --- a/executor/set.go +++ b/executor/set.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/tidb/ast" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/expression" - "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/terror" @@ -181,13 +180,6 @@ func (e *SetExecutor) setSysVariable(name string, v *expression.VarAssignment) e log.Infof("con:%d %s=%s", sessionVars.ConnectionID, name, valStr) } - if name == variable.TxnIsolation { - isoLevel, _ := sessionVars.GetSystemVar(variable.TxnIsolation) - if isoLevel == ast.ReadCommitted { - e.ctx.Txn().SetOption(kv.IsolationLevel, kv.RC) - } - } - return nil } diff --git a/session/session.go b/session/session.go index 981ab1412caea..d76313e581abd 100644 --- a/session/session.go +++ b/session/session.go @@ -1351,10 +1351,6 @@ func (s *session) ActivePendingTxn() error { return errors.Trace(err) } s.sessionVars.TxnCtx.StartTS = s.txn.StartTS() - isoLevel, _ := s.sessionVars.GetSystemVar(variable.TxnIsolation) - if isoLevel == ast.ReadCommitted { - s.txn.SetOption(kv.IsolationLevel, kv.RC) - } return nil } diff --git a/session/session_test.go b/session/session_test.go index fa956eb36530a..2179a89e1c7a2 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -2000,7 +2000,7 @@ func (s *testSessionSuite) TestSetTransactionIsolationOneShot(c *C) { // Check isolation level is set to read committed. ctx := context.WithValue(context.Background(), "CheckSelectRequestHook", func(req *kv.Request) { - c.Assert(req.IsolationLevel, Equals, kv.RC) + c.Assert(req.IsolationLevel, Equals, kv.SI) }) tk.Se.Execute(ctx, "select * from t where k = 1") diff --git a/store/tikv/lock_test.go b/store/tikv/lock_test.go index e3177dafc4ce0..f544053f6dbb6 100644 --- a/store/tikv/lock_test.go +++ b/store/tikv/lock_test.go @@ -181,22 +181,6 @@ func (s *testLockSuite) TestGetTxnStatus(c *C) { c.Assert(status.IsCommitted(), IsFalse) } -func (s *testLockSuite) TestRC(c *C) { - s.putKV(c, []byte("key"), []byte("v1")) - - txn, err := s.store.Begin() - c.Assert(err, IsNil) - txn.Set([]byte("key"), []byte("v2")) - s.prewriteTxn(c, txn.(*tikvTxn)) - - txn2, err := s.store.Begin() - c.Assert(err, IsNil) - txn2.SetOption(kv.IsolationLevel, kv.RC) - val, err := txn2.Get([]byte("key")) - c.Assert(err, IsNil) - c.Assert(string(val), Equals, "v1") -} - func (s *testLockSuite) prewriteTxn(c *C, txn *tikvTxn) { committer, err := newTwoPhaseCommitter(txn, 0) c.Assert(err, IsNil) diff --git a/store/tikv/scan.go b/store/tikv/scan.go index d8e57dc1d4020..0ccf297666ee6 100644 --- a/store/tikv/scan.go +++ b/store/tikv/scan.go @@ -146,9 +146,8 @@ func (s *Scanner) getData(bo *Backoffer) error { Version: s.startTS(), }, Context: pb.Context{ - IsolationLevel: pbIsolationLevel(s.snapshot.isolationLevel), - Priority: s.snapshot.priority, - NotFillCache: s.snapshot.notFillCache, + Priority: s.snapshot.priority, + NotFillCache: s.snapshot.notFillCache, }, } resp, err := sender.SendReq(bo, req, loc.Region, ReadTimeoutMedium) diff --git a/store/tikv/snapshot.go b/store/tikv/snapshot.go index 2c91c3bd1d5b6..986dd2dd58943 100644 --- a/store/tikv/snapshot.go +++ b/store/tikv/snapshot.go @@ -42,13 +42,12 @@ const ( // tikvSnapshot implements the kv.Snapshot interface. type tikvSnapshot struct { - store *tikvStore - version kv.Version - isolationLevel kv.IsoLevel - priority pb.CommandPri - notFillCache bool - syncLog bool - vars *kv.Variables + store *tikvStore + version kv.Version + priority pb.CommandPri + notFillCache bool + syncLog bool + vars *kv.Variables } var snapshotGP = gp.New(time.Minute) @@ -56,11 +55,10 @@ var snapshotGP = gp.New(time.Minute) // newTiKVSnapshot creates a snapshot of an TiKV store. func newTiKVSnapshot(store *tikvStore, ver kv.Version) *tikvSnapshot { return &tikvSnapshot{ - store: store, - version: ver, - isolationLevel: kv.SI, - priority: pb.CommandPri_Normal, - vars: kv.DefaultVars, + store: store, + version: ver, + priority: pb.CommandPri_Normal, + vars: kv.DefaultVars, } } @@ -151,9 +149,8 @@ func (s *tikvSnapshot) batchGetSingleRegion(bo *Backoffer, batch batchKeys, coll Version: s.version.Ver, }, Context: pb.Context{ - Priority: s.priority, - IsolationLevel: pbIsolationLevel(s.isolationLevel), - NotFillCache: s.notFillCache, + Priority: s.priority, + NotFillCache: s.notFillCache, }, } resp, err := sender.SendReq(bo, req, batch.region, ReadTimeoutMedium) @@ -233,9 +230,8 @@ func (s *tikvSnapshot) get(bo *Backoffer, k kv.Key) ([]byte, error) { Version: s.version.Ver, }, Context: pb.Context{ - Priority: s.priority, - IsolationLevel: pbIsolationLevel(s.isolationLevel), - NotFillCache: s.notFillCache, + Priority: s.priority, + NotFillCache: s.notFillCache, }, } for { diff --git a/store/tikv/txn.go b/store/tikv/txn.go index 27bd026f88b59..a39a0d110ceaa 100644 --- a/store/tikv/txn.go +++ b/store/tikv/txn.go @@ -144,8 +144,6 @@ func (txn *tikvTxn) Delete(k kv.Key) error { func (txn *tikvTxn) SetOption(opt kv.Option, val interface{}) { txn.us.SetOption(opt, val) switch opt { - case kv.IsolationLevel: - txn.snapshot.isolationLevel = val.(kv.IsoLevel) case kv.Priority: txn.snapshot.priority = kvPriorityToCommandPri(val.(int)) case kv.NotFillCache: @@ -157,9 +155,6 @@ func (txn *tikvTxn) SetOption(opt kv.Option, val interface{}) { func (txn *tikvTxn) DelOption(opt kv.Option) { txn.us.DelOption(opt) - if opt == kv.IsolationLevel { - txn.snapshot.isolationLevel = kv.SI - } } func (txn *tikvTxn) Commit(ctx context.Context) error {