From fbe67c3b56ab56837a14f325f1504e32f207be8b Mon Sep 17 00:00:00 2001 From: yisaer Date: Fri, 14 May 2021 12:26:57 +0800 Subject: [PATCH] address the comment Signed-off-by: yisaer --- store/tikv/kv.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/store/tikv/kv.go b/store/tikv/kv.go index bbf8517a42a8c..03fe370bd10cd 100644 --- a/store/tikv/kv.go +++ b/store/tikv/kv.go @@ -66,13 +66,10 @@ var oracleUpdateInterval = 2000 // KVStore contains methods to interact with a TiKV cluster. type KVStore struct { - clusterID uint64 - uuid string - oracle oracle.Oracle - clientMu struct { - sync.RWMutex - client Client - } + clusterID uint64 + uuid string + oracle oracle.Oracle + client atomic.Value pdClient pd.Client regionCache *RegionCache lockResolver *LockResolver @@ -144,7 +141,7 @@ func NewKVStore(uuid string, pdClient pd.Client, spkv SafePointKV, client Client closed: make(chan struct{}), replicaReadSeed: rand.Uint32(), } - store.clientMu.client = reqCollapse{client} + store.client.Store(reqCollapse{client}) store.lockResolver = newLockResolver(store) go store.runSafePointChecker() @@ -346,16 +343,12 @@ func (s *KVStore) SetOracle(oracle oracle.Oracle) { // SetTiKVClient resets the client instance. func (s *KVStore) SetTiKVClient(client Client) { - s.clientMu.Lock() - defer s.clientMu.Unlock() - s.clientMu.client = client + s.client.Store(client) } // GetTiKVClient gets the client instance. func (s *KVStore) GetTiKVClient() (client Client) { - s.clientMu.RLock() - defer s.clientMu.RUnlock() - return s.clientMu.client + return s.client.Load().(Client) } func (s *KVStore) getSafeTS(storeID uint64) uint64 {