apache/cassandra · error · IllegalArgumentException
Cannot specify tokens without keyspace.
Error message
Cannot specify tokens without keyspace.
What it means
Nodetool 'rebuild' only accepts the --tokens (source-token selection) option together with an explicit keyspace; tokens filter which sources stream data for a specific keyspace rebuild. Passing --tokens with no keyspace is rejected client-side with this IllegalArgumentException before the JMX rebuild call.
Solutions
- Add the keyspace: `nodetool rebuild -- <keyspace> -- --tokens <tokens>`
- Drop the --tokens option if you intend a full (all-keyspace) rebuild
- Run `nodetool help rebuild` to confirm argument syntax
Example fix
// before nodetool rebuild -- --tokens 1,2,3 // after nodetool rebuild -- myks -- --tokens 1,2,3
Defensive patterns
Strategy: validation
Validate before calling
if [ -n "$TOKENS" ] && [ -z "$KEYSPACE" ]; then echo "--tokens requires a keyspace"; exit 2; fi
Prevention
- Pair --tokens with an explicit keyspace in scripts
- Drop --tokens for full rebuilds
- Validate CLI flags in wrapper scripts
When it happens
Trigger: `nodetool rebuild -- --tokens <token,...>` (or -tk) without specifying a keyspace.
Common situations: Copying rebuild examples that use --tokens without noticing they also pass a keyspace; scripting a full-cluster rebuild where keyspace was omitted intentionally.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- arguments for -F are json, yaml, table only.
- Need to give either a token for a new move operation, or…
- argument for sort must be one of
- argument for top must be a positive integer.
- Argument must have keyspace and table values.
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/bf3632ff88de6121.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/tools/nodetool/Rebuild.java:61
private String tokens = null;
@Option(paramLabel = "specific_sources",
names = {"-s", "--sources"},
description = "Use -s to specify hosts that this node should stream from when -ts is used. Multiple hosts should be separated using commas (e.g. 127.0.0.1,127.0.0.2,...)")
private String specificSources = null;
@Option(paramLabel = "exclude_local_dc",
names = {"--exclude-local-dc"},
description = "Use --exclude-local-dc to exclude nodes in local data center as source for streaming.")
private boolean excludeLocalDatacenterNodes = false;
@Override
public void execute(NodeProbe probe)
{
// check the arguments
if (keyspace == null && tokens != null)
{
throw new IllegalArgumentException("Cannot specify tokens without keyspace.");
}
probe.rebuild(sourceDataCenterName, keyspace, tokens, specificSources, excludeLocalDatacenterNodes);
}
}
View on GitHub (pinned to 88fd0f6a0e)