Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReplicaReadMode: introduce new replica_read mode PreferLeader. #40906

Merged
merged 18 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,6 @@ replace (
// fix potential security issue(CVE-2020-26160) introduced by indirect dependency.
github.com/dgrijalva/jwt-go => github.com/form3tech-oss/jwt-go v3.2.6-0.20210809144907-32ab6a8243d7+incompatible
github.com/pingcap/tidb/parser => ./parser
github.com/tikv/client-go/v2 => github.com/LykxSassinator/client-go/v2 v2.0.0-20230131091257-ada803e8728e
LykxSassinator marked this conversation as resolved.
Show resolved Hide resolved
go.opencensus.io => go.opencensus.io v0.23.1-0.20220331163232-052120675fac
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ github.com/Jeffail/gabs/v2 v2.5.1 h1:ANfZYjpMlfTTKebycu4X1AgkVWumFVDYQl7JwOr4mDk
github.com/Jeffail/gabs/v2 v2.5.1/go.mod h1:xCn81vdHKxFUuWWAaD5jCTQDNPBMh5pPs9IJ+NcziBI=
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
github.com/Joker/jade v1.0.1-0.20190614124447-d475f43051e7/go.mod h1:6E6s8o2AE4KhCrqr6GRJjdC/gNfTdxkIXvuGZZda2VM=
github.com/LykxSassinator/client-go/v2 v2.0.0-20230131091257-ada803e8728e h1:1XdsW0wFZo9MUKZqZggKRE39RTdAOp6OjWoLIqgUSVg=
LykxSassinator marked this conversation as resolved.
Show resolved Hide resolved
github.com/LykxSassinator/client-go/v2 v2.0.0-20230131091257-ada803e8728e/go.mod h1:jc7J2EbNeVvU6eXmB50wAGrTPyJwdi+0ENccMXMFSpw=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
Expand Down
2 changes: 2 additions & 0 deletions kv/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ const (
ReplicaReadClosestAdaptive
// ReplicaReadLearner stands for 'read from learner'.
ReplicaReadLearner
// ReplicaReadPreferLeader stands for 'read from leader and auto-turn to followers if leader is abnormal'.
ReplicaReadPreferLeader
)

// IsFollowerRead checks if follower is going to be used to read data.
Expand Down
4 changes: 3 additions & 1 deletion sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,7 @@ var defaultSysVars = []*SysVar{
s.NoopFuncsMode = TiDBOptOnOffWarn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBReplicaRead, Value: "leader", Type: TypeEnum, PossibleValues: []string{"leader", "follower", "leader-and-follower", "closest-replicas", "closest-adaptive", "learner"}, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBReplicaRead, Value: "leader", Type: TypeEnum, PossibleValues: []string{"leader", "prefer-leader", "follower", "leader-and-follower", "closest-replicas", "closest-adaptive", "learner"}, SetSession: func(s *SessionVars, val string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update the user document.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update the user document.

Yeap, thx. It's already recorded in the related prs:

if strings.EqualFold(val, "follower") {
s.SetReplicaRead(kv.ReplicaReadFollower)
} else if strings.EqualFold(val, "leader-and-follower") {
Expand All @@ -1814,6 +1814,8 @@ var defaultSysVars = []*SysVar{
s.SetReplicaRead(kv.ReplicaReadClosestAdaptive)
} else if strings.EqualFold(val, "learner") {
s.SetReplicaRead(kv.ReplicaReadLearner)
} else if strings.EqualFold(val, "prefer-leader") {
s.SetReplicaRead(kv.ReplicaReadPreferLeader)
}
return nil
}},
Expand Down
2 changes: 2 additions & 0 deletions store/driver/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func GetTiKVReplicaReadType(t kv.ReplicaReadType) storekv.ReplicaReadType {
return storekv.ReplicaReadMixed
case kv.ReplicaReadLearner:
return storekv.ReplicaReadLearner
case kv.ReplicaReadPreferLeader:
return storekv.ReplicaReadPreferLeader
}
return 0
}