apache/cassandra · error · AssertionError
The sum of nodes in each rack %s must equal total node count
Error message
The sum of nodes in each rack %s must equal total node count %s.
What it means
GenerateTokens.main validates that the per-rack node counts given via -r/-n sum exactly to the total node count given via -t. An AssertionError signals a configuration mismatch between the racks definition and total nodes, so token generation cannot proceed.
Source
Thrown at src/java/org/apache/cassandra/tools/GenerateTokens.java:80
try
{
// disable the summary statistics logging, since this is a command-line tool with dedicated output
((Logger) LoggerFactory.getLogger(TokenAllocation.class)).setLevel(Level.ERROR);
Util.initDatabaseDescriptor();
options = getOptions();
CommandLine cmd = parseCommandLine(args, options);
rf = Integer.parseInt(cmd.getOptionValue(RF));
tokens = Integer.parseInt(cmd.getOptionValue(TOKENS));
nodes = Integer.parseInt(cmd.getOptionValue(NODES));
logger = new OutputHandler.SystemOutput(cmd.hasOption(VERBOSE), true, true);
partitioner = FBUtilities.newPartitioner(cmd.getOptionValue(PARTITIONER, Murmur3Partitioner.class.getSimpleName()));
racksDef = getRacks(cmd.getOptionValue(RACKS, cmd.getOptionValue(NODES)));
if (Arrays.stream(racksDef).sum() != nodes)
{
throw new AssertionError(String.format("The sum of nodes in each rack %s must equal total node count %s.",
cmd.getOptionValue(RACKS),
cmd.getOptionValue(NODES)));
}
}
catch (NumberFormatException e)
{
System.err.println("Invalid integer " + e.getMessage());
System.out.println();
printUsage(options);
System.exit(1);
}
catch (AssertionError | ConfigurationException | ParseException t)
{
System.err.println(t.getMessage());
System.out.println();
printUsage(options);
System.exit(1);
}View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Adjust the -r/-n rack counts so they sum to the -t total node count.
- Recount the cluster's nodes per rack and regenerate the option values.
- Check the printed values of RACKS/NODES options in the message to spot which side is wrong.
Example fix
// before // GenerateTokens -t 6 -r 2,2,1 ... // after // GenerateTokens -t 6 -r 2,2,2 ...
Defensive patterns
Strategy: validation
Validate before calling
int sum = Arrays.stream(racksDef).sum();
if (sum != nodes)
throw new IllegalArgumentException("Rack counts sum " + sum + " != total nodes " + nodes); Try / catch
try { GenerateTokens.main(args); } catch (AssertionError e) { System.err.println("Fix -r/-n vs -t: " + e.getMessage()); } Prevention
- Recount nodes per rack before generating tokens
- Keep the racks option and total consistent in scripts
- Validate sums in wrapper scripts before invoking
When it happens
Trigger: Running GenerateTokens where Arrays.stream(racksDef).sum() != nodes, e.g. -t 6 with -r 2,2,1 (sum 5), or omitting/misspelling one of the options so defaults disagree.
Common situations: Adding a node to the cluster but forgetting to update the racks list; typos in comma-separated counts; confusing -n (nodes per rack list) with -t (total).
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Cannot specify a repair as both paxos only and accord only
- Start and end tokens must be different.
- The specified range %s is not a range that is owned by this
- Tokens must be provided to force join a node.
- When specifying the table for a snapshot, you must specify o
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/378ef22365c44cd9.
Report an issue: GitHub.