From 9c806e7fdf9fa69663b5643c31c306fc424ccd05 Mon Sep 17 00:00:00 2001 From: lucasliang Date: Thu, 12 Oct 2023 21:10:06 +0800 Subject: [PATCH 1/3] bugfix: fix invalid nil pointer when trying to record Store.SlownessStat. Signed-off-by: lucasliang --- internal/locate/region_request.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/locate/region_request.go b/internal/locate/region_request.go index 7d2aaf82e..fd7bcfc5c 100644 --- a/internal/locate/region_request.go +++ b/internal/locate/region_request.go @@ -1680,7 +1680,7 @@ func (s *RegionRequestSender) sendReqToRegion( start := time.Now() resp, err = s.client.SendRequest(ctx, sendToAddr, req, timeout) // Record timecost of external requests on related Store when ReplicaReadMode == PreferLeader. - if req.ReplicaReadType == kv.ReplicaReadPreferLeader && !util.IsInternalRequest(req.RequestSource) { + if req.ReplicaReadType == kv.ReplicaReadPreferLeader && !util.IsInternalRequest(req.RequestSource) && rpcCtx.Store != nil { rpcCtx.Store.recordSlowScoreStat(time.Since(start)) } if s.Stats != nil { From 180f44a4683e7b56414af26e9e69fe90e3e3c0aa Mon Sep 17 00:00:00 2001 From: lucasliang Date: Thu, 12 Oct 2023 21:13:51 +0800 Subject: [PATCH 2/3] Polish codes. Signed-off-by: lucasliang --- internal/locate/region_request.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/locate/region_request.go b/internal/locate/region_request.go index fd7bcfc5c..deef091eb 100644 --- a/internal/locate/region_request.go +++ b/internal/locate/region_request.go @@ -1680,7 +1680,7 @@ func (s *RegionRequestSender) sendReqToRegion( start := time.Now() resp, err = s.client.SendRequest(ctx, sendToAddr, req, timeout) // Record timecost of external requests on related Store when ReplicaReadMode == PreferLeader. - if req.ReplicaReadType == kv.ReplicaReadPreferLeader && !util.IsInternalRequest(req.RequestSource) && rpcCtx.Store != nil { + if rpcCtx.Store != nil && req.ReplicaReadType == kv.ReplicaReadPreferLeader && !util.IsInternalRequest(req.RequestSource) { rpcCtx.Store.recordSlowScoreStat(time.Since(start)) } if s.Stats != nil { From c6a885f8c83501903cafc217608d1b0ef7f20a27 Mon Sep 17 00:00:00 2001 From: lucasliang Date: Mon, 16 Oct 2023 10:56:03 +0800 Subject: [PATCH 3/3] Polish comments. Signed-off-by: lucasliang --- internal/locate/region_request.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/locate/region_request.go b/internal/locate/region_request.go index deef091eb..9c9e613e0 100644 --- a/internal/locate/region_request.go +++ b/internal/locate/region_request.go @@ -1679,7 +1679,7 @@ func (s *RegionRequestSender) sendReqToRegion( if !injectFailOnSend { start := time.Now() resp, err = s.client.SendRequest(ctx, sendToAddr, req, timeout) - // Record timecost of external requests on related Store when ReplicaReadMode == PreferLeader. + // Record timecost of external requests on related Store when `ReplicaReadMode == "PreferLeader"`. if rpcCtx.Store != nil && req.ReplicaReadType == kv.ReplicaReadPreferLeader && !util.IsInternalRequest(req.RequestSource) { rpcCtx.Store.recordSlowScoreStat(time.Since(start)) }