mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-11 14:28:33 +01:00
buildPolicyFromTaskConfigs passed a literal nil to vacuum, erasure_coding
and balance LoadConfigFromPersistence. Those functions look for their
LoadXTaskPolicy() accessor via a type assertion, which a nil interface can
never satisfy, so every call fell through to NewDefaultConfig() and the
policy came back with the compiled-in defaults - Enabled: true among them.
A task disabled on disk was therefore still scheduled, and the only trace
was a glog.V(1) "Using default ... configuration" line.
Thread the real ConfigPersistence through instead. There are two copies of
this function: the one in weed/admin/dash builds config.Policy on the
normal admin startup path and can simply take cp as its receiver, and the
one in weed/admin/maintenance is the fallback used when the config carries
no policy yet, which now receives the store from NewMaintenanceManager.
weed/admin/dash already imports weed/admin/maintenance, so the maintenance
side has to keep the duck-typed interface{} parameter that the task
loaders already use rather than importing the concrete type back.
The store is only handed over when a data directory is configured: an
unconfigured one has nothing to read, and a typed nil pointer would pass
the loaders' type assertion and then panic on first use.
Fixes #10874
75 lines
2.7 KiB
Go
75 lines
2.7 KiB
Go
package dash
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/balance"
|
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/vacuum"
|
|
)
|
|
|
|
// TestLoadMaintenanceConfigHonoursPersistedTaskConfigs guards against the regression in
|
|
// https://github.com/seaweedfs/seaweedfs/issues/10874: buildPolicyFromTaskConfigs used to call
|
|
// LoadConfigFromPersistence(nil), which can never satisfy the loaders' type assertion, so every
|
|
// task silently fell back to its compiled-in defaults (Enabled: true) and a task disabled in the
|
|
// admin UI kept being scheduled.
|
|
func TestLoadMaintenanceConfigHonoursPersistedTaskConfigs(t *testing.T) {
|
|
dir := t.TempDir()
|
|
cp := NewConfigPersistence(dir)
|
|
|
|
// A maintenance.pb must exist, otherwise LoadMaintenanceConfig returns early with defaults.
|
|
if err := cp.SaveMaintenanceConfig(DefaultMaintenanceConfig()); err != nil {
|
|
t.Fatalf("save maintenance config: %v", err)
|
|
}
|
|
|
|
// Disable balance and vacuum the way the admin UI does, and change a value that is not a bool
|
|
// so a fallback to defaults cannot pass by coincidence.
|
|
disabledBalance := balance.NewDefaultConfig()
|
|
disabledBalance.Enabled = false
|
|
disabledBalance.MinServerCount = 7
|
|
if err := cp.SaveBalanceTaskPolicy(disabledBalance.ToTaskPolicy()); err != nil {
|
|
t.Fatalf("save balance policy: %v", err)
|
|
}
|
|
|
|
disabledVacuum := vacuum.NewDefaultConfig()
|
|
disabledVacuum.Enabled = false
|
|
if err := cp.SaveVacuumTaskPolicy(disabledVacuum.ToTaskPolicy()); err != nil {
|
|
t.Fatalf("save vacuum policy: %v", err)
|
|
}
|
|
|
|
config, err := cp.LoadMaintenanceConfig()
|
|
if err != nil {
|
|
t.Fatalf("load maintenance config: %v", err)
|
|
}
|
|
if config.Policy == nil {
|
|
t.Fatal("policy is nil, want it populated from the persisted task configs")
|
|
}
|
|
|
|
balancePolicy := config.Policy.TaskPolicies["balance"]
|
|
if balancePolicy == nil {
|
|
t.Fatal("no balance task policy in the built maintenance policy")
|
|
}
|
|
if balancePolicy.Enabled {
|
|
t.Error("balance enabled = true, want false from the persisted config")
|
|
}
|
|
if got := balancePolicy.GetBalanceConfig().GetMinServerCount(); got != 7 {
|
|
t.Errorf("balance min server count = %d, want persisted 7", got)
|
|
}
|
|
|
|
vacuumPolicy := config.Policy.TaskPolicies["vacuum"]
|
|
if vacuumPolicy == nil {
|
|
t.Fatal("no vacuum task policy in the built maintenance policy")
|
|
}
|
|
if vacuumPolicy.Enabled {
|
|
t.Error("vacuum enabled = true, want false from the persisted config")
|
|
}
|
|
|
|
// erasure_coding was never saved, so it keeps the loader's default of enabled.
|
|
ecPolicy := config.Policy.TaskPolicies["erasure_coding"]
|
|
if ecPolicy == nil {
|
|
t.Fatal("no erasure_coding task policy in the built maintenance policy")
|
|
}
|
|
if !ecPolicy.Enabled {
|
|
t.Error("erasure_coding enabled = false, want the default true for a config never saved")
|
|
}
|
|
}
|