Skip to content

Commit

Permalink
Enrich the multi replcia in one AZ case but it failed...
Browse files Browse the repository at this point in the history
Signed-off-by: MyonKeminta <[email protected]>
  • Loading branch information
MyonKeminta committed Apr 7, 2024
1 parent 8ebbe6a commit 05eec3f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/locate/replica_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ func (s *ReplicaSelectMixedStrategy) calculateScore(r *replica, isLeader bool) s
}
} else if s.tryLeader {
if len(s.labels) > 0 {
// When the leader has matching labels, prefer leader than other mismatching peers.
// When label matching is enabled, prefer selecting the leader for replicas that has same label-matching
// results.
score |= flagPreferLeader
} else {
score |= flagNormalPeer
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 @@ -1797,6 +1797,50 @@ func TestMultiReplicaInOneAZ(t *testing.T) {
},
}
s.True(s.runCaseAndCompare(ca))

s.changeRegionLeader(4)
// Prefer choosing leader for replicas with same label matching results.
for _, staleRead := range []bool{false, true} {
ca = replicaSelectorAccessPathCase{
reqType: tikvrpc.CmdGet,
readType: kv.ReplicaReadMixed,
staleRead: staleRead,
accessErr: []RegionErrorType{},
label: &metapb.StoreLabel{Key: "id", Value: "1"},
expect: &accessPathResult{
accessPath: []string{
fmt.Sprintf("{addr: store4, replica-read: %v, stale-read: %v}", !staleRead, staleRead),
},
respErr: "",
respRegionError: nil,
backoffCnt: 0,
backoffDetail: []string{},
regionIsValid: true,
},
}
s.True(s.runCaseAndCompare(ca))
}

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

func TestReplicaReadAccessPathByStaleReadCase(t *testing.T) {
Expand Down

0 comments on commit 05eec3f

Please sign in to comment.