From 92cecd8aa8259c77c7953690dfb1ad63e2102055 Mon Sep 17 00:00:00 2001 From: bb7133 Date: Thu, 4 Jun 2026 14:34:34 -0700 Subject: [PATCH 1/4] config: support log timeout action --- go.mod | 2 +- go.sum | 2 ++ pkg/config/config.go | 15 ++++++++++++++- pkg/config/config_test.go | 28 ++++++++++++++++++++++++++-- pkg/extension/enterprise | 2 +- 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 061e04170275d..559cfd49ab386 100644 --- a/go.mod +++ b/go.mod @@ -102,7 +102,7 @@ require ( github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 github.com/pingcap/fn v1.0.0 github.com/pingcap/kvproto v0.0.0-20260601035955-b2b3bb492278 - github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9 + github.com/pingcap/log v1.1.1-0.20260604211921-80a4a2dc3943 github.com/pingcap/metering_sdk v0.0.0-20260324055927-14fead745f1d github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5 github.com/pingcap/tidb/pkg/parser v0.0.0-20211011031125-9b13dc409c5e diff --git a/go.sum b/go.sum index 4519978492ae0..09c442e5518d1 100644 --- a/go.sum +++ b/go.sum @@ -734,6 +734,8 @@ github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuR github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9 h1:qG9BSvlWFEE5otQGamuWedx9LRm0nrHvsQRQiW8SxEs= github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9/go.mod h1:ORfBOFp1eteu2odzsyaxI+b8TzJwgjwyQcGhI+9SfEA= +github.com/pingcap/log v1.1.1-0.20260604211921-80a4a2dc3943 h1:Gdg+HJrHOg4suytbZUrR0vITtGOgufme94srbScI3hk= +github.com/pingcap/log v1.1.1-0.20260604211921-80a4a2dc3943/go.mod h1:pxfz2oJfAuhwrb3/rcLqD//GS/5gRP4gD022iP3cEO0= github.com/pingcap/metering_sdk v0.0.0-20260324055927-14fead745f1d h1:5JCgncG9X7tOsqKqbIXpV2VG4mu/hv3RvvZewqFj0U4= github.com/pingcap/metering_sdk v0.0.0-20260324055927-14fead745f1d/go.mod h1:HMNxmg0/lrn3SPGJ6LTZqP0WwEpcXMu9s/4TWJbzT8w= github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5 h1:T4pXRhBflzDeAhmOQHNPRRogMYxP13V7BkYw3ZsoSfE= diff --git a/pkg/config/config.go b/pkg/config/config.go index a9dff133d3ebf..d5690712dfe51 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -627,8 +627,11 @@ type Log struct { SlowThreshold uint64 `toml:"slow-threshold" json:"slow-threshold"` RecordPlanInSlowLog uint32 `toml:"record-plan-in-slow-log" json:"record-plan-in-slow-log"` - // Make tidb panic if write log operation hang in `Timeout` seconds + // Timeout is the maximum seconds allowed for a log write/sync operation. Timeout int `toml:"timeout" json:"timeout"` + // TimeoutAction controls the action when log write/sync timeout occurs. + // Valid values: panic, discard. + TimeoutAction string `toml:"timeout-action" json:"timeout-action"` } // Instance is the section of instance scope system variables. @@ -1133,6 +1136,7 @@ var defaultConf = Config{ QueryLogMaxLen: logutil.DefaultQueryLogMaxLen, RecordPlanInSlowLog: logutil.DefaultRecordPlanInSlowLog, EnableSlowLog: *NewAtomicBool(logutil.DefaultTiDBEnableSlowLog), + TimeoutAction: zaplog.LogTimeoutActionPanic, }, Instance: Instance{ TiDBGeneralLog: false, @@ -1647,6 +1651,14 @@ func (c *Config) Valid() error { if c.Log.File.MaxSize > MaxLogFileSize { return fmt.Errorf("invalid max log file size=%v which is larger than max=%v", c.Log.File.MaxSize, MaxLogFileSize) } + switch strings.ToLower(c.Log.TimeoutAction) { + case "", zaplog.LogTimeoutActionPanic: + c.Log.TimeoutAction = zaplog.LogTimeoutActionPanic + case zaplog.LogTimeoutActionDiscard: + c.Log.TimeoutAction = zaplog.LogTimeoutActionDiscard + default: + return fmt.Errorf("log.timeout-action should be one of [%s, %s]", zaplog.LogTimeoutActionPanic, zaplog.LogTimeoutActionDiscard) + } if c.TableColumnCountLimit < DefTableColumnCountLimit || c.TableColumnCountLimit > DefMaxOfTableColumnCountLimit { return fmt.Errorf("table-column-limit should be [%d, %d]", DefIndexLimit, DefMaxOfTableColumnCountLimit) } @@ -1762,6 +1774,7 @@ func (l *Log) ToLogConfig() *logutil.LogConfig { return logutil.NewLogConfig(l.Level, l.Format, l.SlowQueryFile, l.GeneralLogFile, l.File, l.getDisableTimestamp(), func(config *zaplog.Config) { config.DisableErrorVerbose = l.getDisableErrorStack() }, func(config *zaplog.Config) { config.Timeout = l.Timeout }, + func(config *zaplog.Config) { config.TimeoutAction = l.TimeoutAction }, ) } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index c3499f2bdfecb..0c64ba415b081 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -129,7 +129,10 @@ func TestLogConfig(t *testing.T) { require.Equal(t, expectedDisableErrorStack, conf.Log.DisableErrorStack) require.Equal(t, expectedEnableTimestamp, conf.Log.EnableTimestamp) require.Equal(t, expectedDisableTimestamp, conf.Log.DisableTimestamp) - require.Equal(t, logutil.NewLogConfig("info", "text", "tidb-slow.log", "", conf.Log.File, resultedDisableTimestamp, func(config *zaplog.Config) { config.DisableErrorVerbose = resultedDisableErrorVerbose }), conf.Log.ToLogConfig()) + require.Equal(t, logutil.NewLogConfig("info", "text", "tidb-slow.log", "", conf.Log.File, resultedDisableTimestamp, + func(config *zaplog.Config) { config.DisableErrorVerbose = resultedDisableErrorVerbose }, + func(config *zaplog.Config) { config.TimeoutAction = conf.Log.TimeoutAction }, + ), conf.Log.ToLogConfig()) err := f.Truncate(0) require.NoError(t, err) _, err = f.Seek(0, 0) @@ -170,6 +173,24 @@ disable-error-stack = false `, nbFalse, nbUnset, nbUnset, nbUnset, false, true) } +func TestLogTimeoutAction(t *testing.T) { + conf := NewConfig() + require.Equal(t, zaplog.LogTimeoutActionPanic, conf.Log.TimeoutAction) + require.NoError(t, conf.Valid()) + require.Equal(t, zaplog.LogTimeoutActionPanic, conf.Log.ToLogConfig().TimeoutAction) + + conf.Log.TimeoutAction = zaplog.LogTimeoutActionDiscard + require.NoError(t, conf.Valid()) + require.Equal(t, zaplog.LogTimeoutActionDiscard, conf.Log.ToLogConfig().TimeoutAction) + + conf.Log.TimeoutAction = "DISCARD" + require.NoError(t, conf.Valid()) + require.Equal(t, zaplog.LogTimeoutActionDiscard, conf.Log.TimeoutAction) + + conf.Log.TimeoutAction = "invalid" + require.EqualError(t, conf.Valid(), "log.timeout-action should be one of [panic, discard]") +} + func TestKeyspaceObservability(t *testing.T) { conf := NewConfig() content := ` @@ -1131,7 +1152,10 @@ grpc-keepalive-timeout = 0.01 require.Equal(t, GetGlobalConfig(), conf) // Test for log config. - require.Equal(t, logutil.NewLogConfig("info", "text", "tidb-slow.log", "", conf.Log.File, false, func(config *zaplog.Config) { config.DisableErrorVerbose = conf.Log.getDisableErrorStack() }), conf.Log.ToLogConfig()) + require.Equal(t, logutil.NewLogConfig("info", "text", "tidb-slow.log", "", conf.Log.File, false, + func(config *zaplog.Config) { config.DisableErrorVerbose = conf.Log.getDisableErrorStack() }, + func(config *zaplog.Config) { config.TimeoutAction = conf.Log.TimeoutAction }, + ), conf.Log.ToLogConfig()) // Test for tracing config. tracingConf := &tracing.Configuration{ diff --git a/pkg/extension/enterprise b/pkg/extension/enterprise index dc633aae52eb1..462aeb27bc86d 160000 --- a/pkg/extension/enterprise +++ b/pkg/extension/enterprise @@ -1 +1 @@ -Subproject commit dc633aae52eb11b4e3549e3a7ef5b0ed14e159b1 +Subproject commit 462aeb27bc86d7e7cb6220270ce3cfaa1969808b From 9df59301eb1136e5fcee8e51b346553e155c6dbf Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Thu, 4 Jun 2026 21:41:49 +0000 Subject: [PATCH 2/4] chore: update bazel file --- DEPS.bzl | 8 ++++---- pkg/config/BUILD.bazel | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DEPS.bzl b/DEPS.bzl index 43869c2a416dc..a16ebb115a75a 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -5539,11 +5539,11 @@ def go_deps(): name = "com_github_pingcap_log", build_file_proto_mode = "disable_global", importpath = "github.com/pingcap/log", - sha256 = "50df543d8d2d5f5f24f6ec5926855f074714a958f1f58e7fe50920c7e4d5fe5d", - strip_prefix = "github.com/pingcap/log@v1.1.1-0.20250917021125-19901e015dc9", + sha256 = "1a358a72b0e696b2e74bb74c08a51f36035fbe5721a9a1b5a3cc1e7c11493710", + strip_prefix = "github.com/pingcap/log@v1.1.1-0.20260604211921-80a4a2dc3943", urls = [ - "https://cache.hawkingrei.com/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250917021125-19901e015dc9.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250917021125-19901e015dc9.zip", + "https://cache.hawkingrei.com/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20260604211921-80a4a2dc3943.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20260604211921-80a4a2dc3943.zip", ], ) go_repository( diff --git a/pkg/config/BUILD.bazel b/pkg/config/BUILD.bazel index 283cbccd8a282..76214492475e7 100644 --- a/pkg/config/BUILD.bazel +++ b/pkg/config/BUILD.bazel @@ -44,7 +44,7 @@ go_test( data = glob(["**"]), embed = [":config"], flaky = True, - shard_count = 35, + shard_count = 36, deps = [ "//pkg/config/deploymode", "//pkg/config/kerneltype", From 690e1efd8dd6bda420ba455ce4f585aac9612a60 Mon Sep 17 00:00:00 2001 From: bb7133 Date: Thu, 4 Jun 2026 20:49:20 -0700 Subject: [PATCH 3/4] config: update go module metadata for log timeout action --- go.mod | 2 +- go.sum | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 559cfd49ab386..f3a4b64bc95a8 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect google.golang.org/protobuf v1.36.10 gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.2.1 gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apimachinery v0.29.11 // indirect k8s.io/klog/v2 v2.120.1 // indirect diff --git a/go.sum b/go.sum index 09c442e5518d1..ec03c9618eeba 100644 --- a/go.sum +++ b/go.sum @@ -732,8 +732,6 @@ github.com/pingcap/kvproto v0.0.0-20260601035955-b2b3bb492278 h1:VV03wSSG2XhOwhF github.com/pingcap/kvproto v0.0.0-20260601035955-b2b3bb492278/go.mod h1:z6+aAHB7dBkA+LyinEX+48/ImRJ3jag0Hg0c7wkhEvE= github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM= github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= -github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9 h1:qG9BSvlWFEE5otQGamuWedx9LRm0nrHvsQRQiW8SxEs= -github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9/go.mod h1:ORfBOFp1eteu2odzsyaxI+b8TzJwgjwyQcGhI+9SfEA= github.com/pingcap/log v1.1.1-0.20260604211921-80a4a2dc3943 h1:Gdg+HJrHOg4suytbZUrR0vITtGOgufme94srbScI3hk= github.com/pingcap/log v1.1.1-0.20260604211921-80a4a2dc3943/go.mod h1:pxfz2oJfAuhwrb3/rcLqD//GS/5gRP4gD022iP3cEO0= github.com/pingcap/metering_sdk v0.0.0-20260324055927-14fead745f1d h1:5JCgncG9X7tOsqKqbIXpV2VG4mu/hv3RvvZewqFj0U4= From ad61f32730e1e54d7012dfa26b0e2dbb667c594f Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Sun, 14 Jun 2026 00:30:04 +0000 Subject: [PATCH 4/4] chore: update bazel file --- pkg/config/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/BUILD.bazel b/pkg/config/BUILD.bazel index 3013a056ce6c1..6f844447517d5 100644 --- a/pkg/config/BUILD.bazel +++ b/pkg/config/BUILD.bazel @@ -45,7 +45,7 @@ go_test( data = glob(["**"]), embed = [":config"], flaky = True, - shard_count = 37, + shard_count = 38, deps = [ "//pkg/config/deploymode", "//pkg/config/kerneltype",