allow protection from invalid config values (#19460)

we have had numerous reports on some config
values not having default values, causing
features misbehaving and not having default
values set properly.

This PR tries to address all these concerns
once and for all.

Each new sub-system that gets added

- must check for invalid keys
- must have default values set
- must not "return err" when being saved into
  a global state() instead collate as part of
  other subsystem errors allow other sub-systems
  to independently initialize.
This commit is contained in:
Harshavardhana
2024-04-10 18:10:30 -07:00
committed by GitHub
parent 9b926f7dbe
commit 0c31e61343
7 changed files with 118 additions and 72 deletions

View File

@@ -33,30 +33,35 @@ var DefaultKVS = config.KVS{
},
}
var configLk sync.RWMutex
// Config represents the subnet related configuration
type Config struct {
// MaxTimeout - maximum timeout for a drive operation
MaxTimeout time.Duration `json:"maxTimeout"`
mutex sync.RWMutex
}
// Update - updates the config with latest values
func (c *Config) Update(new *Config) error {
c.mutex.Lock()
defer c.mutex.Unlock()
func (c *Config) Update(new Config) error {
configLk.Lock()
defer configLk.Unlock()
c.MaxTimeout = getMaxTimeout(new.MaxTimeout)
return nil
}
// GetMaxTimeout - returns the max timeout value.
func (c *Config) GetMaxTimeout() time.Duration {
c.mutex.RLock()
defer c.mutex.RUnlock()
configLk.RLock()
defer configLk.RUnlock()
return getMaxTimeout(c.MaxTimeout)
}
// LookupConfig - lookup config and override with valid environment settings if any.
func LookupConfig(kvs config.KVS) (cfg *Config, err error) {
func LookupConfig(kvs config.KVS) (cfg Config, err error) {
cfg = Config{
MaxTimeout: 30 * time.Second,
}
if err = config.CheckValidKeys(config.DriveSubSys, kvs, DefaultKVS); err != nil {
return cfg, err
}
@@ -68,9 +73,7 @@ func LookupConfig(kvs config.KVS) (cfg *Config, err error) {
d = env.Get("_MINIO_DISK_MAX_TIMEOUT", "")
}
}
cfg = &Config{
mutex: sync.RWMutex{},
}
dur, _ := time.ParseDuration(d)
if dur < time.Second {
cfg.MaxTimeout = 30 * time.Second