Skip to content
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
6 changes: 3 additions & 3 deletions pkg/domain/domain_sysvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (do *Domain) initDomainSysVars() {

variable.ChangeSchemaCacheSize = do.isSyncer.ChangeSchemaCacheSize

variable.ChangePDMetadataCircuitBreakerErrorRateThresholdPct = changePDMetadataCircuitBreakerErrorRateThresholdPct
variable.ChangePDMetadataCircuitBreakerErrorRateThresholdRatio = changePDMetadataCircuitBreakerErrorRateThresholdRatio
}

// setStatsCacheCapacity sets statsCache cap
Expand Down Expand Up @@ -149,8 +149,8 @@ func (do *Domain) getExternalTimestamp(ctx context.Context) (uint64, error) {
return do.store.GetOracle().GetExternalTimestamp(ctx)
}

func changePDMetadataCircuitBreakerErrorRateThresholdPct(errorRatePct uint32) {
func changePDMetadataCircuitBreakerErrorRateThresholdRatio(errorRateRatio uint32) {
tikv.ChangePDRegionMetaCircuitBreakerSettings(func(config *circuitbreaker.Settings) {
config.ErrorRateThresholdPct = errorRatePct
config.ErrorRateThresholdPct = errorRateRatio
})
}
8 changes: 4 additions & 4 deletions pkg/sessionctx/vardef/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -1258,9 +1258,9 @@ const (
// TiDBTSOClientRPCMode controls how the TSO client performs the TSO RPC requests. It internally controls the
// concurrency of the RPC. This variable provides an approach to tune the latency of getting timestamps from PD.
TiDBTSOClientRPCMode = "tidb_tso_client_rpc_mode"
// TiDBCircuitBreakerPDMetadataErrorRateThresholdPct variable is used to set percent of errors to trip the circuit breaker for get region calls to PD
// TiDBCircuitBreakerPDMetadataErrorRateThresholdRatio variable is used to set ratio of errors to trip the circuit breaker for get region calls to PD
// https://github.com/tikv/rfcs/blob/master/text/0115-circuit-breaker.md
TiDBCircuitBreakerPDMetadataErrorRateThresholdPct = "tidb_cb_pd_metadata_error_rate_threshold_pct"
TiDBCircuitBreakerPDMetadataErrorRateThresholdRatio = "tidb_cb_pd_metadata_error_rate_threshold_ratio"

// TiDBEnableTSValidation controls whether to enable the timestamp validation in client-go.
TiDBEnableTSValidation = "tidb_enable_ts_validation"
Expand Down Expand Up @@ -1658,7 +1658,7 @@ const (
DefOptEnableProjectionPushDown = true
DefTiDBEnableSharedLockPromotion = false
DefTiDBTSOClientRPCMode = TSOClientRPCModeDefault
DefTiDBCircuitBreakerPDMetaErrorRatePct = 0.0
DefTiDBCircuitBreakerPDMetaErrorRateRatio = 0.0
DefTiDBAccelerateUserCreationUpdate = false
DefTiDBEnableTSValidation = true
DefTiDBLoadBindingTimeout = 200
Expand Down Expand Up @@ -1790,7 +1790,7 @@ var (
SchemaCacheSizeOriginText = atomic.NewString(strconv.Itoa(DefTiDBSchemaCacheSize))
AccelerateUserCreationUpdate = atomic.NewBool(DefTiDBAccelerateUserCreationUpdate)

CircuitBreakerPDMetadataErrorRateThresholdPct = atomic.NewFloat64(0.0)
CircuitBreakerPDMetadataErrorRateThresholdRatio = atomic.NewFloat64(0.0)
)

func serverMemoryLimitDefaultValue() string {
Expand Down
14 changes: 7 additions & 7 deletions pkg/sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -3563,19 +3563,19 @@ var defaultSysVars = []*SysVar{
return (*SetPDClientDynamicOption.Load())(vardef.TiDBTSOClientRPCMode, val)
},
},
{Scope: vardef.ScopeGlobal, Name: vardef.TiDBCircuitBreakerPDMetadataErrorRateThresholdPct, Value: strconv.FormatFloat(vardef.DefTiDBCircuitBreakerPDMetaErrorRatePct, 'f', -1, 64),
{Scope: vardef.ScopeGlobal, Name: vardef.TiDBCircuitBreakerPDMetadataErrorRateThresholdRatio, Value: strconv.FormatFloat(vardef.DefTiDBCircuitBreakerPDMetaErrorRateRatio, 'f', -1, 64),
Type: vardef.TypeFloat, MinValue: 0, MaxValue: 1,
GetGlobal: func(_ context.Context, s *SessionVars) (string, error) {
return strconv.FormatFloat(vardef.CircuitBreakerPDMetadataErrorRateThresholdPct.Load(), 'f', -1, 64), nil
return strconv.FormatFloat(vardef.CircuitBreakerPDMetadataErrorRateThresholdRatio.Load(), 'f', -1, 64), nil
},
SetGlobal: func(_ context.Context, s *SessionVars, val string) error {
v := tidbOptFloat64(val, vardef.DefTiDBCircuitBreakerPDMetaErrorRatePct)
v := tidbOptFloat64(val, vardef.DefTiDBCircuitBreakerPDMetaErrorRateRatio)
if v < 0 || v > 1 {
return errors.Errorf("invalid tidb_cb_pd_metadata_error_rate_threshold_pct value %s", val)
return errors.Errorf("invalid tidb_cb_pd_metadata_error_rate_threshold_ratio value %s", val)
}
vardef.CircuitBreakerPDMetadataErrorRateThresholdPct.Store(v)
if ChangePDMetadataCircuitBreakerErrorRateThresholdPct != nil {
ChangePDMetadataCircuitBreakerErrorRateThresholdPct(uint32(v * 100))
vardef.CircuitBreakerPDMetadataErrorRateThresholdRatio.Store(v)
if ChangePDMetadataCircuitBreakerErrorRateThresholdRatio != nil {
ChangePDMetadataCircuitBreakerErrorRateThresholdRatio(uint32(v * 100))
}
return nil
},
Expand Down
12 changes: 6 additions & 6 deletions pkg/sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1761,23 +1761,23 @@ func TestTiDBSchemaCacheSize(t *testing.T) {
require.Error(t, err)
}

func TestTiDBCircuitBreakerPDMetadataErrorRateThresholdPct(t *testing.T) {
sv := GetSysVar(vardef.TiDBCircuitBreakerPDMetadataErrorRateThresholdPct)
func TestTiDBCircuitBreakerPDMetadataErrorRateThresholdRatio(t *testing.T) {
sv := GetSysVar(vardef.TiDBCircuitBreakerPDMetadataErrorRateThresholdRatio)
vars := NewSessionVars(nil)

// Too low, will get raised to the min value
val, err := sv.Validate(vars, "-1", vardef.ScopeGlobal)
require.NoError(t, err)
require.Equal(t, strconv.FormatInt(GetSysVar(vardef.TiDBCircuitBreakerPDMetadataErrorRateThresholdPct).MinValue, 10), val)
require.Equal(t, strconv.FormatInt(GetSysVar(vardef.TiDBCircuitBreakerPDMetadataErrorRateThresholdRatio).MinValue, 10), val)
warn := vars.StmtCtx.GetWarnings()[0].Err
require.Equal(t, "[variable:1292]Truncated incorrect tidb_cb_pd_metadata_error_rate_threshold_pct value: '-1'", warn.Error())
require.Equal(t, "[variable:1292]Truncated incorrect tidb_cb_pd_metadata_error_rate_threshold_ratio value: '-1'", warn.Error())

// Too high, will get lowered to the max value
val, err = sv.Validate(vars, "1.1", vardef.ScopeGlobal)
require.NoError(t, err)
require.Equal(t, strconv.FormatUint(GetSysVar(vardef.TiDBCircuitBreakerPDMetadataErrorRateThresholdPct).MaxValue, 10), val)
require.Equal(t, strconv.FormatUint(GetSysVar(vardef.TiDBCircuitBreakerPDMetadataErrorRateThresholdRatio).MaxValue, 10), val)
warn = vars.StmtCtx.GetWarnings()[1].Err
require.Equal(t, "[variable:1292]Truncated incorrect tidb_cb_pd_metadata_error_rate_threshold_pct value: '1.1'", warn.Error())
require.Equal(t, "[variable:1292]Truncated incorrect tidb_cb_pd_metadata_error_rate_threshold_ratio value: '1.1'", warn.Error())

// valid
val, err = sv.Validate(vars, "0.9", vardef.ScopeGlobal)
Expand Down
4 changes: 2 additions & 2 deletions pkg/sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ var (
EnableStatsOwner func() error = nil
// DisableStatsOwner is the func registered by stats to disable running stats in this instance.
DisableStatsOwner func() error = nil
// ChangePDMetadataCircuitBreakerErrorRateThresholdPct changes the error rate threshold of the PD metadata circuit breaker.
ChangePDMetadataCircuitBreakerErrorRateThresholdPct func(uint32) = nil
// ChangePDMetadataCircuitBreakerErrorRateThresholdRatio changes the error rate threshold of the PD metadata circuit breaker.
ChangePDMetadataCircuitBreakerErrorRateThresholdRatio func(uint32) = nil
)

// Hooks functions for Cluster Resource Control.
Expand Down