diff --git a/internal/locate/region_request_state_test.go b/internal/locate/region_request_state_test.go index 441cd683f..58ac94563 100644 --- a/internal/locate/region_request_state_test.go +++ b/internal/locate/region_request_state_test.go @@ -324,7 +324,7 @@ func TestRegionCacheStaleRead(t *testing.T) { leaderRegionValid: true, leaderAsyncReload: util.Some(true), leaderSuccessReplica: []string{"z2", "z3"}, - leaderSuccessReadType: SuccessStaleRead, + leaderSuccessReadType: SuccessFollowerRead, followerRegionValid: true, followerAsyncReload: util.Some(false), followerSuccessReplica: []string{"z2"}, @@ -346,7 +346,7 @@ func TestRegionCacheStaleRead(t *testing.T) { leaderRegionValid: true, leaderAsyncReload: util.Some(true), leaderSuccessReplica: []string{"z2", "z3"}, - leaderSuccessReadType: SuccessStaleRead, + leaderSuccessReadType: SuccessFollowerRead, followerRegionValid: true, followerAsyncReload: util.None[bool](), followerSuccessReplica: []string{"z2"}, @@ -434,11 +434,11 @@ func TestRegionCacheStaleRead(t *testing.T) { leaderRegionValid: true, leaderAsyncReload: util.Some(true), leaderSuccessReplica: []string{"z2", "z3"}, - leaderSuccessReadType: SuccessStaleRead, + leaderSuccessReadType: SuccessFollowerRead, followerRegionValid: true, followerAsyncReload: util.Some(true), followerSuccessReplica: []string{"z2", "z3"}, - followerSuccessReadType: SuccessStaleRead, + followerSuccessReadType: SuccessFollowerRead, }, { do: leaderDown, @@ -447,11 +447,11 @@ func TestRegionCacheStaleRead(t *testing.T) { leaderRegionValid: true, leaderAsyncReload: util.Some(true), leaderSuccessReplica: []string{"z3"}, - leaderSuccessReadType: SuccessStaleRead, + leaderSuccessReadType: SuccessFollowerRead, followerRegionValid: true, followerAsyncReload: util.Some(true), followerSuccessReplica: []string{"z3"}, - followerSuccessReadType: SuccessStaleRead, + followerSuccessReadType: SuccessFollowerRead, }, { do: leaderDown, @@ -460,11 +460,11 @@ func TestRegionCacheStaleRead(t *testing.T) { leaderRegionValid: true, leaderAsyncReload: util.Some(true), leaderSuccessReplica: []string{"z3"}, - leaderSuccessReadType: SuccessStaleRead, + leaderSuccessReadType: SuccessFollowerRead, followerRegionValid: true, followerAsyncReload: util.Some(true), followerSuccessReplica: []string{"z3"}, - followerSuccessReadType: SuccessStaleRead, + followerSuccessReadType: SuccessFollowerRead, }, } tests := []func(*testRegionCacheStaleReadSuite, *RegionCacheTestCase){ @@ -556,6 +556,8 @@ func testStaleRead(s *testRegionCacheStaleReadSuite, r *RegionCacheTestCase, zon _, successZone, successReadType := s.extractResp(resp) find := false if leaderZone { + funcName := runtime.FuncForPC(reflect.ValueOf(r.do).Pointer()).Name() + fmt.Printf("Function name of r.do(): %s\n", funcName) s.Equal(r.leaderSuccessReadType, successReadType, msg) for _, z := range r.leaderSuccessReplica { if z == successZone { diff --git a/internal/locate/replica_selector.go b/internal/locate/replica_selector.go index a086b0a65..e90a52b89 100644 --- a/internal/locate/replica_selector.go +++ b/internal/locate/replica_selector.go @@ -307,11 +307,10 @@ func (s *ReplicaSelectMixedStrategy) next(selector *replicaSelector) *replica { func (s *ReplicaSelectMixedStrategy) canSendReplicaRead(selector *replicaSelector) bool { replicas := selector.replicas replica := replicas[s.leaderIdx] - liveness := replica.store.getLivenessState() - epochStale := replica.isEpochStale() - if liveness != reachable || epochStale || replica.hasFlag(deadlineErrUsingConfTimeoutFlag) || replica.hasFlag(serverIsBusyFlag) { - // don't overwhelm the leader is busy, timeout, not accessible or stale epoch. + maxAttempt := 1 + if !replica.isExhausted(maxAttempt, 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 diff --git a/internal/locate/replica_selector_test.go b/internal/locate/replica_selector_test.go index ac7f567bf..980a4cf3a 100644 --- a/internal/locate/replica_selector_test.go +++ b/internal/locate/replica_selector_test.go @@ -898,8 +898,8 @@ func TestReplicaReadAccessPathByCase2(t *testing.T) { expect: &accessPathResult{ accessPath: []string{ "{addr: store1, replica-read: false, stale-read: true}", - "{addr: store2, replica-read: false, stale-read: true}", - "{addr: store3, replica-read: false, stale-read: true}"}, + "{addr: store2, replica-read: true, stale-read: false}", + "{addr: store3, replica-read: true, stale-read: false}"}, respErr: "", respRegionError: fakeEpochNotMatch, backoffCnt: 3, @@ -2125,7 +2125,7 @@ func TestReplicaReadAccessPathByStaleReadCase(t *testing.T) { accessPath: []string{ "{addr: store2, replica-read: false, stale-read: true}", "{addr: store1, replica-read: false, stale-read: false}", - "{addr: store3, replica-read: false, stale-read: true}", + "{addr: store3, replica-read: true, stale-read: false}", }, respErr: "", respRegionError: nil,