From 3fdda127206e37e5df04760f0a26182f379675ee Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 24 Jun 2025 10:33:29 +0800 Subject: [PATCH] rename circuit breaker sysvar Signed-off-by: Ryan Leung --- pkg/domain/domain_sysvars.go | 6 +++--- pkg/sessionctx/vardef/tidb_vars.go | 8 ++++---- pkg/sessionctx/variable/sysvar.go | 14 +++++++------- pkg/sessionctx/variable/sysvar_test.go | 12 ++++++------ pkg/sessionctx/variable/tidb_vars.go | 4 ++-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pkg/domain/domain_sysvars.go b/pkg/domain/domain_sysvars.go index a2376336478f3..b03911f025ba6 100644 --- a/pkg/domain/domain_sysvars.go +++ b/pkg/domain/domain_sysvars.go @@ -47,7 +47,7 @@ func (do *Domain) initDomainSysVars() { variable.ChangeSchemaCacheSize = do.isSyncer.ChangeSchemaCacheSize - variable.ChangePDMetadataCircuitBreakerErrorRateThresholdPct = changePDMetadataCircuitBreakerErrorRateThresholdPct + variable.ChangePDMetadataCircuitBreakerErrorRateThresholdRatio = changePDMetadataCircuitBreakerErrorRateThresholdRatio } // setStatsCacheCapacity sets statsCache cap @@ -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 }) } diff --git a/pkg/sessionctx/vardef/tidb_vars.go b/pkg/sessionctx/vardef/tidb_vars.go index ce0a2b0c84ea4..db9f33b536211 100644 --- a/pkg/sessionctx/vardef/tidb_vars.go +++ b/pkg/sessionctx/vardef/tidb_vars.go @@ -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" @@ -1658,7 +1658,7 @@ const ( DefOptEnableProjectionPushDown = true DefTiDBEnableSharedLockPromotion = false DefTiDBTSOClientRPCMode = TSOClientRPCModeDefault - DefTiDBCircuitBreakerPDMetaErrorRatePct = 0.0 + DefTiDBCircuitBreakerPDMetaErrorRateRatio = 0.0 DefTiDBAccelerateUserCreationUpdate = false DefTiDBEnableTSValidation = true DefTiDBLoadBindingTimeout = 200 @@ -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 { diff --git a/pkg/sessionctx/variable/sysvar.go b/pkg/sessionctx/variable/sysvar.go index d09b8001c8ce1..2c1c0236509e6 100644 --- a/pkg/sessionctx/variable/sysvar.go +++ b/pkg/sessionctx/variable/sysvar.go @@ -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 }, diff --git a/pkg/sessionctx/variable/sysvar_test.go b/pkg/sessionctx/variable/sysvar_test.go index e5527d6c6cef4..5a4b80a116094 100644 --- a/pkg/sessionctx/variable/sysvar_test.go +++ b/pkg/sessionctx/variable/sysvar_test.go @@ -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) diff --git a/pkg/sessionctx/variable/tidb_vars.go b/pkg/sessionctx/variable/tidb_vars.go index 53e1316c0cef5..f0fc36d7a5f2f 100644 --- a/pkg/sessionctx/variable/tidb_vars.go +++ b/pkg/sessionctx/variable/tidb_vars.go @@ -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.