mirror of https://github.com/tikv/client-go.git
enable replica-selector-v2 by default (#1229)
* refine replica selector v2 config Signed-off-by: crazycs520 <crazycs520@gmail.com> * add comment Signed-off-by: crazycs520 <crazycs520@gmail.com> --------- Signed-off-by: crazycs520 <crazycs520@gmail.com>
This commit is contained in:
parent
5b6625f167
commit
0606e74e8e
|
|
@ -93,6 +93,9 @@ type TiKVClient struct {
|
||||||
// MaxConcurrencyRequestLimit is the max concurrency number of request to be sent the tikv
|
// MaxConcurrencyRequestLimit is the max concurrency number of request to be sent the tikv
|
||||||
// 0 means auto adjust by feedback.
|
// 0 means auto adjust by feedback.
|
||||||
MaxConcurrencyRequestLimit int64 `toml:"max-concurrency-request-limit" json:"max-concurrency-request-limit"`
|
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.
|
// AsyncCommit is the config for the async commit feature. The switch to enable it is a system variable.
|
||||||
|
|
@ -164,6 +167,7 @@ func DefaultTiKVClient() TiKVClient {
|
||||||
|
|
||||||
ResolveLockLiteThreshold: 16,
|
ResolveLockLiteThreshold: 16,
|
||||||
MaxConcurrencyRequestLimit: math.MaxInt64,
|
MaxConcurrencyRequestLimit: math.MaxInt64,
|
||||||
|
EnableReplicaSelectorV2: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,8 +82,6 @@ type Config struct {
|
||||||
RegionsRefreshInterval uint64
|
RegionsRefreshInterval uint64
|
||||||
// EnablePreload indicates whether to preload region info when initializing the client.
|
// EnablePreload indicates whether to preload region info when initializing the client.
|
||||||
EnablePreload bool
|
EnablePreload bool
|
||||||
// EnableReplicaSelectorV2 indicates whether to enable ReplicaSelectorV2.
|
|
||||||
EnableReplicaSelectorV2 bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultConfig returns the default configuration.
|
// DefaultConfig returns the default configuration.
|
||||||
|
|
@ -101,7 +99,6 @@ func DefaultConfig() Config {
|
||||||
TxnScope: "",
|
TxnScope: "",
|
||||||
EnableAsyncCommit: false,
|
EnableAsyncCommit: false,
|
||||||
Enable1PC: false,
|
Enable1PC: false,
|
||||||
EnableReplicaSelectorV2: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ type ReplicaSelector interface {
|
||||||
func NewReplicaSelector(
|
func NewReplicaSelector(
|
||||||
regionCache *RegionCache, regionID RegionVerID, req *tikvrpc.Request, opts ...StoreSelectorOption,
|
regionCache *RegionCache, regionID RegionVerID, req *tikvrpc.Request, opts ...StoreSelectorOption,
|
||||||
) (ReplicaSelector, error) {
|
) (ReplicaSelector, error) {
|
||||||
if config.GetGlobalConfig().EnableReplicaSelectorV2 {
|
if config.GetGlobalConfig().TiKVClient.EnableReplicaSelectorV2 {
|
||||||
return newReplicaSelectorV2(regionCache, regionID, req, opts...)
|
return newReplicaSelectorV2(regionCache, regionID, req, opts...)
|
||||||
}
|
}
|
||||||
return newReplicaSelector(regionCache, regionID, req, opts...)
|
return newReplicaSelector(regionCache, regionID, req, opts...)
|
||||||
|
|
|
||||||
|
|
@ -2604,13 +2604,13 @@ func (s *testReplicaSelectorSuite) changeRegionLeader(storeId uint64) {
|
||||||
func (s *testReplicaSelectorSuite) runCaseAndCompare(ca1 replicaSelectorAccessPathCase) bool {
|
func (s *testReplicaSelectorSuite) runCaseAndCompare(ca1 replicaSelectorAccessPathCase) bool {
|
||||||
ca2 := ca1
|
ca2 := ca1
|
||||||
config.UpdateGlobal(func(conf *config.Config) {
|
config.UpdateGlobal(func(conf *config.Config) {
|
||||||
conf.EnableReplicaSelectorV2 = false
|
conf.TiKVClient.EnableReplicaSelectorV2 = false
|
||||||
})
|
})
|
||||||
sender := ca1.run(s)
|
sender := ca1.run(s)
|
||||||
ca1.checkResult(s, "v1", sender)
|
ca1.checkResult(s, "v1", sender)
|
||||||
|
|
||||||
config.UpdateGlobal(func(conf *config.Config) {
|
config.UpdateGlobal(func(conf *config.Config) {
|
||||||
conf.EnableReplicaSelectorV2 = true
|
conf.TiKVClient.EnableReplicaSelectorV2 = true
|
||||||
})
|
})
|
||||||
sender = ca2.run(s)
|
sender = ca2.run(s)
|
||||||
if ca2.expect == nil {
|
if ca2.expect == nil {
|
||||||
|
|
@ -2623,7 +2623,7 @@ func (s *testReplicaSelectorSuite) runCaseAndCompare(ca1 replicaSelectorAccessPa
|
||||||
|
|
||||||
func (s *testReplicaSelectorSuite) runCase(ca replicaSelectorAccessPathCase, v2 bool) bool {
|
func (s *testReplicaSelectorSuite) runCase(ca replicaSelectorAccessPathCase, v2 bool) bool {
|
||||||
config.UpdateGlobal(func(conf *config.Config) {
|
config.UpdateGlobal(func(conf *config.Config) {
|
||||||
conf.EnableReplicaSelectorV2 = v2
|
conf.TiKVClient.EnableReplicaSelectorV2 = v2
|
||||||
})
|
})
|
||||||
sender := ca.run(s)
|
sender := ca.run(s)
|
||||||
version := "v1"
|
version := "v1"
|
||||||
|
|
@ -2638,7 +2638,7 @@ func (s *testReplicaSelectorSuite) runMultiCaseAndCompare(cas []replicaSelectorA
|
||||||
expects := make([]accessPathResult, 0, len(cas))
|
expects := make([]accessPathResult, 0, len(cas))
|
||||||
valid := true
|
valid := true
|
||||||
config.UpdateGlobal(func(conf *config.Config) {
|
config.UpdateGlobal(func(conf *config.Config) {
|
||||||
conf.EnableReplicaSelectorV2 = false
|
conf.TiKVClient.EnableReplicaSelectorV2 = false
|
||||||
})
|
})
|
||||||
for _, ca1 := range cas {
|
for _, ca1 := range cas {
|
||||||
sender := ca1.run(s)
|
sender := ca1.run(s)
|
||||||
|
|
@ -2648,7 +2648,7 @@ func (s *testReplicaSelectorSuite) runMultiCaseAndCompare(cas []replicaSelectorA
|
||||||
}
|
}
|
||||||
|
|
||||||
config.UpdateGlobal(func(conf *config.Config) {
|
config.UpdateGlobal(func(conf *config.Config) {
|
||||||
conf.EnableReplicaSelectorV2 = true
|
conf.TiKVClient.EnableReplicaSelectorV2 = true
|
||||||
})
|
})
|
||||||
for i, ca2 := range cas {
|
for i, ca2 := range cas {
|
||||||
sender := ca2.run(s)
|
sender := ca2.run(s)
|
||||||
|
|
@ -3227,7 +3227,7 @@ func BenchmarkReplicaSelector(b *testing.B) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
config.UpdateGlobal(func(conf *config.Config) {
|
config.UpdateGlobal(func(conf *config.Config) {
|
||||||
conf.EnableReplicaSelectorV2 = true
|
conf.TiKVClient.EnableReplicaSelectorV2 = true
|
||||||
})
|
})
|
||||||
cnt := 0
|
cnt := 0
|
||||||
allErrs := getAllRegionErrors(nil)
|
allErrs := getAllRegionErrors(nil)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue