Skip to content

Commit

Permalink
configure more circuitbreaker settings
Browse files Browse the repository at this point in the history
Signed-off-by: artem_danilov <[email protected]>
  • Loading branch information
Tema committed Jan 8, 2025
1 parent 3586031 commit 620862d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
12 changes: 6 additions & 6 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7037,13 +7037,13 @@ def go_deps():
name = "com_github_tikv_client_go_v2",
build_file_proto_mode = "disable_global",
importpath = "github.com/tikv/client-go/v2",
sha256 = "7b4e966e06ef0bb2e8677a80e323cc4bf5f838c30ff0024d1180ac8667da74a1",
strip_prefix = "github.com/Tema/client-go/[email protected]20250108010516-c325d48bed73",
sha256 = "f3d9a9003c69ae742847bf54ec92925b54968314f55f4a5de02ffab9ac22d9e5",
strip_prefix = "github.com/Tema/client-go/[email protected]20250108222013-bf5b9450dbba",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/Tema/client-go/v2/com_github_tema_client_go_v2-v2.0.0-20250108010516-c325d48bed73.zip",
"http://ats.apps.svc/gomod/github.com/Tema/client-go/v2/com_github_tema_client_go_v2-v2.0.0-20250108010516-c325d48bed73.zip",
"https://cache.hawkingrei.com/gomod/github.com/Tema/client-go/v2/com_github_tema_client_go_v2-v2.0.0-20250108010516-c325d48bed73.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/Tema/client-go/v2/com_github_tema_client_go_v2-v2.0.0-20250108010516-c325d48bed73.zip",
"http://bazel-cache.pingcap.net:8080/gomod/github.com/Tema/client-go/v2/com_github_tema_client_go_v2-v2.0.0-20250108222013-bf5b9450dbba.zip",
"http://ats.apps.svc/gomod/github.com/Tema/client-go/v2/com_github_tema_client_go_v2-v2.0.0-20250108222013-bf5b9450dbba.zip",
"https://cache.hawkingrei.com/gomod/github.com/Tema/client-go/v2/com_github_tema_client_go_v2-v2.0.0-20250108222013-bf5b9450dbba.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/Tema/client-go/v2/com_github_tema_client_go_v2-v2.0.0-20250108222013-bf5b9450dbba.zip",
],
)
go_repository(
Expand Down
1 change: 1 addition & 0 deletions cmd/tidb-server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ go_library(
"@com_github_prometheus_client_golang//prometheus/push",
"@com_github_tikv_client_go_v2//tikv",
"@com_github_tikv_client_go_v2//txnkv/transaction",
"@com_github_tikv_pd_client//pkg/circuitbreaker",
"@org_uber_go_automaxprocs//maxprocs",
"@org_uber_go_zap//:zap",
],
Expand Down
10 changes: 10 additions & 0 deletions cmd/tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import (
"github.com/prometheus/client_golang/prometheus/push"
"github.com/tikv/client-go/v2/tikv"
"github.com/tikv/client-go/v2/txnkv/transaction"
"github.com/tikv/pd/client/pkg/circuitbreaker"
"go.uber.org/automaxprocs/maxprocs"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -803,6 +804,15 @@ func setGlobalVars() {

atomic.StoreUint64(&transaction.CommitMaxBackoff, uint64(parseDuration(cfg.TiKVClient.CommitTimeout).Seconds()*1000))
tikv.SetRegionCacheTTLSec(int64(cfg.TiKVClient.RegionCacheTTL))
tikv.ChangePdRegionMetaCircuitBreakerSettings(func(config *circuitbreaker.Settings) {
s := cfg.TiKVClient.CircuitBreakerSettingsList.PDRegionsMetadata
// config.ErrorRateThreshold is controlled by tidb_cb_pd_metadata_error_rate_threshold_pct sysvar
config.ErrorRateWindow = time.Duration(s.ErrorRateEvaluationWindowSeconds) * time.Second
config.MinQPSForOpen = uint32(s.MinQPSToOpen)
config.CoolDownInterval = time.Duration(s.CooldownIntervalSeconds) * time.Second
config.HalfOpenSuccessCount = uint32(s.HalfOpenSuccessCount)
})

domainutil.RepairInfo.SetRepairMode(cfg.RepairMode)
domainutil.RepairInfo.SetRepairTableList(cfg.RepairTableList)
executor.GlobalDiskUsageTracker.SetBytesLimit(cfg.TempStorageQuota)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,4 @@ replace (
)

// pending https://github.com/tikv/client-go/pull/1543
replace github.com/tikv/client-go/v2 => github.com/Tema/client-go/v2 v2.0.0-20250108010516-c325d48bed73
replace github.com/tikv/client-go/v2 => github.com/Tema/client-go/v2 v2.0.0-20250108222013-bf5b9450dbba
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8=
github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk=
github.com/Tema/client-go/v2 v2.0.0-20250107045051-7dde728bc5e5 h1:+dH38cGhjLOJfUyrIFXZ7sObUB0JZ243jVoMLlFGR0I=
github.com/Tema/client-go/v2 v2.0.0-20250107045051-7dde728bc5e5/go.mod h1:YMP2WbENjh0V0PaNY9LPRh7bLto2MmmuRE0zJ7IAZIA=
github.com/Tema/client-go/v2 v2.0.0-20250108010516-c325d48bed73 h1:2IBYnKqJ5FZwHQUkJCUYTGD9fjP+lTkJz8ewJfSSw4E=
github.com/Tema/client-go/v2 v2.0.0-20250108010516-c325d48bed73/go.mod h1:YMP2WbENjh0V0PaNY9LPRh7bLto2MmmuRE0zJ7IAZIA=
github.com/Tema/client-go/v2 v2.0.0-20250108222013-bf5b9450dbba h1:oauAWSHrQ8MXti2pURWk5Naq+iPjATHGUfvk6JmvORo=
github.com/Tema/client-go/v2 v2.0.0-20250108222013-bf5b9450dbba/go.mod h1:YMP2WbENjh0V0PaNY9LPRh7bLto2MmmuRE0zJ7IAZIA=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,11 @@ grpc-keepalive-timeout = 0.2
[tikv-client.async-commit]
keys-limit=123
total-key-size-limit=1024
[tikv-client.circuit-breaker.pd-region-metadata]
error-rate-evaluation-window-seconds = 50
min-qps-to-open=15
cooldown-interval-seconds=25
half-open-success-count=5
[experimental]
allow-expression-index = true
[isolation-read]
Expand Down Expand Up @@ -784,6 +789,11 @@ max_connections = 200
require.Equal(t, uint64(1024), conf.TiKVClient.AsyncCommit.TotalKeySizeLimit)
require.Equal(t, uint(128), conf.TiKVClient.MaxBatchSize)
require.Equal(t, uint(6000), conf.TiKVClient.RegionCacheTTL)
cbSettings := conf.TiKVClient.CircuitBreakerSettingsList.PDRegionsMetadata
require.Equal(t, uint(50), cbSettings.ErrorRateEvaluationWindowSeconds)
require.Equal(t, uint(15), cbSettings.MinQPSToOpen)
require.Equal(t, uint(25), cbSettings.CooldownIntervalSeconds)
require.Equal(t, uint(5), cbSettings.HalfOpenSuccessCount)
require.Equal(t, int64(0), conf.TiKVClient.StoreLimit)
require.Equal(t, int64(8192), conf.TiKVClient.TTLRefreshedTxnSize)
require.Equal(t, time.Millisecond*200, conf.TiKVClient.GetGrpcKeepAliveTimeout())
Expand Down

0 comments on commit 620862d

Please sign in to comment.