From b771e6317faac5ae8cd2683e0c10e9957e1a8eaa Mon Sep 17 00:00:00 2001 From: husharp Date: Mon, 14 Aug 2023 14:24:53 +0800 Subject: [PATCH] make ci happy Signed-off-by: husharp --- tikv/kv.go | 8 +++++--- util/pd.go | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/tikv/kv.go b/tikv/kv.go index 468ffbf15..fbdd65d8b 100644 --- a/tikv/kv.go +++ b/tikv/kv.go @@ -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 { @@ -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{ @@ -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) diff --git a/util/pd.go b/util/pd.go index a9af5f237..68ac8c3e7 100644 --- a/util/pd.go +++ b/util/pd.go @@ -99,6 +99,7 @@ func (p *PDHTTPClient) GetMinResolvedTSByStoresIDs(ctx context.Context, storeIDs v, e := pdRequest(ctx, addr, query, p.cli, http.MethodGet, nil) if e != nil { logutil.BgLogger().Debug("failed to get min resolved ts", zap.String("addr", addr), zap.Error(e)) + err = e continue } logutil.BgLogger().Debug("min resolved ts", zap.String("resp", string(v))) @@ -117,14 +118,25 @@ func (p *PDHTTPClient) GetMinResolvedTSByStoresIDs(ctx context.Context, storeIDs } if val, e := EvalFailpoint("InjectMinResolvedTS"); e == nil { // Need to make sure successfully get from real pd. - for storeID, v := range d.StoresMinResolvedTS { - if v != 0 { - // Should be val.(uint64) but failpoint doesn't support that. - if tmp, ok := val.(int); ok { - d.StoresMinResolvedTS[storeID] = uint64(tmp) - logutil.BgLogger().Info("inject min resolved ts", zap.Uint64("storeID", storeID), zap.Uint64("ts", uint64(tmp))) + if d.StoresMinResolvedTS != nil { + for storeID, v := range d.StoresMinResolvedTS { + if v != 0 { + // Should be val.(uint64) but failpoint doesn't support that. + if tmp, ok := val.(int); ok { + d.StoresMinResolvedTS[storeID] = uint64(tmp) + logutil.BgLogger().Info("inject min resolved ts", zap.Uint64("storeID", storeID), zap.Uint64("ts", uint64(tmp))) + } } } + } else { + // Should be val.(uint64) but failpoint doesn't support that. + if tmp, ok := val.(int); ok { + // ci's store id is 1, we can change it if we have more stores. + // but for pool ci it's no need to do that :( + d.StoresMinResolvedTS = make(map[uint64]uint64) + d.StoresMinResolvedTS[1] = uint64(tmp) + logutil.BgLogger().Info("inject min resolved ts", zap.Uint64("ts", uint64(tmp))) + } } }