Skip to content

Commit

Permalink
address commnet
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao committed Oct 21, 2019
1 parent 775f37b commit 2ec341e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 25 deletions.
3 changes: 1 addition & 2 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,7 @@ func (w *addIndexWorker) backfillIndexInTxn(handleRange reorgIndexTask) (taskCtx

// Lock the row key to notify us that someone delete or update the row,
// then we should not backfill the index of it, otherwise the adding index is redundant.
var ignore uint32
err := txn.LockKeys(context.Background(), &ignore, 0, idxRecord.key)
err := txn.LockKeys(context.Background(), nil, 0, idxRecord.key)
if err != nil {
return errors.Trace(err)
}
Expand Down
3 changes: 1 addition & 2 deletions executor/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,7 @@ func (e *RecoverIndexExec) backfillIndexInTxn(ctx context.Context, txn kv.Transa
}

recordKey := e.table.RecordKey(row.handle)
var ignore uint32
err := txn.LockKeys(ctx, &ignore, 0, recordKey)
err := txn.LockKeys(ctx, nil, 0, recordKey)
if err != nil {
return result, err
}
Expand Down
3 changes: 1 addition & 2 deletions kv/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func (s testMockSuite) TestInterface(c *C) {

transaction, err := storage.Begin()
c.Check(err, IsNil)
var ignore uint32
err = transaction.LockKeys(context.Background(), &ignore, 0, Key("lock"))
err = transaction.LockKeys(context.Background(), nil, 0, Key("lock"))
c.Check(err, IsNil)
transaction.SetOption(Option(23), struct{}{})
if mock, ok := transaction.(*mockTxn); ok {
Expand Down
13 changes: 4 additions & 9 deletions store/tikv/2pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,21 +718,16 @@ func (action actionPessimisticLock) handleSingleBatch(c *twoPhaseCommitter, bo *
return errors.Trace(err)
}

if err1 := bo.BackoffWithMaxSleep(boTxnLockFast, int(expire), errors.New(locks[0].String())); err1 != nil {
return err1
}
// Handle the killed flag when waiting for the pessimistic lock.
// When a txn runs into LockKeys() and backoff here, it has no chance to call
// executor.Next() and check the killed flag.
for {
if action.killed != nil {
if atomic.CompareAndSwapUint32(action.killed, 1, 0) {
return ErrQueryInterrupted
}
const checkKillInterval = 10 // millisecond
if expire > checkKillInterval {
time.Sleep(checkKillInterval * time.Millisecond)
expire -= checkKillInterval
} else {
time.Sleep(time.Duration(expire) * time.Millisecond)
break
}
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions store/tikv/2pc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ func (s *testCommitterSuite) TestUnsetPrimaryKey(c *C) {
c.Assert(txn.Set(key, key), IsNil)
txn.DelOption(kv.PresumeKeyNotExistsError)
txn.DelOption(kv.PresumeKeyNotExists)
var ignore uint32
err := txn.LockKeys(context.Background(), &ignore, txn.startTS, key)
err := txn.LockKeys(context.Background(), nil, txn.startTS, key)
c.Assert(err, NotNil)
c.Assert(txn.Delete(key), IsNil)
key2 := kv.Key("key2")
Expand All @@ -519,10 +518,9 @@ func (s *testCommitterSuite) TestUnsetPrimaryKey(c *C) {
func (s *testCommitterSuite) TestPessimisticLockedKeysDedup(c *C) {
txn := s.begin(c)
txn.SetOption(kv.Pessimistic, true)
var ignore uint32
err := txn.LockKeys(context.Background(), &ignore, 100, kv.Key("abc"), kv.Key("def"))
err := txn.LockKeys(context.Background(), nil, 100, kv.Key("abc"), kv.Key("def"))
c.Assert(err, IsNil)
err = txn.LockKeys(context.Background(), &ignore, 100, kv.Key("abc"), kv.Key("def"))
err = txn.LockKeys(context.Background(), nil, 100, kv.Key("abc"), kv.Key("def"))
c.Assert(err, IsNil)
c.Assert(txn.lockKeys, HasLen, 2)
}
Expand All @@ -532,12 +530,11 @@ func (s *testCommitterSuite) TestPessimisticTTL(c *C) {
txn := s.begin(c)
txn.SetOption(kv.Pessimistic, true)
time.Sleep(time.Millisecond * 100)
var ignore uint32
err := txn.LockKeys(context.Background(), &ignore, txn.startTS, key)
err := txn.LockKeys(context.Background(), nil, txn.startTS, key)
c.Assert(err, IsNil)
time.Sleep(time.Millisecond * 100)
key2 := kv.Key("key2")
err = txn.LockKeys(context.Background(), &ignore, txn.startTS, key2)
err = txn.LockKeys(context.Background(), nil, txn.startTS, key2)
c.Assert(err, IsNil)
lockInfo := s.getLockInfo(c, key)
elapsedTTL := lockInfo.LockTtl - PessimisticLockTTL
Expand Down
3 changes: 1 addition & 2 deletions store/tikv/ticlient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ func (s *testTiclientSuite) TestSingleKey(c *C) {
txn := s.beginTxn(c)
err := txn.Set(encodeKey(s.prefix, "key"), []byte("value"))
c.Assert(err, IsNil)
var ignore uint32
err = txn.LockKeys(context.Background(), &ignore, 0, encodeKey(s.prefix, "key"))
err = txn.LockKeys(context.Background(), nil, 0, encodeKey(s.prefix, "key"))
c.Assert(err, IsNil)
err = txn.Commit(context.Background())
c.Assert(err, IsNil)
Expand Down

0 comments on commit 2ec341e

Please sign in to comment.