Skip to content

Commit

Permalink
check nil
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp committed Aug 14, 2023
1 parent d8451eb commit a376cf3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func (s *KVStore) updateSafeTS(ctx context.Context) {
wg.Add(len(stores))
// Try to get the minimum resolved timestamp of the store from PD.
var err error
storeMinResolvedTSs := make(map[uint64]uint64)
var storeMinResolvedTSs map[uint64]uint64
if s.pdHttpClient != nil {
storeIDs := make([]string, len(stores))
for i, store := range stores {
Expand All @@ -608,10 +608,10 @@ func (s *KVStore) updateSafeTS(ctx context.Context) {
go func(ctx context.Context, wg *sync.WaitGroup, storeID uint64, storeAddr string) {
defer wg.Done()

safeTS := storeMinResolvedTSs[storeID]
var safeTS uint64
storeIDStr := strconv.FormatUint(storeID, 10)
// If getting the minimum resolved timestamp from PD failed or returned 0, try to get it from TiKV.
if safeTS == 0 || err != nil {
if storeMinResolvedTSs == nil || storeMinResolvedTSs[storeID] == 0 || err != nil {
resp, err := tikvClient.SendRequest(
ctx, storeAddr, tikvrpc.NewRequest(
tikvrpc.CmdStoreSafeTS, &kvrpcpb.StoreSafeTSRequest{
Expand All @@ -630,6 +630,8 @@ func (s *KVStore) updateSafeTS(ctx context.Context) {
return
}
safeTS = resp.Resp.(*kvrpcpb.StoreSafeTSResponse).GetSafeTs()
} else {
safeTS = storeMinResolvedTSs[storeID]
}

_, preSafeTS := s.getSafeTS(storeID)
Expand Down

0 comments on commit a376cf3

Please sign in to comment.