Skip to content

Commit

Permalink
pkg: remove txn lock (#6208)
Browse files Browse the repository at this point in the history
ref #5895

Signed-off-by: Ryan Leung <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
rleungx and ti-chi-bot authored Mar 23, 2023
1 parent 791106f commit 769de12
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions pkg/storage/kv/etcd_kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/utils/etcdutil"
"github.com/tikv/pd/pkg/utils/syncutil"
"go.etcd.io/etcd/clientv3"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -195,10 +194,8 @@ func (t *SlowLogTxn) Commit() (*clientv3.TxnResponse, error) {
// Transaction commit will be successful only if all conditions are met,
// aka, no other transaction has modified values loaded during current transaction.
type etcdTxn struct {
kv *etcdKVBase
ctx context.Context
// mu protects conditions and operations.
mu syncutil.Mutex
kv *etcdKVBase
ctx context.Context
conditions []clientv3.Cmp
operations []clientv3.Op
}
Expand All @@ -221,8 +218,6 @@ func (kv *etcdKVBase) RunInTxn(ctx context.Context, f func(txn Txn) error) error
func (txn *etcdTxn) Save(key, value string) error {
key = path.Join(txn.kv.rootPath, key)
operation := clientv3.OpPut(key, value)
txn.mu.Lock()
defer txn.mu.Unlock()
txn.operations = append(txn.operations, operation)
return nil
}
Expand All @@ -231,8 +226,6 @@ func (txn *etcdTxn) Save(key, value string) error {
func (txn *etcdTxn) Remove(key string) error {
key = path.Join(txn.kv.rootPath, key)
operation := clientv3.OpDelete(key)
txn.mu.Lock()
defer txn.mu.Unlock()
txn.operations = append(txn.operations, operation)
return nil
}
Expand Down Expand Up @@ -261,8 +254,6 @@ func (txn *etcdTxn) Load(key string) (string, error) {
return "", errs.ErrEtcdKVGetResponse.GenWithStackByArgs(resp.Kvs)
}
// Append the check condition to transaction.
txn.mu.Lock()
defer txn.mu.Unlock()
txn.conditions = append(txn.conditions, condition)
return value, nil
}
Expand All @@ -276,8 +267,6 @@ func (txn *etcdTxn) LoadRange(key, endKey string, limit int) (keys []string, val
return keys, values, err
}
// If LoadRange successful, must make sure values stay the same before commit.
txn.mu.Lock()
defer txn.mu.Unlock()
for i := range keys {
fullKey := path.Join(txn.kv.rootPath, keys[i])
condition := clientv3.Compare(clientv3.Value(fullKey), "=", values[i])
Expand Down

0 comments on commit 769de12

Please sign in to comment.