diff --git a/DEPS.bzl b/DEPS.bzl index b55b770038061..acd4c74969dde 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/go.mod b/go.mod index cd2f5ed44731b..017ef7115e6c3 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-20260602101655-f8184e7702eb - 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 @@ -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 2d711399ad7ab..f94448e1840e2 100644 --- a/go.sum +++ b/go.sum @@ -732,8 +732,8 @@ github.com/pingcap/kvproto v0.0.0-20260602101655-f8184e7702eb h1:Ms0a58PRX1y6iqG github.com/pingcap/kvproto v0.0.0-20260602101655-f8184e7702eb/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= 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/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", diff --git a/pkg/config/config.go b/pkg/config/config.go index a51b83797637b..c13c3b3eca8dc 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -643,8 +643,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. @@ -1152,6 +1155,7 @@ var defaultConf = Config{ QueryLogMaxLen: logutil.DefaultQueryLogMaxLen, RecordPlanInSlowLog: logutil.DefaultRecordPlanInSlowLog, EnableSlowLog: *NewAtomicBool(logutil.DefaultTiDBEnableSlowLog), + TimeoutAction: zaplog.LogTimeoutActionPanic, }, Instance: Instance{ TiDBGeneralLog: false, @@ -1736,6 +1740,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) } @@ -1851,6 +1863,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 6dc546f87a68b..87d8120fc2ffe 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 TestErrorMessageExtensionConfig(t *testing.T) { configFile := filepath.Join(t.TempDir(), "config.toml") require.NoError(t, os.WriteFile(configFile, []byte(` @@ -1220,7 +1241,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