Skip to content

Commit 8da079b

Browse files
committed
reduce compare
Signed-off-by: husharp <[email protected]>
1 parent 6a19c69 commit 8da079b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tikv/kv.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ func (s *KVStore) updateSafeTS(ctx context.Context) {
547547
tikvClient := s.GetTiKVClient()
548548
wg := &sync.WaitGroup{}
549549
wg.Add(len(stores))
550-
safeTS, txnScopeMap, err := s.buildTxnScopeMap(ctx)
550+
safeTS, txnScopeMap, err := s.buildTxnScopeMap(ctx, stores)
551551
for _, store := range stores {
552552
storeID := store.StoreID()
553553
storeAddr := store.GetAddr()
@@ -591,19 +591,22 @@ func (s *KVStore) updateSafeTS(ctx context.Context) {
591591
}(ctx, wg, storeID, storeAddr)
592592
}
593593

594-
for txnScope, storeIDs := range txnScopeMap {
595-
s.updateMinSafeTS(txnScope, storeIDs)
594+
if safeTS != 0 && err == nil {
595+
s.minSafeTS.Store(oracle.GlobalTxnScope, safeTS)
596+
} else {
597+
for txnScope, storeIDs := range txnScopeMap {
598+
s.updateMinSafeTS(txnScope, storeIDs)
599+
}
596600
}
597601
wg.Wait()
598602
}
599603

600604
// build txnScopeMap and judge whether it is needed to get safeTS from PD.
601605
// - if stores label are global, return get cluster min resolved ts from pd.
602606
// - if contains dc label store, return try to get it from TiKV.
603-
func (s *KVStore) buildTxnScopeMap(ctx context.Context) (safeTS uint64, txnScopeMap map[string][]uint64, err error) {
607+
func (s *KVStore) buildTxnScopeMap(ctx context.Context, stores []*Store) (safeTS uint64, txnScopeMap map[string][]uint64, err error) {
604608
isGlobal := true
605609
txnScopeMap = make(map[string][]uint64)
606-
stores := s.regionCache.GetStoresByType(tikvrpc.TiKV)
607610
for _, store := range stores {
608611
txnScopeMap[oracle.GlobalTxnScope] = append(txnScopeMap[oracle.GlobalTxnScope], store.StoreID())
609612

0 commit comments

Comments
 (0)