@@ -547,7 +547,7 @@ func (s *KVStore) updateSafeTS(ctx context.Context) {
547
547
tikvClient := s .GetTiKVClient ()
548
548
wg := & sync.WaitGroup {}
549
549
wg .Add (len (stores ))
550
- safeTS , txnScopeMap , err := s .buildTxnScopeMap (ctx )
550
+ safeTS , txnScopeMap , err := s .buildTxnScopeMap (ctx , stores )
551
551
for _ , store := range stores {
552
552
storeID := store .StoreID ()
553
553
storeAddr := store .GetAddr ()
@@ -591,19 +591,22 @@ func (s *KVStore) updateSafeTS(ctx context.Context) {
591
591
}(ctx , wg , storeID , storeAddr )
592
592
}
593
593
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
+ }
596
600
}
597
601
wg .Wait ()
598
602
}
599
603
600
604
// build txnScopeMap and judge whether it is needed to get safeTS from PD.
601
605
// - if stores label are global, return get cluster min resolved ts from pd.
602
606
// - 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 ) {
604
608
isGlobal := true
605
609
txnScopeMap = make (map [string ][]uint64 )
606
- stores := s .regionCache .GetStoresByType (tikvrpc .TiKV )
607
610
for _ , store := range stores {
608
611
txnScopeMap [oracle .GlobalTxnScope ] = append (txnScopeMap [oracle .GlobalTxnScope ], store .StoreID ())
609
612
0 commit comments