Commit Graph
20 Commits
Author SHA1 Message Date
6a67fe503e vacuum: compact copies held read-only by a readonlyCanDelete mark (#13283)
* vacuum: compact copies held read-only by a readonlyCanDelete mark

A volume marked with volume.mark -readonlyCanDelete takes no new writes
but keeps taking deletes, so it can drain instead of holding a volume
slot (#10688). The automatic vacuum never reclaims those deletes: it
skips every read-only copy unless low disk space is the only cause, and
a mark clears that exception (#11519). The space comes back only once
the last needle is deleted (deleteEmpty) or through volume.vacuum
-volumeId, one volume at a time, so a volume that never drains
completely keeps its garbage.

VacuumVolumeCheck now also reports can_delete_mark: the copy is
read-only through a readonlyCanDelete mark and nothing that refuses
deletes (no plain read-only mark, no I/O quarantine, not tiered to
remote storage). The sweep compacts such a copy like a writable one,
except when the master pushed the mark itself to quarantine a duplicate
volume id. The mark survives the compaction, so the copy stays
read-only, keeps taking deletes and stays out of the writables. A
read-only volume reserves no headroom, so the space it gives back
becomes free volume slots.

The Rust volume server reports the same field. In volume.vacuum, the
help text and the list of read-only volumes the sweep skips leave out
copies that still take deletes. For the unnamed collection, which the
shell vacuums volume by volume, such volumes are left to the sweep: an
explicit request would also compact a quarantined copy.

An older volume server does not set the field and an older master
ignores it, so a mixed cluster keeps skipping these copies.

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

* shell: say which marked volumes volume.vacuum leaves to the sweep

For the unnamed collection, volume.vacuum sends one request per volume
and skips a volume held by a readonlyCanDelete mark, while the "skipped
by the sweep" hint leaves such volumes out because the sweep compacts
them. With a filter matching only those volumes, the command returned
without a request and without a word. It now lists the marked volumes
over the threshold that it leaves to the automatic sweep.

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

* storage: drop the compacted needle map a read-only commit leaves unused

CommitCompact reloads a read-only volume into a sorted map, so the
compacted map built for the reload is never consumed: it stays in
v.tmpNm with every needle of the volume, and with a leveldb index its
.cpldb stays on disk. The next compaction reopens that .cpldb as is, so
needles deleted between the two compactions come back in the leveldb
map with stale offsets once the volume is writable again, and reads of
them fail with EOF instead of not found.

The sweep now compacts readonlyCanDelete volumes, so this path is no
longer limited to an explicit volume.vacuum -volumeId.

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

* storage: do not tie the canDelete compaction test to random needle sizes

newRandomNeedle sizes its data at random, so three deleted needles out
of six left under 30% garbage about once in twenty runs and failed the
precondition. The test only needs the deletes to leave some garbage.

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

* shell: say the sweep skips quarantined copies in the left-to-sweep note

The note named unnamed-collection volumes as left to the automatic
sweep, but the sweep skips a copy the master holds for a duplicate
volume id under the same mark, and the topology does not show that
quarantine. The note now says so. It also describes the copies by what
the topology shows, read-only but still taking deletes, since a copy
read-only only for low disk space looks the same when its probe fails.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
2026-12-02 04:23:39 -08:00
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
1167ca8cf5 vacuum: report a request dropped because another vacuum is running (#12648)
* vacuum: report a request dropped because another vacuum is running

The master runs one vacuum at a time. A request that arrives while
another one is running, the automatic vacuum or an earlier request, is
dropped: Topology.Vacuum logs "Vacuum is already running" and returns.
The VacuumVolume RPC and /vol/vacuum then answered as if the vacuum had
run, so volume.vacuum printed nothing and exited 0 with no volume
compacted. Where the automatic vacuum is busy for hours, an explicit
volume.vacuum -volumeId could do nothing every time, and nothing said so.

Topology.Vacuum now returns ErrVacuumRunning for a dropped request. The
RPC returns it and /vol/vacuum answers 409 with it. volume.vacuum names
the request that failed, because a list of volumes or collections is
sent as several requests and a vacuum that starts in between fails only
the later ones. Requests are still dropped, not queued, and the
automatic vacuum ignores the error as before.

The integration tests that need their /vol/vacuum request to run ask
again while the master answers 409.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* docs: note the 409 answer from /vol/vacuum while another vacuum runs

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

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
2026-11-14 11:07:44 -08:00
bac2196d65 shell: return flag parse errors from every command (#12618)
* shell: return flag parse errors from every command

48 commands returned nil when their flags failed to parse, so a mistyped
flag printed the flag error but the command still counted as a success:
a piped weed shell run exited 0, the master maintenance loop logged no
error, and admin script jobs reported the line as done.

Return the parse error as s3.bucket.create (#12544) and the other shell
commands already do. TestCommandsReturnFlagParseErrors runs every
registered command with an unknown flag and fails for the 48 on master.

Signed-off-by: anant <170962632+antcybersec@users.noreply.github.com>

* shell: don't report -h as a failure

With the parse errors returned, -h on those commands now returns
flag.ErrHelp, so the shell printed "error: flag: help requested" and a
piped run exited 1. The flag package has already printed the usage, so
processEachCmd now treats flag.ErrHelp as success for every command.

Signed-off-by: anant <170962632+antcybersec@users.noreply.github.com>

* shell: keep the -h test beside the flag parse test

TestProcessEachCmdTreatsHelpAsSuccess covers the same change as
TestCommandsReturnFlagParseErrors, so it lives in the same new file and
shell_liner_test.go stays as it was.

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

---------

Signed-off-by: anant <170962632+antcybersec@users.noreply.github.com>
Co-authored-by: anant <170962632+antcybersec@users.noreply.github.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 12:19:44 -08:00
Chris Lu b0ab4c4e1e shell: make every -collection flag parse the same way (#11794)
* shell: make every -collection flag parse the same way

The filter vocabulary (comma-separated names, wildcards, regexes,
"_default" for the empty-named collection) already existed in
wildcard.CompileCollectionMatcher, but several commands still did their
own exact-match comparison or sent the raw flag value to servers.

fs.mergeVolumes used a literal string compare, so -collection=_default
silently produced an empty merge plan; it now uses the shared matcher
while keeping "*" as the match-all default. volume.fsck and volume.mark
filter through the matcher too, and volume.vacuum resolves the filter
client-side into per-collection and per-volume requests, since no
Collection value scopes the VacuumVolume RPC to the unnamed collection
alone.

Commands that put one concrete collection name on the wire normalize
"_default" to "" (volume.grow, fs.configure, mq.topic.compact,
collection.delete, ec.rebuild, ec.balance), and the tier -volumeId
commands resolve the volume's actual collection from topology first so
patterns and named-collection requests pass the volume server's
collection check.

* shell: spell the default-collection keyword via CollectionDefault

* shell: address review findings on collection filter handling

volume.fsck keeps a set of every volume the master knows before any
filtering, so a filer entry whose volume was excluded by -collection or
-volumeId is skipped instead of reported "volume not found" and deleted
by -reallyDeleteFilerEntries. The collection filter also no longer
scopes the filer walk to /buckets/<collection>: fs.configure can bind a
collection to any path prefix, and a narrower walk could mark live
chunks as orphans under -reallyDeleteFromVolume.

ec.rebuild and ec.balance resolve -collection through the new
wildcard.ExpandCollectionFilter, which passes literal names through even
when the master does not list them — ec.rebuild must be able to recover
a collection whose shards all lost their index and never registered.

fs.configure and mq.topic.compact now reject _default outright: an empty
Collection means "unset" in both the path-rule merge and the filer's
storage-option fallback chain, so the keyword would have been silently
ignored.

The unnamed-collection vacuum sweep keeps the master's low-disk-space
exception: a volume whose every replica is read-only is probed with
VacuumVolumeCheck and stays eligible when a replica reports
DiskSpaceLow, instead of being dropped outright.
2026-10-16 21:07:51 -07:00
ihnokim d3cd061c22 shell: say which read-only volumes volume.vacuum leaves alone (#11525)
* shell: say which read-only volumes volume.vacuum leaves alone

volume.vacuum without -volumeId runs the same sweep as the automatic
vacuum, which skips read-only volumes, and the master's response carries
no result. An operator whose disk filled up runs the command, sees it
return, and watches nothing change (issue #11516).

Before issuing the request, list the read-only volumes whose garbage is at
or above the threshold and point at -volumeId, which is the explicit path
PR #9861 opened for them. The help text says the same.

* shell: volume.vacuum hint survives a failed listing and looks at every replica

Review follow-ups: a failed topology listing no longer stops a sweep
without -volumeId, it only drops the hint; a volume counts as read-only
when any replica is, with the garbage ratio taken from the replica that
reports the most, which is what the sweep itself does; a converted index
that reports deletes without sizes is listed rather than hidden; and the
threshold is printed as given instead of rounded to two decimals.

* shell: do not guess a garbage ratio for a converted index

The master cannot compute one for a volume that reports deletes without
their sizes, and a guess of 1 would send the operator to -volumeId for a
volume the server may decline at that threshold. Leave it out and say so.
2026-10-01 01:08:48 +08:00
Chris Lu 902a12fd6f wdclient: bound the wait for a master leader by the caller's context (#11002)
* wdclient: bound the wait for a master leader by the caller's context

WithClient waited on GetMaster with context.Background(), so a caller that
arrived while no master leader was known parked in a 200ms poll loop until one
appeared, whatever deadline it had already set on the RPC. Each retry above it
then left another goroutine in the same wait.

Take the context in WithClient and WithClientCustomGetMaster and hand it to
GetMaster, and stop the retry loop once it is done. The dial keeps
context.Background(): fn brings its own RPC context, so a cancellation seen
here cannot be attributed to the shared connection.

Call sites pass whatever they hold: the request context in the filer's
CollectionList, DeleteCollection and Statistics handlers and in the credential
store's propagation, the operation context in the shell's s3.bucket.delete and
the kafka gateway's broker and filer discovery, and context.Background() where
there is none - the shell commands, the admin dashboard wrapper, and the
exclusive locker's initial lease. The locker's release keeps its own
uncancelled context so a slow unlock cannot turn into a ghost lock.

Claude-Session: https://claude.ai/code/session_01BjDWtZsCoZY6x4pdDmGWxU

* wdclient: test that WithClient gives up with the caller's context

Claude-Session: https://claude.ai/code/session_01BjDWtZsCoZY6x4pdDmGWxU

* wdclient: cut the master retry backoff short when the caller gives up

util.Retry sleeps unconditionally between attempts, so a transient error
arriving just before the caller's deadline still cost it a full backoff step.
Use the context-aware util.RetryWithBackoff, the same helper the volume lookup
in this file already uses.

Two call sites went with it: the shell's lock-holder lookup builds its three
second bound before WithClient so it also covers finding the leader, as its
comment already promised, and the filer's post-delete collection cleanup goes
back to an uncancelled context - the entry is already gone, so a caller that
hung up must not leave the collection behind.

Claude-Session: https://claude.ai/code/session_01BjDWtZsCoZY6x4pdDmGWxU

* wdclient: test that a cancel during backoff ends the retry

Claude-Session: https://claude.ai/code/session_01BjDWtZsCoZY6x4pdDmGWxU
2026-08-27 22:27:45 -07:00
Chris Lu 08a7502b2c fix(shell): error on missing volume id in fsck, mergeVolumes, vacuum (#9158)
* fix(shell): error on missing volume id in fsck, mergeVolumes, vacuum

Three shell commands silently report success when -volumeId /
-fromVolumeId / -toVolumeId names a volume the master doesn't know
about: typos, already-deleted volumes, and stale scripts all look
identical to a clean no-op, which is what made the confusion in #9116
take as long as it did to diagnose.

- volume.fsck: filter at the per-datanode loop drops unknown ids and
  findExtraChunksInVolumeServers ends with totalOrphanChunkCount==0,
  printing "no orphan data".
- fs.mergeVolumes: createMergePlan iterates only known volumes, so an
  unknown -fromVolumeId produces an empty plan and we print just the
  "max volume size: N MB" header (indistinguishable from "nothing to
  merge").
- volume.vacuum: the master's VacuumVolume RPC silently iterates
  matching volumes; a missing id returns success having done nothing.

Validate the requested ids against the current topology up front and
return an explicit "volume(s) not found on master: [X Y]" error. Also
drop a stale duplicate `if err != nil` in volume.fsck.Do left over from
a prior refactor.

Surfaces #9116 follow-up from madalee-com.

* address review: propagate reloadVolumesInfo error; dedupe vacuum missing ids

- fs.mergeVolumes: c.reloadVolumesInfo's return was ignored. If the
  master is unreachable or VolumeList fails, c.volumes stays empty and
  the new validation block reports "fromVolumeId X not found on master"
  — masking the real connection/RPC failure. Return the wrapped error
  instead.

- volume.vacuum: "volume.vacuum -volumeId 5,5,5" on a missing volume 5
  listed [5 5 5] in the error. Collect missing ids in a set so each
  missing id appears once.

* address review: reject fromVolumeId/toVolumeId values that overflow uint32

flag.Uint produces a uint (64-bit on amd64), and the existing cast to
needle.VolumeId silently truncates to uint32. A typo like
`-fromVolumeId=4294967297` would wrap to volume 1 and slip past every
other validation, so the merge would run against a completely
different volume than the operator intended.

Bail out with an explicit error when the raw flag value exceeds the
uint32 range, before the cast.
2026-04-20 15:32:31 -07:00
Chris Lu cd6832249b Fix volume.fsck crashing on EC volumes and add multi-volume vacuum support (#8406)
* helm: refine openshift-values.yaml to remove hardcoded UIDs

Remove hardcoded runAsUser, runAsGroup, and fsGroup from the
openshift-values.yaml example. This allows OpenShift's admission
controller to automatically assign a valid UID from the namespace's
allocated range, avoiding "forbidden" errors when UID 1000 is
outside the permissible range.

Updates #8381, #8390.

* helm: fix volume.logs and add consistent security context comments

* Update README.md

* fix volume.fsck crashing on EC volumes and add multi-volume vacuum support

* address comments
2026-02-22 22:07:15 -08:00
chrislu ec30a504ba refactor 2024-09-29 10:38:22 -07:00
chrislu 701abbb9df add IsResourceHeavy() to command interface 2024-09-28 20:23:01 -07:00
chrislu 26dbc6c905 move to https://github.com/seaweedfs/seaweedfs 2022-07-29 00:17:28 -07:00
guosj 1a5de36257 fix return value 2022-04-29 11:19:36 +08:00
Konstantin Lebedev 36c5a59ed8 add help 2022-04-18 19:36:14 +05:00
Konstantin Lebedev 1e35b4929f shell vacuum volume by collection and volume id 2022-04-18 18:40:58 +05:00
guosj 26f3ab8d4b fix a return bug in func (c *commandVacuum) Do 2022-02-24 09:04:38 +08:00
chrislu 9f9ef1340c use streaming mode for long poll grpc calls
streaming mode would create separate grpc connections for each call.
this is to ensure the long poll connections are properly closed.
2021-12-26 00:15:03 -08:00
chrislu a2d3f89c7b add lock messages 2021-12-10 13:24:38 -08:00
Chris Lu 119d5908dd shell: do not need to lock to see volume -h 2021-09-13 22:13:34 -07:00
Chris Lu 965413c21b shell: add volume.vacuum command 2020-11-28 23:18:02 -08:00