Skip to content

Commit

Permalink
replica-read request with mixed strategy and with label, should be ab…
Browse files Browse the repository at this point in the history
…le to retry all remain replicas

Signed-off-by: crazycs520 <[email protected]>
  • Loading branch information
crazycs520 committed Feb 23, 2024
1 parent 2d31d6f commit 6721d36
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ func (state *accessFollower) next(bo *retry.Backoffer, selector *replicaSelector
// If the leader is also unavailable, we can fallback to the follower and use replica-read flag again,
// The remote follower not tried yet, and the local follower can retry without stale-read flag.
// If leader tried and received deadline exceeded error, try follower.
if state.isStaleRead || leader.deadlineErrUsingConfTimeout {
if state.isStaleRead || leader.deadlineErrUsingConfTimeout || len(state.option.labels) > 0 {
selector.state = &tryFollower{
leaderIdx: state.leaderIdx,
lastIdx: state.leaderIdx,
Expand Down
44 changes: 44 additions & 0 deletions internal/locate/replica_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,50 @@ func TestReplicaReadAccessPathByCase(t *testing.T) {
}
s.True(s.runCaseAndCompare(ca))
s.changeRegionLeader(1)

ca = replicaSelectorAccessPathCase{
reqType: tikvrpc.CmdGet,
readType: kv.ReplicaReadMixed,
staleRead: false,
timeout: time.Second,
label: &metapb.StoreLabel{Key: "id", Value: "2"},
accessErr: []RegionErrorType{DeadLineExceededErr, ServerIsBusyErr},
expect: &accessPathResult{
accessPath: []string{
"{addr: store2, replica-read: true, stale-read: false}",
"{addr: store1, replica-read: true, stale-read: false}",
"{addr: store3, replica-read: true, stale-read: false}"},
respErr: "",
respRegionError: nil,
backoffCnt: 0,
backoffDetail: []string{},
regionIsValid: true,
},
}
s.True(s.runCaseAndCompare(ca))

s.changeRegionLeader(2)
ca = replicaSelectorAccessPathCase{
reqType: tikvrpc.CmdGet,
readType: kv.ReplicaReadMixed,
staleRead: false,
timeout: time.Second,
label: &metapb.StoreLabel{Key: "id", Value: "3"},
accessErr: []RegionErrorType{DeadLineExceededErr, ServerIsBusyErr},
expect: &accessPathResult{
accessPath: []string{
"{addr: store3, replica-read: true, stale-read: false}",
"{addr: store2, replica-read: true, stale-read: false}",
"{addr: store1, replica-read: true, stale-read: false}"},
respErr: "",
respRegionError: nil,
backoffCnt: 0,
backoffDetail: []string{},
regionIsValid: true,
},
}
s.True(s.runCaseAndCompare(ca))
s.changeRegionLeader(1)
}

func (s *testReplicaSelectorSuite) changeRegionLeader(storeId uint64) {
Expand Down

0 comments on commit 6721d36

Please sign in to comment.