Files
seaweedfs/weed/shell/command_ec_balance.go
T
Chris LuandClaude Opus 5.5 b53f6d4b5e admin: warn when more than one scheduler runs the same maintenance work (#13065)
* admin/maintenance: report whether the running manager queues a task type

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: list the EC balancers that are active at the same time

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>

* admin: log a warning while more than one EC balancer is active

The check runs on the maintenance metrics tick and logs again only when the
set of active balancers changes. The legacy maintenance entry names the
admin.toml switch that turns it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: warn on the plugin pages when more than one EC balancer is active

The scheduler status API returns the active EC balancers, and the scheduler
banner on the plugin and lane pages lists them when there are two or more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin/maintenance: count a task type only when a registered worker can run it

Only legacy maintenance workers pull tasks from the legacy queue. With plugin
workers alone, the queued ec_balance tasks never run, so they do not compete
with the plugin ec_balance job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: parse ec.balance apply flags like the flag package

A value counts only when strconv.ParseBool reads it as true, and a # token
ends the arguments, as it does for the shell command's flag parser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin/maintenance: skip legacy workers past their heartbeat timeout

A disconnected worker keeps its queue record until the cleanup loop removes
it, so the capability check also requires a heartbeat within the worker
timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: count ec.balance only when its flags parse the way the command parses them

An invalid boolean in -apply or -force fails the whole command, the last
value of a flag wins, -force overrides -apply, and parsing stops at the
first non-flag argument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell: share ec.balance's flag set and report whether its arguments apply the plan

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: count an admin_script ec.balance only when ec.balance accepts its flags

Unknown flags and invalid values of any flag fail the command before it
can move shards, so they no longer count as an active balancer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell, plugin/worker: move admin_script command tokenizing into the shell package

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: split admin_script ec.balance arguments with the executor's tokenizer

A quoted value with spaces is one argument to ec.balance, so flags after it
are still seen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell: report through one lookup whether a command's arguments change the cluster

ec.balance now also rejects an invalid -volumeIds, as its Do does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell: report whether volume.balance arguments apply its plan

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell: report whether ec.encode accepts its arguments

ec.encode has no dry run, so any accepted invocation changes the cluster.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell: report whether volume.vacuum accepts its arguments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: report overlap for every maintenance work that more than one scheduler runs

The plugin scheduler, the legacy maintenance manager, and an admin_script can
each run volume balance, EC balance, EC encoding, and vacuum. Check all four
from one table and report each work with two or more active runners, in the
log and in the scheduler-status API as maintenance_overlaps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: show each maintenance overlap on the plugin pages

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 17:46:34 -08:00

117 lines
4.2 KiB
Go

package shell
import (
"flag"
"io"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
"github.com/seaweedfs/seaweedfs/weed/storage/types"
"github.com/seaweedfs/seaweedfs/weed/util/wildcard"
)
func init() {
Commands = append(Commands, &commandEcBalance{})
}
type commandEcBalance struct {
}
func (c *commandEcBalance) Name() string {
return "ec.balance"
}
func (c *commandEcBalance) Help() string {
return `balance all ec shards among all racks and volume servers
ec.balance [-collection EACH_COLLECTION|<collection_name>] [-apply] [-dataCenter <data_center>] [-shardReplicaPlacement <replica_placement>] [-diskType <disk_type>] [-volumeIds <id>[,<id>...]]
Options:
-diskType: the disk type for EC shards (hdd, ssd, or empty for default hdd)
-volumeIds: only balance these ec volume ids, e.g. -volumeIds 123,456. The plan is
built as if no other ec volume existed, so nothing else is moved or deduplicated.
Ids without any ec shard in the selected collection, dataCenter and disk type are
an error.
Algorithm:
` + ecBalanceAlgorithmDescription
}
func (c *commandEcBalance) HasTag(CommandTag) bool {
return false
}
func (c *commandEcBalance) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
balanceCommand, f := newEcBalanceFlagSet(c.Name())
if err = balanceCommand.Parse(args); err != nil {
return err
}
handleDeprecatedForceFlag(writer, balanceCommand, f.force, f.apply)
infoAboutSimulationMode(writer, *f.apply, "-apply")
var volumeIds []needle.VolumeId
if *f.volumeIds != "" {
if volumeIds, err = parseVolumeIdsFlag(*f.volumeIds); err != nil {
return err
}
}
if err = commandEnv.confirmIsLocked(args); err != nil {
return
}
collections, err := resolveEcCollections(commandEnv, *f.collection)
if err != nil {
return err
}
glog.V(1).Infof("balanceEcVolumes collections %+v\n", len(collections))
rp, err := parseReplicaPlacementArg(commandEnv, *f.shardReplicaPlacement)
if err != nil {
return err
}
diskType := types.ToDiskType(*f.diskType)
return EcBalance(commandEnv, collections, *f.dc, rp, diskType, *f.maxParallelization, *f.ioBytePerSecond, *f.apply, nil, volumeIds)
}
type ecBalanceFlags struct {
collection, dc, shardReplicaPlacement, diskType, volumeIds *string
maxParallelization *int
ioBytePerSecond *int64
apply, force *bool
}
func newEcBalanceFlagSet(name string) (*flag.FlagSet, *ecBalanceFlags) {
fs := flag.NewFlagSet(name, flag.ContinueOnError)
return fs, &ecBalanceFlags{
collection: fs.String("collection", string(wildcard.CollectionFilterEach), "comma-separated collection names, wildcards, or regex patterns, \""+CollectionDefault+"\" for the collection with no name, or \""+string(wildcard.CollectionFilterEach)+"\" for each collection"),
dc: fs.String("dataCenter", "", "only apply the balancing for this dataCenter"),
shardReplicaPlacement: fs.String("shardReplicaPlacement", "", "replica placement for EC shards, or master default if empty"),
diskType: fs.String("diskType", "", "the disk type for EC shards (hdd, ssd, or empty for default hdd)"),
volumeIds: fs.String("volumeIds", "", "optional comma-separated list of ec volume ids to balance; defaults to all"),
maxParallelization: fs.Int("maxParallelization", DefaultMaxParallelization, "run up to X tasks in parallel, whenever possible"),
ioBytePerSecond: fs.Int64("ioBytePerSecond", 0, "limit the speed of each shard copy; 0 falls back to the volume server's maintenance rate"),
apply: fs.Bool("apply", false, "apply the balancing plan"),
force: fs.Bool("force", false, "apply the balancing plan (alias for -apply)"),
}
}
func (c *commandEcBalance) argsApply(args []string) bool {
fs, f := newEcBalanceFlagSet(c.Name())
fs.SetOutput(io.Discard)
if fs.Parse(args) != nil {
return false
}
handleDeprecatedForceFlag(io.Discard, fs, f.force, f.apply)
if *f.volumeIds != "" {
if _, err := parseVolumeIdsFlag(*f.volumeIds); err != nil {
return false
}
}
return *f.apply
}