Skip to content

Commit

Permalink
*: fix panic log when call RegionRequestSender.String method
Browse files Browse the repository at this point in the history
Signed-off-by: crazycs520 <[email protected]>
  • Loading branch information
crazycs520 committed Apr 3, 2024
1 parent 125a140 commit a1e0bb3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ type RegionRequestSender struct {
}

func (s *RegionRequestSender) String() string {
return fmt.Sprintf("{rpcError:%v,replicaSelector: %v}", s.rpcError, s.replicaSelector.String())
if s.replicaSelector == nil {
return fmt.Sprintf("{rpcError:%v, replicaSelector: %v}", s.rpcError, s.replicaSelector)
}
return fmt.Sprintf("{rpcError:%v, replicaSelector: %v}", s.rpcError, s.replicaSelector.String())
}

// RegionRequestRuntimeStats records the runtime stats of send region requests.
Expand Down
10 changes: 10 additions & 0 deletions internal/locate/region_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,13 @@ func (s *testRegionRequestToSingleStoreSuite) TestClientExt() {
s.NotNil(sender.client)
s.Nil(sender.getClientExt())
}

func (s *testRegionRequestToSingleStoreSuite) TestRegionRequestSenderString() {
sender := NewRegionRequestSender(s.cache, &fnClient{})
loc, err := s.cache.LocateRegionByID(s.bo, s.region)
s.Nil(err)
// invalid region cache before sending request.
s.cache.InvalidateCachedRegion(loc.Region)
sender.SendReqCtx(s.bo, tikvrpc.NewRequest(tikvrpc.CmdGet, &kvrpcpb.GetRequest{}), loc.Region, time.Second, tikvrpc.TiKV)
s.Equal("{rpcError:cached region invalid, replicaSelector: <nil>}", sender.String())
}

0 comments on commit a1e0bb3

Please sign in to comment.