Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#3022
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
overvenus authored and ti-chi-bot committed Oct 14, 2021
1 parent 5527e7e commit 2cfb87d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
6 changes: 3 additions & 3 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (s *serverSuite) TestLoadAndVerifyServerConfig(c *check.C) {
KeyPath: "cc",
CertAllowedCN: []string{"dd", "ee"},
},
PerTableMemoryQuota: 20 * 1024 * 1024, // 20M
PerTableMemoryQuota: 10 * 1024 * 1024, // 10M
KVClient: &config.KVClientConfig{
WorkerConcurrent: 8,
WorkerPoolSize: 0,
Expand Down Expand Up @@ -241,7 +241,7 @@ sort-dir = "/tmp/just_a_test"
SortDir: config.DefaultSortDir,
},
Security: &config.SecurityConfig{},
PerTableMemoryQuota: 20 * 1024 * 1024, // 20M
PerTableMemoryQuota: 10 * 1024 * 1024, // 10M
KVClient: &config.KVClientConfig{
WorkerConcurrent: 8,
WorkerPoolSize: 0,
Expand Down Expand Up @@ -309,7 +309,7 @@ cert-allowed-cn = ["dd","ee"]
KeyPath: "cc",
CertAllowedCN: []string{"dd", "ee"},
},
PerTableMemoryQuota: 20 * 1024 * 1024, // 20M
PerTableMemoryQuota: 10 * 1024 * 1024, // 10M
KVClient: &config.KVClientConfig{
WorkerConcurrent: 8,
WorkerPoolSize: 0,
Expand Down
13 changes: 5 additions & 8 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ var defaultServerConfig = &ServerConfig{
SortDir: DefaultSortDir,
},
Security: &SecurityConfig{},
PerTableMemoryQuota: 20 * 1024 * 1024, // 20MB
PerTableMemoryQuota: 10 * 1024 * 1024, // 10MB
KVClient: &KVClientConfig{
WorkerConcurrent: 8,
WorkerPoolSize: 0, // 0 will use NumCPU() * 2
Expand Down Expand Up @@ -301,9 +301,9 @@ func (c *ServerConfig) ValidateAndAdjust() error {
}
}

conf := GetDefaultServerConfig()
defaultCfg := GetDefaultServerConfig()
if c.Sorter == nil {
c.Sorter = conf.Sorter
c.Sorter = defaultCfg.Sorter
}
c.Sorter.SortDir = DefaultSortDir
err := c.Sorter.ValidateAndAdjust()
Expand All @@ -312,14 +312,11 @@ func (c *ServerConfig) ValidateAndAdjust() error {
}

if c.PerTableMemoryQuota == 0 {
c.PerTableMemoryQuota = conf.PerTableMemoryQuota
}
if c.PerTableMemoryQuota < 6*1024*1024 {
return cerror.ErrInvalidServerOption.GenWithStackByArgs("per-table-memory-quota should be at least 6MB")
c.PerTableMemoryQuota = defaultCfg.PerTableMemoryQuota
}

if c.KVClient == nil {
c.KVClient = conf.KVClient
c.KVClient = defaultCfg.KVClient
}
if c.KVClient.WorkerConcurrent <= 0 {
return cerror.ErrInvalidServerOption.GenWithStackByArgs("region-scan-limit should be at least 1")
Expand Down
14 changes: 14 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,19 @@ func (s *replicaConfigSuite) TestOutDated(c *check.C) {
c.Assert(conf2, check.DeepEquals, conf)
}

<<<<<<< HEAD
type serverConfigSuite struct{}

var _ = check.Suite(&serverConfigSuite{})

func (s *serverConfigSuite) TestMarshal(c *check.C) {
defer testleak.AfterTest(c)()
rawConfig := `{"addr":"192.155.22.33:8887","advertise-addr":"","log-file":"","log-level":"info","log":{"file":{"max-size":300,"max-days":0,"max-backups":0}},"data-dir":"","gc-ttl":86400,"tz":"System","capture-session-ttl":10,"owner-flush-interval":200000000,"processor-flush-interval":100000000,"sorter":{"num-concurrent-worker":4,"chunk-size-limit":999,"max-memory-percentage":30,"max-memory-consumption":17179869184,"num-workerpool-goroutine":16,"sort-dir":"/tmp/sorter"},"security":{"ca-path":"","cert-path":"","key-path":"","cert-allowed-cn":null},"per-table-memory-quota":20971520,"kv-client":{"worker-concurrent":8,"worker-pool-size":0,"region-scan-limit":6}}`
=======
func TestServerConfigMarshal(t *testing.T) {
t.Parallel()
rawConfig := `{"addr":"192.155.22.33:8887","advertise-addr":"","log-file":"","log-level":"info","log":{"file":{"max-size":300,"max-days":0,"max-backups":0}},"data-dir":"","gc-ttl":86400,"tz":"System","capture-session-ttl":10,"owner-flush-interval":200000000,"processor-flush-interval":100000000,"sorter":{"num-concurrent-worker":4,"chunk-size-limit":999,"max-memory-percentage":30,"max-memory-consumption":17179869184,"num-workerpool-goroutine":16,"sort-dir":"/tmp/sorter"},"security":{"ca-path":"","cert-path":"","key-path":"","cert-allowed-cn":null},"per-table-memory-quota":10485760,"kv-client":{"worker-concurrent":8,"worker-pool-size":0,"region-scan-limit":40}}`
>>>>>>> be1f3fe4c (config: remove per-table-memory-quota min value check (#3022))

conf := GetDefaultServerConfig()
conf.Addr = "192.155.22.33:8887"
Expand Down Expand Up @@ -129,5 +135,13 @@ func (s *serverConfigSuite) TestValidateAndAdjust(c *check.C) {
c.Assert(conf.ValidateAndAdjust(), check.ErrorMatches, ".*does not contain a port")
conf.AdvertiseAddr = "advertise:1234"
conf.PerTableMemoryQuota = 1
<<<<<<< HEAD
c.Assert(conf.ValidateAndAdjust(), check.ErrorMatches, ".*should be at least.*")
=======
require.Nil(t, conf.ValidateAndAdjust())
require.EqualValues(t, 1, conf.PerTableMemoryQuota)
conf.PerTableMemoryQuota = 0
require.Nil(t, conf.ValidateAndAdjust())
require.EqualValues(t, GetDefaultServerConfig().PerTableMemoryQuota, conf.PerTableMemoryQuota)
>>>>>>> be1f3fe4c (config: remove per-table-memory-quota min value check (#3022))
}

0 comments on commit 2cfb87d

Please sign in to comment.