diff --git a/config/config.go b/config/config.go index 78fb4e4c86fb6..9e9ce88c2e17e 100644 --- a/config/config.go +++ b/config/config.go @@ -262,8 +262,8 @@ var defaultConf = Config{ MemQuotaQuery: 32 << 30, EnableStreaming: false, TxnLocalLatches: TxnLocalLatches{ - Enabled: false, - Capacity: 10240000, + Enabled: true, + Capacity: 2048000, }, LowerCaseTableNames: 2, Log: Log{ diff --git a/config/config.toml.example b/config/config.toml.example index bea0a99590eb6..d67efc5f1b9a0 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -232,8 +232,8 @@ commit-timeout = "41s" [txn-local-latches] # Enable local latches for transactions. Enable it when # there are lots of conflicts between transactions. -enabled = false -capacity = 10240000 +enabled = true +capacity = 2048000 [binlog] diff --git a/executor/write_test.go b/executor/write_test.go index 98a91cf58d455..3079c9c35f001 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -1793,7 +1793,7 @@ func (s *testSuite) TestNullDefault(c *C) { tk.MustQuery("select * from test_null_default").Check(testkit.Rows("", "1970-01-01 08:20:34")) } -func (s *testBypassSuite) TestBypassLatch(c *C) { +func (s *testBypassSuite) TestLatch(c *C) { store, err := mockstore.NewMockTikvStore( // Small latch slot size to make conflicts. mockstore.WithTxnLocalLatches(64), @@ -1827,15 +1827,13 @@ func (s *testBypassSuite) TestBypassLatch(c *C) { tk2.MustExec("commit") } - // txn1 and txn2 data range do not overlap, but using latches result in txn conflict. + // txn1 and txn2 data range do not overlap, using latches should not + // result in txn conflict. fn() tk1.MustExec("commit") tk1.MustExec("truncate table t") fn() - txn := tk1.Se.Txn() - txn.SetOption(kv.BypassLatch, true) - // Bypass latch, there will be no conflicts. tk1.MustExec("commit") } diff --git a/kv/kv.go b/kv/kv.go index 1c9230ed65a6a..8c8a0830b208a 100644 --- a/kv/kv.go +++ b/kv/kv.go @@ -43,9 +43,6 @@ const ( NotFillCache // SyncLog decides whether the WAL(write-ahead log) of this request should be synchronized. SyncLog - // BypassLatch option tells 2PC commit to bypass latches, it would be true when the - // transaction is not conflict-retryable, for example: 'select for update', 'load data'. - BypassLatch // KeyOnly retrieve only keys, it can be used in scan now. KeyOnly ) diff --git a/server/conn.go b/server/conn.go index f8a269a9735e7..11f2ebbc89de0 100644 --- a/server/conn.go +++ b/server/conn.go @@ -764,11 +764,6 @@ func insertDataWithCommit(ctx context.Context, prevData, curData []byte, loadDat break } loadDataInfo.Ctx.StmtCommit() - // Load data should not use latches, because: - // 1. latches may result in false positive transaction conflicts. - // 2. load data is not retryable when it meets conflicts. - // 3. load data will abort abnormally under condition 1 + 2. - loadDataInfo.Ctx.Txn().SetOption(kv.BypassLatch, true) // Make sure that there are no retries when committing. if err = loadDataInfo.Ctx.RefreshTxnCtx(ctx); err != nil { return nil, errors.Trace(err) @@ -837,7 +832,6 @@ func (cc *clientConn) handleLoadData(ctx context.Context, loadDataInfo *executor return errors.Trace(err) } - txn.SetOption(kv.BypassLatch, true) return errors.Trace(cc.ctx.CommitTxn(sessionctx.SetCommitCtx(ctx, loadDataInfo.Ctx))) } diff --git a/session/session.go b/session/session.go index 9d195a4cddf7d..716eb8eda60b4 100644 --- a/session/session.go +++ b/session/session.go @@ -312,9 +312,6 @@ func (s *session) doCommit(ctx context.Context) error { } // Set this option for 2 phase commit to validate schema lease. s.txn.SetOption(kv.SchemaChecker, domain.NewSchemaChecker(domain.GetDomain(s), s.sessionVars.TxnCtx.SchemaVersion, tableIDs)) - if s.sessionVars.TxnCtx.ForUpdate { - s.txn.SetOption(kv.BypassLatch, true) - } if err := s.txn.Commit(sessionctx.SetCommitCtx(ctx, s)); err != nil { return errors.Trace(err) diff --git a/store/tikv/txn.go b/store/tikv/txn.go index 18b7e1a17d31f..96ff1311244f9 100644 --- a/store/tikv/txn.go +++ b/store/tikv/txn.go @@ -192,17 +192,6 @@ func (txn *tikvTxn) Commit(ctx context.Context) error { } // latches enabled - var bypassLatch bool - if option := txn.us.GetOption(kv.BypassLatch); option != nil { - bypassLatch = option.(bool) - } - // When bypassLatch flag is true, commit directly. - if bypassLatch { - err = committer.executeAndWriteFinishBinlog(ctx) - log.Debug("[kv]", connID, " txnLatches enabled while txn not retryable, 2pc directly:", err) - return errors.Trace(err) - } - // for transactions which need to acquire latches lock := txn.store.txnLatches.Lock(committer.startTS, committer.keys) defer txn.store.txnLatches.UnLock(lock)