Skip to content

Commit

Permalink
retry stale read as stale if leader is not accessible
Browse files Browse the repository at this point in the history
Signed-off-by: rishabh_mittal <[email protected]>
  • Loading branch information
mittalrishabh committed Feb 3, 2025
1 parent 2eba2f6 commit 9783ca6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 7 deletions.
3 changes: 0 additions & 3 deletions internal/locate/region_request3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,9 +1412,6 @@ func (s *testRegionRequestToThreeStoresSuite) TestDoNotTryUnreachableLeader() {
follower, _, _, _ := region.FollowerStorePeer(regionStore, 0, &storeSelectorOp{})

s.regionRequestSender.client = &fnClient{fn: func(ctx context.Context, addr string, req *tikvrpc.Request, timeout time.Duration) (response *tikvrpc.Response, err error) {
if req.StaleRead && addr == follower.addr {
return &tikvrpc.Response{Resp: &kvrpcpb.GetResponse{RegionError: &errorpb.Error{DataIsNotReady: &errorpb.DataIsNotReady{}}}}, nil
}
return &tikvrpc.Response{Resp: &kvrpcpb.GetResponse{
Value: []byte(addr),
}}, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/locate/region_request_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func TestRegionCacheStaleRead(t *testing.T) {
leaderRegionValid: true,
leaderAsyncReload: util.Some(true),
leaderSuccessReplica: []string{"z2", "z3"},
leaderSuccessReadType: SuccessFollowerRead,
leaderSuccessReadType: SuccessStaleRead,
followerRegionValid: true,
followerAsyncReload: util.None[bool](),
followerSuccessReplica: []string{"z2"},
Expand Down
4 changes: 2 additions & 2 deletions internal/locate/replica_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ func (s *ReplicaSelectMixedStrategy) next(selector *replicaSelector) *replica {
func (s *ReplicaSelectMixedStrategy) canSendReplicaRead(selector *replicaSelector) bool {
replicas := selector.replicas
replica := replicas[s.leaderIdx]
if replica.hasFlag(deadlineErrUsingConfTimeoutFlag) || replica.hasFlag(serverIsBusyFlag) {
// don't overwhelm the leader if it is busy
if replica.attempts == 0 || replica.hasFlag(deadlineErrUsingConfTimeoutFlag) || replica.hasFlag(serverIsBusyFlag) {
// don't do the replica read if leader is not exhausted or leader has timeout or server busy error.
return false
}
return true
Expand Down
2 changes: 1 addition & 1 deletion internal/locate/replica_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,7 @@ func TestReplicaReadAccessPathByStaleReadCase(t *testing.T) {
beforeRun: func() { /* don't resetStoreState */ },
expect: &accessPathResult{
accessPath: []string{
"{addr: store3, replica-read: true, stale-read: false}",
"{addr: store3, replica-read: false, stale-read: true}",
},
respErr: "",
respRegionError: fakeEpochNotMatch,
Expand Down

0 comments on commit 9783ca6

Please sign in to comment.