mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
heal: calculate the number of workers based on NRRequests (#17945)
This commit is contained in:
@@ -31,13 +31,15 @@ import (
|
||||
|
||||
// Compression environment variables
|
||||
const (
|
||||
Bitrot = "bitrotscan"
|
||||
Sleep = "max_sleep"
|
||||
IOCount = "max_io"
|
||||
Bitrot = "bitrotscan"
|
||||
Sleep = "max_sleep"
|
||||
IOCount = "max_io"
|
||||
DriveWorkers = "drive_workers"
|
||||
|
||||
EnvBitrot = "MINIO_HEAL_BITROTSCAN"
|
||||
EnvSleep = "MINIO_HEAL_MAX_SLEEP"
|
||||
EnvIOCount = "MINIO_HEAL_MAX_IO"
|
||||
EnvBitrot = "MINIO_HEAL_BITROTSCAN"
|
||||
EnvSleep = "MINIO_HEAL_MAX_SLEEP"
|
||||
EnvIOCount = "MINIO_HEAL_MAX_IO"
|
||||
EnvDriveWorkers = "MINIO_HEAL_DRIVE_WORKERS"
|
||||
)
|
||||
|
||||
var configMutex sync.RWMutex
|
||||
@@ -51,6 +53,8 @@ type Config struct {
|
||||
Sleep time.Duration `json:"sleep"`
|
||||
IOCount int `json:"iocount"`
|
||||
|
||||
DriveWorkers int `json:"drive_workers"`
|
||||
|
||||
// Cached value from Bitrot field
|
||||
cache struct {
|
||||
// -1: bitrot enabled, 0: bitrot disabled, > 0: bitrot cycle
|
||||
@@ -77,6 +81,13 @@ func (opts Config) Clone() (int, time.Duration, string) {
|
||||
return opts.IOCount, opts.Sleep, opts.Bitrot
|
||||
}
|
||||
|
||||
// GetWorkers returns the number of workers, -1 is none configured
|
||||
func (opts Config) GetWorkers() int {
|
||||
configMutex.RLock()
|
||||
defer configMutex.RUnlock()
|
||||
return opts.DriveWorkers
|
||||
}
|
||||
|
||||
// Update updates opts with nopts
|
||||
func (opts *Config) Update(nopts Config) {
|
||||
configMutex.Lock()
|
||||
@@ -85,6 +96,7 @@ func (opts *Config) Update(nopts Config) {
|
||||
opts.Bitrot = nopts.Bitrot
|
||||
opts.IOCount = nopts.IOCount
|
||||
opts.Sleep = nopts.Sleep
|
||||
opts.DriveWorkers = nopts.DriveWorkers
|
||||
|
||||
opts.cache.bitrotCycle, _ = parseBitrotConfig(nopts.Bitrot)
|
||||
}
|
||||
@@ -103,6 +115,10 @@ var DefaultKVS = config.KVS{
|
||||
Key: IOCount,
|
||||
Value: "100",
|
||||
},
|
||||
config.KV{
|
||||
Key: DriveWorkers,
|
||||
Value: "",
|
||||
},
|
||||
}
|
||||
|
||||
const minimumBitrotCycleInMonths = 1
|
||||
@@ -154,5 +170,18 @@ func LookupConfig(kvs config.KVS) (cfg Config, err error) {
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("'heal:max_io' value invalid: %w", err)
|
||||
}
|
||||
if ws := env.Get(EnvDriveWorkers, kvs.GetWithDefault(DriveWorkers, DefaultKVS)); ws != "" {
|
||||
w, err := strconv.Atoi(ws)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("'heal:drive_workers' value invalid: %w", err)
|
||||
}
|
||||
if w < 1 {
|
||||
return cfg, fmt.Errorf("'heal:drive_workers' value invalid: zero or negative integer unsupported")
|
||||
}
|
||||
cfg.DriveWorkers = w
|
||||
} else {
|
||||
cfg.DriveWorkers = -1
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
@@ -45,5 +45,11 @@ var (
|
||||
Optional: true,
|
||||
Type: "int",
|
||||
},
|
||||
config.HelpKV{
|
||||
Key: DriveWorkers,
|
||||
Description: `the number of workers per drive to heal a new disk replacement` + defaultHelpPostfix(DriveWorkers),
|
||||
Optional: true,
|
||||
Type: "int",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -37,6 +37,7 @@ type Info struct {
|
||||
Minor uint32
|
||||
Name string
|
||||
Rotational *bool
|
||||
NRRequests uint64
|
||||
}
|
||||
|
||||
// DevID is the drive major and minor ids
|
||||
|
||||
@@ -98,6 +98,7 @@ func GetInfo(path string, firstTime bool) (info Info, err error) {
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
info.NRRequests = qst.NRRequests
|
||||
rot := qst.Rotational == 1 // Rotational is '1' if the device is HDD
|
||||
info.Rotational = &rot
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user