Skip to content

Commit

Permalink
tikv: skip 0 when call getMinSafeTSByStores
Browse files Browse the repository at this point in the history
Signed-off-by: Hangjie Mo <mohangjie1995@gmail.com>
  • Loading branch information
Defined2014 committed Nov 3, 2022
1 parent 8f35d3a commit bd622b0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,12 @@ func (s *KVStore) GetClusterID() uint64 {
return s.clusterID
}

func (s *KVStore) getSafeTS(storeID uint64) uint64 {
func (s *KVStore) getSafeTS(storeID uint64) (bool, uint64) {
safeTS, ok := s.safeTSMap.Load(storeID)
if !ok {
return 0
return false, 0
}
return safeTS.(uint64)
return true, safeTS.(uint64)
}

// setSafeTS sets safeTs for store storeID, export for testing
Expand All @@ -511,9 +511,13 @@ func (s *KVStore) getMinSafeTSByStores(stores []*locate.Store) uint64 {
return 0
}
for _, store := range stores {
safeTS := s.getSafeTS(store.StoreID())
if safeTS < minSafeTS {
minSafeTS = safeTS
ok, safeTS := s.getSafeTS(store.StoreID())
if ok {
if safeTS != 0 && safeTS < minSafeTS {
minSafeTS = safeTS
}
} else {
minSafeTS = 0
}
}
return minSafeTS
Expand Down Expand Up @@ -559,7 +563,7 @@ func (s *KVStore) updateSafeTS(ctx context.Context) {
return
}
safeTS := resp.Resp.(*kvrpcpb.StoreSafeTSResponse).GetSafeTs()
preSafeTS := s.getSafeTS(storeID)
_, preSafeTS := s.getSafeTS(storeID)
if preSafeTS > safeTS {
metrics.TiKVSafeTSUpdateCounter.WithLabelValues("skip", storeIDStr).Inc()
preSafeTSTime := oracle.GetTimeFromTS(preSafeTS)
Expand Down

0 comments on commit bd622b0

Please sign in to comment.