Skip to content

Commit

Permalink
store/tikv: make LockKeys() function thread safe (pingcap#6340) (ping…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and coocood committed Apr 25, 2018
1 parent e0b7668 commit b4d72e0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions store/tikv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package tikv

import (
"fmt"
"sync"
"time"

"github.com/juju/errors"
Expand All @@ -40,6 +41,7 @@ type tikvTxn struct {
commitTS uint64
valid bool
lockKeys [][]byte
mu sync.Mutex // For thread-safe LockKeys function.
dirty bool
setCnt int64
}
Expand Down Expand Up @@ -214,9 +216,11 @@ func (txn *tikvTxn) Rollback() error {

func (txn *tikvTxn) LockKeys(keys ...kv.Key) error {
metrics.TiKVTxnCmdCounter.WithLabelValues("lock_keys").Inc()
txn.mu.Lock()
for _, key := range keys {
txn.lockKeys = append(txn.lockKeys, key)
}
txn.mu.Unlock()
return nil
}

Expand Down

0 comments on commit b4d72e0

Please sign in to comment.