apache/cassandra · error · InvalidRequestException

Keyspace does not exist

Error message

Keyspace {keyspace} does not exist

What it means

ConsensusRequestRouter.metadata() validates that the target keyspace/table exists before making a routing decision. When the keyspace is absent from the local schema, it throws InvalidRequestException. The code notes this normally means a race with dropping the keyspace/table.

Solutions

  1. Retry the request; if the drop was intentional the error is expected and the client should stop using the keyspace
  2. Verify the keyspace name spelling in the client/application configuration
  3. Run a schema agreement check (nodetool describecluster / system_schema queries) and refresh schema on the node
  4. If drops are frequent, serialize schema changes with application-level request draining

Example fix

// before
session.execute("SELECT * FROM mykeyspace.mytable WHERE k = ?", key);
// after
if (session.getCluster().getMetadata().getKeyspace("mykeyspace") == null) {
    throw new IllegalStateException("Keyspace mykeyspace was dropped; aborting request");
}
session.execute("SELECT * FROM mykeyspace.mytable WHERE k = ?", key);
Defensive patterns

Strategy: try-catch

Validate before calling

KeyspaceMetadata ksm = session.getCluster().getMetadata().getKeyspace(keyspace);
if (ksm == null) throw new IllegalArgumentException("Keyspace " + keyspace + " does not exist");

Try / catch

try { router.metadata(cm, keyspace, table, ...); }
catch (InvalidRequestException e) {
    // keyspace dropped concurrently; refresh schema and decide retry vs. abort
}

Prevention

When it happens

Trigger: A request routed to this node references a keyspace that no longer exists in the local schema — typically a DROP KEYSPACE racing with in-flight requests, or a client typo'ing the keyspace name.

Common situations: Concurrent DROP KEYSPACE while reads/writes are in flight; clients using stale schema metadata after a keyspace was removed; typo'd keyspace in application config.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/38ddb9a44fa4b890. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/service/consensus/migration/ConsensusRequestRouter.java:175

        return pickPaxos();
    }

    /*
     * Accord never handles local tables, but if the table doesn't exist then we need to generate the correct
     * InvalidRequestException.
     */
    private static TableMetadata metadata(ClusterMetadata cm, String keyspace, String table)
    {
        Optional<KeyspaceMetadata> ksm = cm.schema.maybeGetKeyspaceMetadata(keyspace);
        if (ksm.isEmpty())
        {
            // It's a non-distributed table which is fine, but we want to error if it doesn't exist
            // We should never actually reach here unless there is a race with dropping the table
            Keyspaces localKeyspaces = Schema.instance.localKeyspaces();
            KeyspaceMetadata ksm2 = localKeyspaces.getNullable(keyspace);
            if (ksm2 == null)
                throw new InvalidRequestException("Keyspace " + keyspace + " does not exist");
            // Explicitly including views in case they get used in non-distributed tables
            TableMetadata tbm2 = ksm2.getTableOrViewNullable(table);
            if (tbm2 == null)
                throw new InvalidRequestException("Table " + keyspace + "." + table + " does not exist");
            return null;
        }
        TableMetadata tbm = ksm.get().getTableNullable(table);
        if (tbm == null)
            throw new InvalidRequestException("Table " + keyspace + "." + table + " does not exist");

        return tbm;
    }

    public ConsensusRoutingDecision routeAndMaybeMigrate(@Nonnull ClusterMetadata cm, @Nonnull DecoratedKey key, @Nonnull TableId tableId, ConsistencyLevel consistencyLevel, Dispatcher.RequestTime requestTime, long timeoutNanos, boolean isForWrite)
    {
        TableMetadata metadata = getTableMetadata(cm, tableId);
        // Non-distributed tables always take the Paxos path
        if (metadata == null)

View on GitHub (pinned to 88fd0f6a0e)