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 26, 2024
1 parent e72c4cd commit add7453
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ 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 has labels, some followers's labels may not match, then can't be candidate, need to try follower.
if state.isStaleRead || leader.deadlineErrUsingConfTimeout || len(state.option.labels) > 0 {
selector.state = &tryFollower{
leaderIdx: state.leaderIdx,
lastIdx: state.leaderIdx,
Expand Down
23 changes: 22 additions & 1 deletion internal/locate/replica_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type accessPathResult struct {
regionIsValid bool
}

func TestReplicaReadStaleReadAccessPathByCase(t *testing.T) {
func TestReplicaReadAccessPathByCase(t *testing.T) {
s := new(testReplicaSelectorSuite)
s.SetupTest(t)
defer s.TearDownTest()
Expand Down Expand Up @@ -282,6 +282,27 @@ func TestReplicaReadStaleReadAccessPathByCase(t *testing.T) {
},
}
s.True(s.runCaseAndCompare(ca))

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: 1,
backoffDetail: []string{"tikvServerBusy+1"},
regionIsValid: true,
},
}
s.True(s.runCaseAndCompare(ca))
}
func (s *testReplicaSelectorSuite) runCaseAndCompare(ca2 replicaSelectorAccessPathCase) bool {
ca2.run(s)
Expand Down

0 comments on commit add7453

Please sign in to comment.