apache/cassandra · error · InvalidRequestException
Invalid empty consistency level
Error message
Invalid empty consistency level
What it means
BatchStatement.execute requires a non-null consistency level on the BatchQueryOptions. If the consistency level was never set (left null) the coordinator cannot determine the required replication ack count, so it throws InvalidRequestException 'Invalid empty consistency level'.
Source
Thrown at src/java/org/apache/cassandra/cql3/statements/BatchStatement.java:506
tableNames.size() == 1 ? "" : "s", tableNames}).getMessage());
}
}
}
@Override
public ResultMessage execute(QueryState queryState, QueryOptions options, Dispatcher.RequestTime requestTime)
{
return execute(queryState, BatchQueryOptions.withoutPerStatementVariables(options), requestTime);
}
public ResultMessage execute(QueryState queryState, BatchQueryOptions options, Dispatcher.RequestTime requestTime)
{
long timestamp = options.getTimestamp(queryState);
long nowInSeconds = options.getNowInSeconds(queryState);
if (options.getConsistency() == null)
throw new InvalidRequestException("Invalid empty consistency level");
if (options.getSerialConsistency() == null)
throw new InvalidRequestException("Invalid empty serial consistency level");
ClientState clientState = queryState.getClientState();
if (Guardrails.writeConsistencyLevels.enabled(clientState)) // to avoid EnumSet allocation
Guardrails.writeConsistencyLevels.guard(EnumSet.of(options.getConsistency(),
options.getSerialConsistency()),
clientState);
// resolved once for the whole batch, the guardrail checks are not cheap enough to repeat per statement
DiskUsageCheck diskUsageCheck = ModificationStatement.diskUsageCheck(clientState);
if (diskUsageCheck != DiskUsageCheck.NONE)
for (int i = 0; i < statements.size(); i++)
statements.get(i).validateDiskUsage(options.forStatement(i), clientState, diskUsageCheck);
if (hasConditions)
return executeWithConditions(options, queryState, requestTime);
View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Set the consistency level explicitly before executing (options.setConsistency(ConsistencyLevel.QUORUM) or QUORUM-level equivalent in your driver)
- If using a driver, ensure the request includes a consistency level (or configure a default CL in the driver)
- Fix internal tooling to populate BatchQueryOptions consistency rather than passing null
Example fix
// before BatchQueryOptions opts = BatchQueryOptions.forStatement(statements, rawOptions); // CL unset batch.execute(queryState, opts, requestTime); // after rawOptions.setConsistency(ConsistencyLevel.QUORUM); batch.execute(queryState, BatchQueryOptions.forStatement(statements, rawOptions), requestTime);
Defensive patterns
Strategy: validation
Validate before calling
if (options.getConsistency() == null) options.setConsistency(ConsistencyLevel.QUORUM);
Try / catch
catch (InvalidRequestException e) { if (e.getMessage().contains("Invalid empty consistency")) { setDefaultClAndRetry(); } else throw e; } Prevention
- Always build query options through helpers that set a default CL
- In drivers, configure a default consistency level instead of leaving it unset
When it happens
Trigger: Programmatic execution of a BatchStatement where QueryOptions/BatchQueryOptions was constructed without calling setConsistency; native protocol frames missing the consistency field; internal callers bypassing statement preparation.
Common situations: Custom drivers/tools building batch options manually; embedded usage of Cassandra internals (e.g. tests or tools calling execute directly); protocol-level clients omitting the CL field.
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
- Counter and non-counter mutations cannot exist in the same b
- Write operation require a read but consistency %s is not sup
- There were %d markers(?) in CQL but %d bound variables
- Invalid statement in batch: only UPDATE, INSERT and DELETE s
- Invalid null value of timestamp
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/24602ef6d0e02d49.
Report an issue: GitHub.