mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-07 00:27:03 +00:00
ensure correct default value
This commit is contained in:
@@ -1134,6 +1134,55 @@ func (as *AdminServer) getMaintenanceConfig() (*maintenance.MaintenanceConfigDat
|
||||
config = DefaultMaintenanceConfig()
|
||||
}
|
||||
|
||||
// Ensure policy is properly initialized and fix zero values with meaningful defaults
|
||||
defaultConfig := DefaultMaintenanceConfig()
|
||||
configUpdated := false
|
||||
|
||||
if config.Policy == nil {
|
||||
config.Policy = defaultConfig.Policy
|
||||
configUpdated = true
|
||||
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
|
||||
configUpdated = true
|
||||
}
|
||||
|
||||
// Save the corrected configuration if any updates were made
|
||||
if configUpdated {
|
||||
if saveErr := as.configPersistence.SaveMaintenanceConfig(config); saveErr != nil {
|
||||
glog.Errorf("Failed to save corrected configuration: %v", saveErr)
|
||||
} else {
|
||||
glog.V(1).Infof("Updated configuration with meaningful defaults and saved to persistent storage")
|
||||
}
|
||||
}
|
||||
|
||||
// Get system stats from maintenance manager if available
|
||||
var systemStats *MaintenanceStats
|
||||
if as.maintenanceManager != nil {
|
||||
@@ -1170,6 +1219,36 @@ 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()
|
||||
|
||||
if config.Policy == nil {
|
||||
config.Policy = defaultConfig.Policy
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// Save configuration to persistent storage
|
||||
if err := as.configPersistence.SaveMaintenanceConfig(config); err != nil {
|
||||
return fmt.Errorf("failed to save maintenance configuration: %w", err)
|
||||
|
||||
@@ -137,9 +137,10 @@ func (mp *MaintenancePolicy) GetTaskPolicy(taskType MaintenanceTaskType) *TaskPo
|
||||
|
||||
policy, exists := mp.TaskPolicies[taskType]
|
||||
if !exists {
|
||||
// Create generic default policy using global settings - no hardcoded fallbacks
|
||||
// Create default policy - enabled by default for registered task types
|
||||
// This provides a better user experience where available tasks are enabled by default
|
||||
policy = &TaskPolicy{
|
||||
Enabled: false, // Conservative default - require explicit enabling
|
||||
Enabled: true, // Default to enabled for registered task types
|
||||
MaxConcurrent: 1, // Conservative default concurrency
|
||||
RepeatInterval: mp.DefaultRepeatInterval, // Use configured default, 0 if not set
|
||||
CheckInterval: mp.DefaultCheckInterval, // Use configured default, 0 if not set
|
||||
|
||||
@@ -150,7 +150,7 @@ templ MaintenanceConfig(data *maintenance.MaintenanceConfigData) {
|
||||
<i class={menuItem.Icon + " me-2"}></i>
|
||||
{menuItem.DisplayName}
|
||||
</h6>
|
||||
if data.Config.Policy.IsTaskEnabled(menuItem.TaskType) {
|
||||
if menuItem.IsEnabled {
|
||||
<span class="badge bg-success">Enabled</span>
|
||||
} else {
|
||||
<span class="badge bg-secondary">Disabled</span>
|
||||
@@ -250,26 +250,6 @@ templ MaintenanceConfig(data *maintenance.MaintenanceConfigData) {
|
||||
});
|
||||
}
|
||||
|
||||
fetch('/api/maintenance/config', {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(config)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert('Configuration saved successfully');
|
||||
} else {
|
||||
alert('Failed to save configuration: ' + (data.error || 'Unknown error'));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert('Error: ' + error.message);
|
||||
});
|
||||
}
|
||||
|
||||
function resetToDefaults() {
|
||||
if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {
|
||||
// Reset form to defaults (matching DefaultMaintenanceConfig values)
|
||||
|
||||
@@ -192,7 +192,7 @@ func MaintenanceConfig(data *maintenance.MaintenanceConfigData) templ.Component
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if data.Config.Policy.IsTaskEnabled(menuItem.TaskType) {
|
||||
if menuItem.IsEnabled {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "<span class=\"badge bg-success\">Enabled</span>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
@@ -273,7 +273,7 @@ func MaintenanceConfig(data *maintenance.MaintenanceConfigData) templ.Component
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</p></div></div></div></div></div></div></div></div><script>\n function saveConfiguration() {\n const config = {\n enabled: document.getElementById('enabled').checked,\n scan_interval_seconds: parseInt(document.getElementById('scanInterval').value) * 60, // Convert to seconds\n worker_timeout_seconds: parseInt(document.getElementById('workerTimeout').value) * 60, // Convert to seconds\n task_timeout_seconds: parseInt(document.getElementById('taskTimeout').value) * 3600, // Convert to seconds\n retry_delay_seconds: parseInt(document.getElementById('retryDelay').value) * 60, // Convert to seconds\n max_retries: parseInt(document.getElementById('maxRetries').value),\n task_retention_seconds: parseInt(document.getElementById('taskRetention').value) * 24 * 3600, // Convert to seconds\n policy: {\n global_max_concurrent: parseInt(document.getElementById('globalMaxConcurrent').value)\n }\n };\n\n fetch('/api/maintenance/config', {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(config)\n })\n .then(response => response.json())\n .then(data => {\n if (data.success) {\n alert('Configuration saved successfully');\n } else {\n alert('Failed to save configuration: ' + (data.error || 'Unknown error'));\n }\n })\n .catch(error => {\n alert('Error: ' + error.message);\n });\n }\n\n function resetToDefaults() {\n if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {\n // Reset form to defaults (matching DefaultMaintenanceConfig values)\n document.getElementById('enabled').checked = false;\n document.getElementById('scanInterval').value = '30';\n document.getElementById('workerTimeout').value = '5';\n document.getElementById('taskTimeout').value = '2';\n document.getElementById('globalMaxConcurrent').value = '4';\n document.getElementById('maxRetries').value = '3';\n document.getElementById('retryDelay').value = '15';\n document.getElementById('taskRetention').value = '7';\n }\n }\n </script>")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</p></div></div></div></div></div></div></div></div><script>\n function saveConfiguration() {\n // First, get current configuration to preserve existing values\n fetch('/api/maintenance/config')\n .then(response => response.json())\n .then(currentConfig => {\n // Update only the fields from the form\n const updatedConfig = {\n ...currentConfig.config, // Preserve existing config\n enabled: document.getElementById('enabled').checked,\n scan_interval_seconds: parseInt(document.getElementById('scanInterval').value) * 60, // Convert to seconds\n worker_timeout_seconds: parseInt(document.getElementById('workerTimeout').value) * 60, // Convert to seconds\n task_timeout_seconds: parseInt(document.getElementById('taskTimeout').value) * 3600, // Convert to seconds\n retry_delay_seconds: parseInt(document.getElementById('retryDelay').value) * 60, // Convert to seconds\n max_retries: parseInt(document.getElementById('maxRetries').value),\n task_retention_seconds: parseInt(document.getElementById('taskRetention').value) * 24 * 3600, // Convert to seconds\n policy: {\n ...currentConfig.config.policy, // Preserve existing policy\n global_max_concurrent: parseInt(document.getElementById('globalMaxConcurrent').value)\n }\n };\n\n // Send the updated configuration\n return fetch('/api/maintenance/config', {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(updatedConfig)\n });\n })\n .then(response => response.json())\n .then(data => {\n if (data.success) {\n alert('Configuration saved successfully');\n location.reload(); // Reload to show updated values\n } else {\n alert('Failed to save configuration: ' + (data.error || 'Unknown error'));\n }\n })\n .catch(error => {\n alert('Error: ' + error.message);\n });\n }\n\n function resetToDefaults() {\n if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {\n // Reset form to defaults (matching DefaultMaintenanceConfig values)\n document.getElementById('enabled').checked = false;\n document.getElementById('scanInterval').value = '30';\n document.getElementById('workerTimeout').value = '5';\n document.getElementById('taskTimeout').value = '2';\n document.getElementById('globalMaxConcurrent').value = '4';\n document.getElementById('maxRetries').value = '3';\n document.getElementById('retryDelay').value = '15';\n document.getElementById('taskRetention').value = '7';\n }\n }\n </script>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user