mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-19 04:24:28 +02:00
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.
This commit is contained in:
1 parent
268424a5e1
commit
b0ab4c4e1e
23 files changed
+593
-71
No files matched your search
@@ -211,6 +211,47 @@ func isRegexEntry(entry string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ExpandCollectionFilter resolves a collection_filter into concrete names
|
||||
// drawn from candidates — the same names CompileCollectionMatcher would
|
||||
// match — with one difference: a literal entry (no wildcard or regex syntax)
|
||||
// is returned even when absent from candidates, since a command may target a
|
||||
// collection the listing does not contain yet. CollectionDefault resolves to
|
||||
// the empty-named collection. Empty, "*", and the mode sentinels return all
|
||||
// candidates.
|
||||
func ExpandCollectionFilter(filter string, candidates []string) ([]string, error) {
|
||||
trimmed := strings.TrimSpace(filter)
|
||||
mode := CollectionFilterMode(trimmed)
|
||||
if trimmed == "" || trimmed == "*" || mode == CollectionFilterAll || mode == CollectionFilterEach {
|
||||
return candidates, nil
|
||||
}
|
||||
matcher, err := CompileCollectionMatcher(trimmed)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
seen := make(map[string]bool, len(candidates))
|
||||
var out []string
|
||||
add := func(name string) {
|
||||
if !seen[name] {
|
||||
seen[name] = true
|
||||
out = append(out, name)
|
||||
}
|
||||
}
|
||||
for _, entry := range splitCollectionEntries(trimmed) {
|
||||
entry = strings.TrimSpace(entry)
|
||||
if entry == CollectionDefault {
|
||||
add("")
|
||||
} else if !isRegexEntry(entry) && !strings.ContainsAny(entry, "*?") {
|
||||
add(entry)
|
||||
}
|
||||
}
|
||||
for _, name := range candidates {
|
||||
if matcher.Matches(name) {
|
||||
add(name)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Matches reports whether a collection passes the filter. A nil matcher accepts everything.
|
||||
func (m *CollectionMatcher) Matches(collection string) bool {
|
||||
if m == nil {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package wildcard
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCompileCollectionMatcher(t *testing.T) {
|
||||
cases := []struct {
|
||||
@@ -72,3 +75,36 @@ func TestCompileCollectionMatcherInvalidEntry(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandCollectionFilter(t *testing.T) {
|
||||
listed := []string{"photos", "photos-backup", "videos"}
|
||||
cases := []struct {
|
||||
filter string
|
||||
want []string
|
||||
}{
|
||||
// Match-all forms return the candidates.
|
||||
{"", listed},
|
||||
{"*", listed},
|
||||
{string(CollectionFilterEach), listed},
|
||||
// A literal name passes through even when unlisted — the listing only
|
||||
// covers collections with registered volumes.
|
||||
{"photos", []string{"photos"}},
|
||||
{"archived", []string{"archived"}},
|
||||
{CollectionDefault, []string{""}},
|
||||
{"photos," + CollectionDefault, []string{"photos", ""}},
|
||||
// Patterns resolve only against listed names; a literal in the same
|
||||
// list still passes through.
|
||||
{"photos*", []string{"photos", "photos-backup"}},
|
||||
{"photos*,archived", []string{"archived", "photos", "photos-backup"}},
|
||||
{"^videos$", []string{"videos"}},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got, err := ExpandCollectionFilter(c.filter, listed)
|
||||
if err != nil {
|
||||
t.Fatalf("ExpandCollectionFilter(%q): %v", c.filter, err)
|
||||
}
|
||||
if !reflect.DeepEqual(got, c.want) {
|
||||
t.Errorf("ExpandCollectionFilter(%q) = %v, want %v", c.filter, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user