Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: remove kv.BypassLatch option and enable latch scheduler by default #7882

Merged
merged 2 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
8 changes: 3 additions & 5 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ func (s *testSuite) TestNullDefault(c *C) {
tk.MustQuery("select * from test_null_default").Check(testkit.Rows("<nil>", "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),
Expand Down Expand Up @@ -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")
}

Expand Down
3 changes: 0 additions & 3 deletions kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
6 changes: 0 additions & 6 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
}

Expand Down
3 changes: 0 additions & 3 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions store/tikv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down