Skip to content

NodeSet: add brace expansion to node set strings - #739

Merged
thiell merged 1 commit into
clustershell:masterfrom
thiell:feature/nodeset-braces
Nov 16, 2026
Merged

thiell merged 1 commit into
clustershell:masterfrom
thiell:feature/nodeset-braces

Conversation

@thiell

@thiell thiell commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Braces list alternatives for a part of a node name: server[5-9]-{mds,oss} is server[5-9]-mds,server[5-9]-oss, and node[1-3]{,-ib} adds the -ib names of node[1-3]. Shell brace expansion is the usual workaround today, but it breaks clush -w (the shell splits the argument and clush runs the wrong command) and does not help in group sources, host files or the Python API.

  • {a,b} expands a term once per alternative; the union is one operand of the extended pattern operators, so node[1-9]&node{2,4} is node[2,4] (a textual rewrite would be wrong for & and ^)
  • several braces in a term form a cartesian product; alternatives may be empty and surrounding whitespace is ignored, except where whitespace already separates node sets (group source results, host files, standard input)
  • alternatives are literal strings: ranges, groups, wildcards, operators and nested braces are rejected inside braces (and braces inside ranges), but keep working elsewhere in the same term (@rack{1,2}, server-{mds,oss}[0-3], n{1,2}*)
  • output never contains braces, so results stay usable as -w arguments everywhere
  • { and } become reserved characters and join ILLEGAL_GROUP_CHARS
  • strings without braces follow the same code path as before: single node names parse as fast as before, other strings about 2-3% slower
  • docs: new section in the cluset (or nodeset) tool pages and man pages, a mention for clush -w, the guide, the reserved characters in groups.conf, quoting in YAML group files, and a warning about quoting braces on the command line

@thiell thiell added this to the 1.11 milestone Oct 30, 2026
@thiell
thiell force-pushed the feature/nodeset-braces branch from 9fe60d2 to 51b9736 Compare November 5, 2026 17:59
Braces list alternatives for a part of a node name:
server[5-9]-{mds,oss} is server[5-9]-mds,server[5-9]-oss, and
node[1-3]{,-ib} adds the -ib names of node[1-3]. Several braces in a
term form a cartesian product.

A term with braces is evaluated as a whole operand of the extended
pattern operators, so node[1-9]&node{2,4} is node[2,4]. Alternatives are
literal strings: ranges, groups, wildcards and operators are rejected
inside braces (and braces inside ranges) but still work elsewhere in the
same term, as each expansion is fed back through the parser.

{ and } become reserved characters and are added to ILLEGAL_GROUP_CHARS.
Strings without braces take the same code path as before.

Signed-off-by: Stephane Thiell <stephane@thiell.com>
@thiell
thiell force-pushed the feature/nodeset-braces branch from 51b9736 to 3ef2ef2 Compare November 14, 2026 15:41
@thiell

thiell commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

Force-pushed a small update after additional Fable 5.2 max review findings. The review included a fuzzing pass of 250,000 random expressions against an independent oracle (expand the braces as text, parse each expansion with master, compute the union, apply the operators left to right). Strings without braces (120,000) give the same results and error messages as master.

  • Whitespace after an empty expansion: {},b worked but {} ,b and {,a} , b raised parse error. The scanner yields a brace term whole, up to the next operator, so it kept its trailing whitespace, and an empty alternative left a whitespace-only string for the recursive parse. The term is now rstrip()ed, as the scanner already does for other nodes. This was the only disagreement with the oracle on valid input.
  • Linear time on malformed input: BRACE_OP_RE finds the first operator outside [...] and {...}. On an unclosed [ or { it scanned to the end of the string, failed, then started again one character later, so {[[[[... took 204 ms for 20k characters (master rejects [[[[... at once). The closing character is now optional in the regex: an unclosed bracket or brace takes the rest of the string in one match. 200k characters fail in about 1 ms, well-formed strings match exactly as before, and the error shows the whole term (missing closing brace: "n{1,2", was "n{1").
  • Docs, whitespace inside braces: it is ignored only when the node set is a single string. Group source results, host files and standard input are split on whitespace first, so a group source returning node{1, 2} is joined back as node{1,,2} and silently adds node through the empty alternative (host files and standard input raise a parse error). The parser cannot tell this from a wanted empty alternative like {,-ib}, so the docs now state the exception. The YAML group files section also says to quote node sets, as a leading { starts a YAML mapping.
  • Tests: one assertion for the first point, and one for a brace term returned by a non-default group source (@other:io returning @{mds,oss} must resolve both groups in other), which was not covered.
  • Description: I measured strings without braces again, base and PR in the same process with a control copy of the base (noise about 1%). Single node names are as fast as before; other strings are about 2-3% slower (two in checks per parse, one per term, one extra call). The description said "within measurement noise" and is updated.

@thiell
thiell added this pull request to the merge queue Nov 16, 2026
Merged via the queue into clustershell:master with commit 5e39753 Nov 16, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant