{"record":{"id":"378ef22365c44cd9","repo":"apache/cassandra","slug":"the-sum-of-nodes-in-each-rack-s-must-equal-total","errorCode":null,"errorMessage":"The sum of nodes in each rack %s must equal total node count %s.","messagePattern":"The sum of nodes in each rack (.+?) must equal total node count (.+?)\\.","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/GenerateTokens.java","lineNumber":80,"sourceCode":"        try\n        {\n            // disable the summary statistics logging, since this is a command-line tool with dedicated output\n            ((Logger) LoggerFactory.getLogger(TokenAllocation.class)).setLevel(Level.ERROR);\n\n            Util.initDatabaseDescriptor();\n            options = getOptions();\n            CommandLine cmd = parseCommandLine(args, options);\n\n            rf = Integer.parseInt(cmd.getOptionValue(RF));\n            tokens = Integer.parseInt(cmd.getOptionValue(TOKENS));\n            nodes = Integer.parseInt(cmd.getOptionValue(NODES));\n            logger = new OutputHandler.SystemOutput(cmd.hasOption(VERBOSE), true, true);\n\n            partitioner = FBUtilities.newPartitioner(cmd.getOptionValue(PARTITIONER, Murmur3Partitioner.class.getSimpleName()));\n            racksDef = getRacks(cmd.getOptionValue(RACKS, cmd.getOptionValue(NODES)));\n            if (Arrays.stream(racksDef).sum() != nodes)\n            {\n                throw new AssertionError(String.format(\"The sum of nodes in each rack %s must equal total node count %s.\",\n                                                       cmd.getOptionValue(RACKS),\n                                                       cmd.getOptionValue(NODES)));\n            }\n        }\n        catch (NumberFormatException e)\n        {\n            System.err.println(\"Invalid integer \" + e.getMessage());\n            System.out.println();\n            printUsage(options);\n            System.exit(1);\n        }\n        catch (AssertionError | ConfigurationException | ParseException t)\n        {\n            System.err.println(t.getMessage());\n            System.out.println();\n            printUsage(options);\n            System.exit(1);\n        }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/GenerateTokens.java#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\n// GenerateTokens -t 6 -r 2,2,1 ...\n// after\n// GenerateTokens -t 6 -r 2,2,2 ...","handlingStrategy":"validation","validationCode":"int sum = Arrays.stream(racksDef).sum();\nif (sum != nodes)\n    throw new IllegalArgumentException(\"Rack counts sum \" + sum + \" != total nodes \" + nodes);","typeGuard":null,"tryCatchPattern":"try { GenerateTokens.main(args); } catch (AssertionError e) { System.err.println(\"Fix -r/-n vs -t: \" + e.getMessage()); }","preventionTips":["Recount nodes per rack before generating tokens","Keep the racks option and total consistent in scripts","Validate sums in wrapper scripts before invoking"],"tags":["cli","tokens","validation","assertion"],"backgroundTag":"invalid-config-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}