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

enable replica-selector-v2 by default #1229

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ type TiKVClient struct {
// MaxConcurrencyRequestLimit is the max concurrency number of request to be sent the tikv
// 0 means auto adjust by feedback.
MaxConcurrencyRequestLimit int64 `toml:"max-concurrency-request-limit" json:"max-concurrency-request-limit"`
// EnableReplicaSelectorV2 indicate whether to use the new replica-selector-v2.
// TODO(crazycs520): remove this config after the new replica-selector-v2 is stable.
EnableReplicaSelectorV2 bool `toml:"enable-replica-selector-v2" json:"enable-replica-selector-v2"`
}

// AsyncCommit is the config for the async commit feature. The switch to enable it is a system variable.
Expand Down Expand Up @@ -164,6 +167,7 @@ func DefaultTiKVClient() TiKVClient {

ResolveLockLiteThreshold: 16,
MaxConcurrencyRequestLimit: math.MaxInt64,
EnableReplicaSelectorV2: true,
}
}

Expand Down
27 changes: 12 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,23 @@ type Config struct {
RegionsRefreshInterval uint64
// EnablePreload indicates whether to preload region info when initializing the client.
EnablePreload bool
// EnableReplicaSelectorV2 indicates whether to enable ReplicaSelectorV2.
EnableReplicaSelectorV2 bool
}

// DefaultConfig returns the default configuration.
func DefaultConfig() Config {
return Config{
CommitterConcurrency: 128,
MaxTxnTTL: 60 * 60 * 1000, // 1hour
TiKVClient: DefaultTiKVClient(),
PDClient: DefaultPDClient(),
TxnLocalLatches: DefaultTxnLocalLatches(),
StoresRefreshInterval: DefStoresRefreshInterval,
OpenTracingEnable: false,
Path: "",
EnableForwarding: false,
TxnScope: "",
EnableAsyncCommit: false,
Enable1PC: false,
EnableReplicaSelectorV2: true,
CommitterConcurrency: 128,
MaxTxnTTL: 60 * 60 * 1000, // 1hour
TiKVClient: DefaultTiKVClient(),
PDClient: DefaultPDClient(),
TxnLocalLatches: DefaultTxnLocalLatches(),
StoresRefreshInterval: DefStoresRefreshInterval,
OpenTracingEnable: false,
Path: "",
EnableForwarding: false,
TxnScope: "",
EnableAsyncCommit: false,
Enable1PC: false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/locate/replica_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type ReplicaSelector interface {
func NewReplicaSelector(
regionCache *RegionCache, regionID RegionVerID, req *tikvrpc.Request, opts ...StoreSelectorOption,
) (ReplicaSelector, error) {
if config.GetGlobalConfig().EnableReplicaSelectorV2 {
if config.GetGlobalConfig().TiKVClient.EnableReplicaSelectorV2 {
return newReplicaSelectorV2(regionCache, regionID, req, opts...)
}
return newReplicaSelector(regionCache, regionID, req, opts...)
Expand Down
12 changes: 6 additions & 6 deletions internal/locate/replica_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2604,13 +2604,13 @@ func (s *testReplicaSelectorSuite) changeRegionLeader(storeId uint64) {
func (s *testReplicaSelectorSuite) runCaseAndCompare(ca1 replicaSelectorAccessPathCase) bool {
ca2 := ca1
config.UpdateGlobal(func(conf *config.Config) {
conf.EnableReplicaSelectorV2 = false
conf.TiKVClient.EnableReplicaSelectorV2 = false
})
sender := ca1.run(s)
ca1.checkResult(s, "v1", sender)

config.UpdateGlobal(func(conf *config.Config) {
conf.EnableReplicaSelectorV2 = true
conf.TiKVClient.EnableReplicaSelectorV2 = true
})
sender = ca2.run(s)
if ca2.expect == nil {
Expand All @@ -2623,7 +2623,7 @@ func (s *testReplicaSelectorSuite) runCaseAndCompare(ca1 replicaSelectorAccessPa

func (s *testReplicaSelectorSuite) runCase(ca replicaSelectorAccessPathCase, v2 bool) bool {
config.UpdateGlobal(func(conf *config.Config) {
conf.EnableReplicaSelectorV2 = v2
conf.TiKVClient.EnableReplicaSelectorV2 = v2
})
sender := ca.run(s)
version := "v1"
Expand All @@ -2638,7 +2638,7 @@ func (s *testReplicaSelectorSuite) runMultiCaseAndCompare(cas []replicaSelectorA
expects := make([]accessPathResult, 0, len(cas))
valid := true
config.UpdateGlobal(func(conf *config.Config) {
conf.EnableReplicaSelectorV2 = false
conf.TiKVClient.EnableReplicaSelectorV2 = false
})
for _, ca1 := range cas {
sender := ca1.run(s)
Expand All @@ -2648,7 +2648,7 @@ func (s *testReplicaSelectorSuite) runMultiCaseAndCompare(cas []replicaSelectorA
}

config.UpdateGlobal(func(conf *config.Config) {
conf.EnableReplicaSelectorV2 = true
conf.TiKVClient.EnableReplicaSelectorV2 = true
})
for i, ca2 := range cas {
sender := ca2.run(s)
Expand Down Expand Up @@ -3227,7 +3227,7 @@ func BenchmarkReplicaSelector(b *testing.B) {
}()

config.UpdateGlobal(func(conf *config.Config) {
conf.EnableReplicaSelectorV2 = true
conf.TiKVClient.EnableReplicaSelectorV2 = true
})
cnt := 0
allErrs := getAllRegionErrors(nil)
Expand Down
Loading