apache/cassandra · error · IllegalArgumentException
Cannot specify tokens without keyspace.
Error message
Cannot specify tokens without keyspace.
What it means
IllegalArgumentException from Rebuild.rebuild when nodetool rebuild is invoked with --tokens (or an equivalent token list) but no keyspace argument. Token-streaming rebuild is only meaningful in a keyspace context, so this argument combination is rejected up front before any streaming starts.
Source
Thrown at src/java/org/apache/cassandra/service/Rebuild.java:100
if (sourceDc != null)
{
if (sourceDc.equals(DatabaseDescriptor.getLocalDataCenter()) && excludeLocalDatacenterNodes) // fail if source DC is local and --exclude-local-dc is set
throw new IllegalArgumentException("Cannot set source data center to be local data center, when excludeLocalDataCenter flag is set");
Set<String> availableDCs = ClusterMetadata.current().directory.knownDatacenters();
if (!availableDCs.contains(sourceDc))
{
throw new IllegalArgumentException(String.format("Provided datacenter '%s' is not a valid datacenter, available datacenters are: %s",
sourceDc, String.join(",", availableDCs)));
}
}
try
{
// check the arguments
if (keyspace == null && tokens != null)
{
throw new IllegalArgumentException("Cannot specify tokens without keyspace.");
}
logger.info("rebuild from dc: {}, {}, {}", sourceDc == null ? "(any dc)" : sourceDc,
keyspace == null ? "(All keyspaces)" : keyspace,
tokens == null ? "(All tokens)" : tokens);
StorageService.instance.repairPaxosForTopologyChange("rebuild");
ClusterMetadata metadata = ClusterMetadata.current();
MovementMap rebuildMovements = movementMap(metadata, keyspace, tokens);
logger.info("Rebuild movements: {}", rebuildMovements);
RangeStreamer streamer = new RangeStreamer(metadata,
StreamOperation.REBUILD,
false, // no strict consistency when rebuilding
DatabaseDescriptor.getNodeProximity(),
StorageService.instance.streamStateStore,
false,
DatabaseDescriptor.getStreamingConnectionsPerHost(),
rebuildMovements,View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Supply the keyspace the tokens belong to along with tokens
- Drop the tokens argument to rebuild all keyspaces/ranges
Example fix
// before nodetool rebuild --tokens "(-9223372036854775808,-4611686018427387904]" // after nodetool rebuild -ks my_keyspace --tokens "(-9223372036854775808,-4611686018427387904]"
Defensive patterns
Strategy: validation
Validate before calling
if (tokens != null && keyspace == null)
throw new IllegalArgumentException("tokens requires keyspace"); Prevention
- Always pass -ks when using --tokens with `nodetool rebuild`
- Validate CLI/script arguments before invoking the JMX rebuild method
- Keep runbook commands with both flags together to avoid omissions
When it happens
Trigger: Calling rebuild(sourceDc, keyspace=null, tokens=<list>, ...) — e.g. `nodetool rebuild --initial-token ...` style usage without specifying -ks.
Common situations: Operator wants to rebuild only certain ranges after bootstrap issue but forgets the keyspace flag; scripting the JMX rebuild(String,String,String,String,boolean) with null keyspace but non-null tokens.
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
- Cannot set source data center to be local data center, when
- Provided datacenter '%s' is not a valid datacenter, availabl
- This host was specified as a source for rebuilding. Sources
- Unknown host specified ${stringHost}
- Unexpected string: ${tokenScanner.next()}
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/aca846081c6dedeb.
Report an issue: GitHub.