mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-15 18:48:32 +02:00
MaintenanceConfig use ConfigField
This commit is contained in:
1 parent
4e21b3de78
commit
319aa61dab
8 files changed
+2041
-65
No files matched your search
@@ -1135,7 +1135,7 @@ func (as *AdminServer) getMaintenanceConfig() (*maintenance.MaintenanceConfigDat
|
||||
}
|
||||
|
||||
// Ensure policy is properly initialized and fix zero values with meaningful defaults
|
||||
defaultConfig := DefaultMaintenanceConfig()
|
||||
defaultConfig := maintenance.DefaultMaintenanceConfig()
|
||||
configUpdated := false
|
||||
|
||||
if config.Policy == nil {
|
||||
@@ -1144,34 +1144,42 @@ func (as *AdminServer) getMaintenanceConfig() (*maintenance.MaintenanceConfigDat
|
||||
glog.V(1).Infof("Initialized null policy with defaults")
|
||||
}
|
||||
|
||||
// Replace zero values with meaningful defaults
|
||||
if config.ScanIntervalSeconds == 0 {
|
||||
config.ScanIntervalSeconds = defaultConfig.ScanIntervalSeconds
|
||||
configUpdated = true
|
||||
}
|
||||
if config.WorkerTimeoutSeconds == 0 {
|
||||
config.WorkerTimeoutSeconds = defaultConfig.WorkerTimeoutSeconds
|
||||
configUpdated = true
|
||||
}
|
||||
if config.TaskTimeoutSeconds == 0 {
|
||||
config.TaskTimeoutSeconds = defaultConfig.TaskTimeoutSeconds
|
||||
configUpdated = true
|
||||
}
|
||||
if config.RetryDelaySeconds == 0 {
|
||||
config.RetryDelaySeconds = defaultConfig.RetryDelaySeconds
|
||||
configUpdated = true
|
||||
}
|
||||
if config.MaxRetries == 0 {
|
||||
config.MaxRetries = defaultConfig.MaxRetries
|
||||
configUpdated = true
|
||||
}
|
||||
if config.CleanupIntervalSeconds == 0 {
|
||||
config.CleanupIntervalSeconds = defaultConfig.CleanupIntervalSeconds
|
||||
configUpdated = true
|
||||
}
|
||||
if config.TaskRetentionSeconds == 0 {
|
||||
config.TaskRetentionSeconds = defaultConfig.TaskRetentionSeconds
|
||||
// Apply schema defaults for any zero values
|
||||
schema := maintenance.GetMaintenanceConfigSchema()
|
||||
if err := schema.ApplyDefaults(config); err == nil {
|
||||
configUpdated = true
|
||||
glog.V(1).Infof("Applied schema defaults to configuration")
|
||||
} else {
|
||||
glog.V(1).Infof("Schema defaults failed, using fallback: %v", err)
|
||||
// Fallback to using the default config for zero values
|
||||
if config.ScanIntervalSeconds == 0 {
|
||||
config.ScanIntervalSeconds = defaultConfig.ScanIntervalSeconds
|
||||
configUpdated = true
|
||||
}
|
||||
if config.WorkerTimeoutSeconds == 0 {
|
||||
config.WorkerTimeoutSeconds = defaultConfig.WorkerTimeoutSeconds
|
||||
configUpdated = true
|
||||
}
|
||||
if config.TaskTimeoutSeconds == 0 {
|
||||
config.TaskTimeoutSeconds = defaultConfig.TaskTimeoutSeconds
|
||||
configUpdated = true
|
||||
}
|
||||
if config.RetryDelaySeconds == 0 {
|
||||
config.RetryDelaySeconds = defaultConfig.RetryDelaySeconds
|
||||
configUpdated = true
|
||||
}
|
||||
if config.MaxRetries == 0 {
|
||||
config.MaxRetries = defaultConfig.MaxRetries
|
||||
configUpdated = true
|
||||
}
|
||||
if config.CleanupIntervalSeconds == 0 {
|
||||
config.CleanupIntervalSeconds = defaultConfig.CleanupIntervalSeconds
|
||||
configUpdated = true
|
||||
}
|
||||
if config.TaskRetentionSeconds == 0 {
|
||||
config.TaskRetentionSeconds = defaultConfig.TaskRetentionSeconds
|
||||
configUpdated = true
|
||||
}
|
||||
}
|
||||
|
||||
// Save the corrected configuration if any updates were made
|
||||
@@ -1219,34 +1227,47 @@ func (as *AdminServer) getMaintenanceConfig() (*maintenance.MaintenanceConfigDat
|
||||
|
||||
// updateMaintenanceConfig updates maintenance configuration
|
||||
func (as *AdminServer) updateMaintenanceConfig(config *maintenance.MaintenanceConfig) error {
|
||||
// Apply meaningful defaults for zero values before saving
|
||||
defaultConfig := DefaultMaintenanceConfig()
|
||||
// Apply meaningful defaults for zero values before saving using schema
|
||||
schema := maintenance.GetMaintenanceConfigSchema()
|
||||
|
||||
if config.Policy == nil {
|
||||
config.Policy = defaultConfig.Policy
|
||||
// Apply schema defaults
|
||||
if err := schema.ApplyDefaults(config); err != nil {
|
||||
glog.Errorf("Failed to apply schema defaults: %v", err)
|
||||
// Fallback to manual default application
|
||||
defaultConfig := maintenance.DefaultMaintenanceConfig()
|
||||
if config.Policy == nil {
|
||||
config.Policy = defaultConfig.Policy
|
||||
}
|
||||
if config.ScanIntervalSeconds == 0 {
|
||||
config.ScanIntervalSeconds = defaultConfig.ScanIntervalSeconds
|
||||
}
|
||||
if config.WorkerTimeoutSeconds == 0 {
|
||||
config.WorkerTimeoutSeconds = defaultConfig.WorkerTimeoutSeconds
|
||||
}
|
||||
if config.TaskTimeoutSeconds == 0 {
|
||||
config.TaskTimeoutSeconds = defaultConfig.TaskTimeoutSeconds
|
||||
}
|
||||
if config.RetryDelaySeconds == 0 {
|
||||
config.RetryDelaySeconds = defaultConfig.RetryDelaySeconds
|
||||
}
|
||||
if config.MaxRetries == 0 {
|
||||
config.MaxRetries = defaultConfig.MaxRetries
|
||||
}
|
||||
if config.CleanupIntervalSeconds == 0 {
|
||||
config.CleanupIntervalSeconds = defaultConfig.CleanupIntervalSeconds
|
||||
}
|
||||
if config.TaskRetentionSeconds == 0 {
|
||||
config.TaskRetentionSeconds = defaultConfig.TaskRetentionSeconds
|
||||
}
|
||||
}
|
||||
|
||||
// Replace zero values with meaningful defaults
|
||||
if config.ScanIntervalSeconds == 0 {
|
||||
config.ScanIntervalSeconds = defaultConfig.ScanIntervalSeconds
|
||||
}
|
||||
if config.WorkerTimeoutSeconds == 0 {
|
||||
config.WorkerTimeoutSeconds = defaultConfig.WorkerTimeoutSeconds
|
||||
}
|
||||
if config.TaskTimeoutSeconds == 0 {
|
||||
config.TaskTimeoutSeconds = defaultConfig.TaskTimeoutSeconds
|
||||
}
|
||||
if config.RetryDelaySeconds == 0 {
|
||||
config.RetryDelaySeconds = defaultConfig.RetryDelaySeconds
|
||||
}
|
||||
if config.MaxRetries == 0 {
|
||||
config.MaxRetries = defaultConfig.MaxRetries
|
||||
}
|
||||
if config.CleanupIntervalSeconds == 0 {
|
||||
config.CleanupIntervalSeconds = defaultConfig.CleanupIntervalSeconds
|
||||
}
|
||||
if config.TaskRetentionSeconds == 0 {
|
||||
config.TaskRetentionSeconds = defaultConfig.TaskRetentionSeconds
|
||||
// Validate configuration using schema
|
||||
if validationErrors := schema.ValidateConfig(config); len(validationErrors) > 0 {
|
||||
var errorMessages []string
|
||||
for _, err := range validationErrors {
|
||||
errorMessages = append(errorMessages, err.Error())
|
||||
}
|
||||
return fmt.Errorf("configuration validation failed: %v", errorMessages)
|
||||
}
|
||||
|
||||
// Save configuration to persistent storage
|
||||
|
||||
Reference in new issue
Block a user