diff --git a/distsql/request_builder.go b/distsql/request_builder.go index d93233f04bb86..f44c40e086dc0 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/sessionctx/stmtctx" "github.com/pingcap/tidb/sessionctx/variable" @@ -124,15 +123,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 @@ -142,7 +135,7 @@ func (builder *RequestBuilder) getIsolationLevel(sv *variable.SessionVars) kv.Is // "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 return builder } diff --git a/distsql/request_builder_test.go b/distsql/request_builder_test.go index b5309b8270cab..2cc5b26c2e02d 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: 0, - IsolationLevel: 0, + IsolationLevel: kv.SI, Priority: 1, NotFillCache: true, SyncLog: false, diff --git a/executor/analyze.go b/executor/analyze.go index 81e8fc5e9888a..31669b5e0a0ea 100644 --- a/executor/analyze.go +++ b/executor/analyze.go @@ -21,7 +21,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" @@ -201,7 +200,6 @@ func (e *AnalyzeIndexExec) open() error { SetPriority(e.priority). Build() kvReq.Concurrency = e.concurrency - kvReq.IsolationLevel = kv.RC ctx := context.TODO() e.result, err = distsql.Analyze(ctx, e.ctx.GetClient(), kvReq) if err != nil { @@ -317,7 +315,6 @@ func (e *AnalyzeColumnsExec) buildResp(ranges []*ranger.NewRange) (distsql.Selec SetKeepOrder(e.keepOrder). SetPriority(e.priority). 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 7742e6afda34e..dedef780169b6 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 294e8a4658d03..bdc671f1b172c 100644 --- a/session/session.go +++ b/session/session.go @@ -1360,10 +1360,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 eb6243432b820..ef4051ddaeaf8 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -1985,7 +1985,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 3b7bfd94f5e1e..ce8614a28d7b3 100644 --- a/store/tikv/snapshot.go +++ b/store/tikv/snapshot.go @@ -39,12 +39,11 @@ 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 + store *tikvStore + version kv.Version + priority pb.CommandPri + notFillCache bool + syncLog bool } var snapshotGP = gp.New(time.Minute) @@ -52,10 +51,9 @@ 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, + store: store, + version: ver, + priority: pb.CommandPri_Normal, } } @@ -146,9 +144,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) @@ -228,9 +225,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 467fdae9272fe..9168fc1a2e7ac 100644 --- a/store/tikv/txn.go +++ b/store/tikv/txn.go @@ -138,8 +138,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: @@ -151,9 +149,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 {