mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
The plugin ec_balance job, the legacy maintenance manager's ec_balance task and an admin_script job that runs ec.balance -apply each plan shard moves from the same topology without knowing about the others. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
3.0 KiB
Go
104 lines
3.0 KiB
Go
package dash
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/admin/maintenance"
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
|
)
|
|
|
|
const (
|
|
ecBalancerPlugin = "plugin ec_balance job"
|
|
ecBalancerLegacy = "legacy maintenance ec_balance task"
|
|
ecBalancerAdminScript = "admin_script job running ec.balance -apply"
|
|
|
|
pluginECBalanceJobType = "ec_balance"
|
|
pluginAdminScriptJobType = "admin_script"
|
|
)
|
|
|
|
type ecBalancerState struct {
|
|
PluginECBalanceEnabled bool
|
|
LegacyECBalanceEnabled bool
|
|
AdminScriptEnabled bool
|
|
AdminScript string
|
|
}
|
|
|
|
func activeECBalancers(state ecBalancerState) []string {
|
|
var active []string
|
|
if state.PluginECBalanceEnabled {
|
|
active = append(active, ecBalancerPlugin)
|
|
}
|
|
if state.LegacyECBalanceEnabled {
|
|
active = append(active, ecBalancerLegacy)
|
|
}
|
|
if state.AdminScriptEnabled && scriptAppliesECBalance(state.AdminScript) {
|
|
active = append(active, ecBalancerAdminScript)
|
|
}
|
|
return active
|
|
}
|
|
|
|
func scriptAppliesECBalance(script string) bool {
|
|
for _, line := range strings.Split(strings.ReplaceAll(script, "\r\n", "\n"), "\n") {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" || strings.HasPrefix(line, "#") {
|
|
continue
|
|
}
|
|
for _, command := range strings.Split(line, ";") {
|
|
fields := strings.Fields(command)
|
|
if len(fields) == 0 || fields[0] != "ec.balance" {
|
|
continue
|
|
}
|
|
for _, arg := range fields[1:] {
|
|
name, value, hasValue := strings.Cut(strings.TrimLeft(strings.Trim(arg, "\"'"), "-"), "=")
|
|
if name != "apply" && name != "force" {
|
|
continue
|
|
}
|
|
if !hasValue || (value != "false" && value != "0") {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (s *AdminServer) collectECBalancerState() ecBalancerState {
|
|
var state ecBalancerState
|
|
if s.maintenanceManager != nil {
|
|
state.LegacyECBalanceEnabled = s.maintenanceManager.IsTaskTypeEnabled(maintenance.MaintenanceTaskType(types.TaskTypeECBalance))
|
|
}
|
|
pluginSvc := s.GetPlugin()
|
|
if pluginSvc == nil {
|
|
return state
|
|
}
|
|
states, err := pluginSvc.ListSchedulerStates()
|
|
if err != nil {
|
|
glog.V(1).Infof("ec balancer check: list scheduler states: %v", err)
|
|
return state
|
|
}
|
|
for _, jobState := range states {
|
|
switch jobState.JobType {
|
|
case pluginECBalanceJobType:
|
|
state.PluginECBalanceEnabled = jobState.Enabled
|
|
case pluginAdminScriptJobType:
|
|
state.AdminScriptEnabled = jobState.Enabled
|
|
}
|
|
}
|
|
if state.AdminScriptEnabled {
|
|
cfg, err := pluginSvc.LoadJobTypeConfig(pluginAdminScriptJobType)
|
|
if err != nil {
|
|
glog.V(1).Infof("ec balancer check: load %s config: %v", pluginAdminScriptJobType, err)
|
|
} else if cfg != nil {
|
|
state.AdminScript = cfg.GetAdminConfigValues()["script"].GetStringValue()
|
|
}
|
|
}
|
|
return state
|
|
}
|
|
|
|
// ActiveECBalancers lists the EC balancers that would move shards on their own.
|
|
// More than one entry means they plan moves from the same topology independently.
|
|
func (s *AdminServer) ActiveECBalancers() []string {
|
|
return activeECBalancers(s.collectECBalancerState())
|
|
}
|