Skip to content

Commit

Permalink
test(pkg/config): fix defaultServerConfig unexpected data race (#2957) (
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Oct 12, 2021
1 parent 6a3bca2 commit e7bb22c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
28 changes: 7 additions & 21 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,39 +301,25 @@ func (c *ServerConfig) ValidateAndAdjust() error {
}
}

conf := GetDefaultServerConfig()
if c.Sorter == nil {
c.Sorter = defaultServerConfig.Sorter
c.Sorter = conf.Sorter
}
c.Sorter.SortDir = DefaultSortDir

if c.Sorter.ChunkSizeLimit < 1*1024*1024 {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("chunk-size-limit should be at least 1MB")
}
if c.Sorter.NumConcurrentWorker < 1 {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("num-concurrent-worker should be at least 1")
}
if c.Sorter.NumWorkerPoolGoroutine > 4096 {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("num-workerpool-goroutine should be at most 4096")
}
if c.Sorter.NumConcurrentWorker > c.Sorter.NumWorkerPoolGoroutine {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("num-concurrent-worker larger than num-workerpool-goroutine is useless")
}
if c.Sorter.NumWorkerPoolGoroutine < 1 {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("num-workerpool-goroutine should be at least 1, larger than 8 is recommended")
}
if c.Sorter.MaxMemoryPressure < 0 || c.Sorter.MaxMemoryPressure > 100 {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("max-memory-percentage should be a percentage")
err := c.Sorter.ValidateAndAdjust()
if err != nil {
return err
}

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

if c.KVClient == nil {
c.KVClient = defaultServerConfig.KVClient
c.KVClient = conf.KVClient
}
if c.KVClient.WorkerConcurrent <= 0 {
return cerror.ErrInvalidServerOption.GenWithStackByArgs("region-scan-limit should be at least 1")
Expand Down
26 changes: 26 additions & 0 deletions pkg/config/sorter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package config

import cerror "github.com/pingcap/ticdc/pkg/errors"

// SorterConfig represents sorter config for a changefeed
type SorterConfig struct {
// number of concurrent heap sorts
Expand All @@ -28,3 +30,27 @@ type SorterConfig struct {
// the directory used to store the temporary files generated by the sorter
SortDir string `toml:"sort-dir" json:"sort-dir"`
}

// ValidateAndAdjust validates and adjusts the sorter configuration
func (c *SorterConfig) ValidateAndAdjust() error {
if c.ChunkSizeLimit < 1*1024*1024 {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("chunk-size-limit should be at least 1MB")
}
if c.NumConcurrentWorker < 1 {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("num-concurrent-worker should be at least 1")
}
if c.NumWorkerPoolGoroutine > 4096 {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("num-workerpool-goroutine should be at most 4096")
}
if c.NumConcurrentWorker > c.NumWorkerPoolGoroutine {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("num-concurrent-worker larger than num-workerpool-goroutine is useless")
}
if c.NumWorkerPoolGoroutine < 1 {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("num-workerpool-goroutine should be at least 1, larger than 8 is recommended")
}
if c.MaxMemoryPressure < 0 || c.MaxMemoryPressure > 100 {
return cerror.ErrIllegalUnifiedSorterParameter.GenWithStackByArgs("max-memory-percentage should be a percentage")
}

return nil
}

0 comments on commit e7bb22c

Please sign in to comment.