Skip to content

Commit

Permalink
config: update config template (pingcap#5963)
Browse files Browse the repository at this point in the history
* update config template
  • Loading branch information
jackysp authored and zimulala committed Mar 7, 2018
1 parent cddc45a commit a90ee13
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ var defaultConf = Config{
Format: "text",
File: logutil.FileLogConfig{
LogRotate: true,
MaxSize: logutil.DefaultLogMaxSize,
},
SlowThreshold: 300,
ExpensiveThreshold: 10000,
Expand Down
26 changes: 13 additions & 13 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ store = "mocktikv"
path = "/tmp/tidb"

# The socket file to use for connection.
#socket = ""
socket = ""

# Socket file to write binlog.
#binlog-socket = ""
binlog-socket = ""

# Run ddl worker on this tidb-server.
run-ddl = true
Expand All @@ -29,7 +29,7 @@ lease = "10s"
split-table = true

# The limit of concurrent executed sessions.
# token-limit = 1000
token-limit = 1000

# Enable chunk executors.
enable-chunk = true
Expand All @@ -48,11 +48,11 @@ level = "info"
# Log format, one of json, text, console.
format = "text"

# Disable automatic timestamps in output
# Disable automatic timestamp in output
disable-timestamp = false

# Stores slow query log into seperate files.
#slow-query-file = ""
# Stores slow query log into separated files.
slow-query-file = ""

# Queries with execution time greater than this value will be logged. (Milliseconds)
slow-threshold = 300
Expand All @@ -68,14 +68,14 @@ query-log-max-len = 2048
# Log file name.
filename = ""

# Max log file size in MB.
#max-size = 300
# Max log file size in MB (upper limit to 4096MB).
max-size = 300

# Max log file keep days.
#max-days = 28
# Max log file keep days. No clean up by default.
max-days = 0

# Maximum number of old log files to retain.
#max-backups = 7
# Maximum number of old log files to retain. No clean up by default.
max-backups = 0

# Rotate log by day
log-rotate = true
Expand Down Expand Up @@ -130,7 +130,7 @@ join-concurrency = 5
# Whether support cartesian product.
cross-join = true

# Stats lease duration, which inflences the time of analyze and stats load.
# Stats lease duration, which influences the time of analyze and stats load.
stats-lease = "3s"

# Run auto analyze worker on this tidb-server.
Expand Down
23 changes: 18 additions & 5 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package config

import (
"os"
"path"
"runtime"
"testing"
Expand All @@ -36,10 +37,20 @@ func (s *testConfigSuite) TestConfig(c *C) {
conf.Performance.RetryLimit = 20
conf.TiKVClient.CommitTimeout = "10s"

_, filename, _, _ := runtime.Caller(0)
configFile := path.Join(path.Dir(filename), "config.toml.example")
err := conf.Load(configFile)
configFile := "config.toml"
_, localFile, _, _ := runtime.Caller(0)
configFile = path.Join(path.Dir(localFile), configFile)

f, err := os.Create(configFile)
c.Assert(err, IsNil)
_, err = f.WriteString(`[performance]
retry-limit=10
[tikv-client]
commit-timeout="41s"`)
c.Assert(err, IsNil)
c.Assert(f.Sync(), IsNil)

c.Assert(conf.Load(configFile), IsNil)

// Test that the original value will not be clear by load the config file that does not contain the option.
c.Assert(conf.BinlogSocket, Equals, "/tmp/socket")
Expand All @@ -48,9 +59,11 @@ func (s *testConfigSuite) TestConfig(c *C) {
c.Assert(conf.Performance.RetryLimit, Equals, uint(10))

c.Assert(conf.TiKVClient.CommitTimeout, Equals, "41s")
c.Assert(f.Close(), IsNil)
c.Assert(os.Remove(configFile), IsNil)

// Reset
conf.BinlogSocket = ""
configFile = path.Join(path.Dir(localFile), "config.toml.example")
c.Assert(conf.Load(configFile), IsNil)

// Make sure the example config is the same as default config.
c.Assert(conf, DeepEquals, GetGlobalConfig())
Expand Down
9 changes: 5 additions & 4 deletions util/logutil/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import (

const (
defaultLogTimeFormat = "2006/01/02 15:04:05.000"
defaultLogMaxSize = 300 // MB
defaultLogFormat = "text"
defaultLogLevel = log.InfoLevel
// DefaultLogMaxSize is the default size of log files.
DefaultLogMaxSize = 300 // MB
defaultLogFormat = "text"
defaultLogLevel = log.InfoLevel
)

// FileLogConfig serializes file log related config in toml/json.
Expand Down Expand Up @@ -222,7 +223,7 @@ func initFileLog(cfg *FileLogConfig, logger *log.Logger) error {
}
}
if cfg.MaxSize == 0 {
cfg.MaxSize = defaultLogMaxSize
cfg.MaxSize = DefaultLogMaxSize
}

// use lumberjack to logrotate
Expand Down

0 comments on commit a90ee13

Please sign in to comment.