{"record":{"id":"38ddb9a44fa4b890","repo":"apache/cassandra","slug":"keyspace-keyspace-does-not-exist","errorCode":null,"errorMessage":"Keyspace {keyspace} does not exist","messagePattern":"Keyspace (.+?) does not exist","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/consensus/migration/ConsensusRequestRouter.java","lineNumber":175,"sourceCode":"\n        return pickPaxos();\n    }\n\n    /*\n     * Accord never handles local tables, but if the table doesn't exist then we need to generate the correct\n     * InvalidRequestException.\n     */\n    private static TableMetadata metadata(ClusterMetadata cm, String keyspace, String table)\n    {\n        Optional<KeyspaceMetadata> ksm = cm.schema.maybeGetKeyspaceMetadata(keyspace);\n        if (ksm.isEmpty())\n        {\n            // It's a non-distributed table which is fine, but we want to error if it doesn't exist\n            // We should never actually reach here unless there is a race with dropping the table\n            Keyspaces localKeyspaces = Schema.instance.localKeyspaces();\n            KeyspaceMetadata ksm2 = localKeyspaces.getNullable(keyspace);\n            if (ksm2 == null)\n                throw new InvalidRequestException(\"Keyspace \" + keyspace + \" does not exist\");\n            // Explicitly including views in case they get used in non-distributed tables\n            TableMetadata tbm2 = ksm2.getTableOrViewNullable(table);\n            if (tbm2 == null)\n                throw new InvalidRequestException(\"Table \" + keyspace + \".\" + table + \" does not exist\");\n            return null;\n        }\n        TableMetadata tbm = ksm.get().getTableNullable(table);\n        if (tbm == null)\n            throw new InvalidRequestException(\"Table \" + keyspace + \".\" + table + \" does not exist\");\n\n        return tbm;\n    }\n\n    public ConsensusRoutingDecision routeAndMaybeMigrate(@Nonnull ClusterMetadata cm, @Nonnull DecoratedKey key, @Nonnull TableId tableId, ConsistencyLevel consistencyLevel, Dispatcher.RequestTime requestTime, long timeoutNanos, boolean isForWrite)\n    {\n        TableMetadata metadata = getTableMetadata(cm, tableId);\n        // Non-distributed tables always take the Paxos path\n        if (metadata == null)","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/consensus/migration/ConsensusRequestRouter.java#L157-L193","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry the request; if the drop was intentional the error is expected and the client should stop using the keyspace","Verify the keyspace name spelling in the client/application configuration","Run a schema agreement check (nodetool describecluster / system_schema queries) and refresh schema on the node","If drops are frequent, serialize schema changes with application-level request draining"],"exampleFix":"// before\nsession.execute(\"SELECT * FROM mykeyspace.mytable WHERE k = ?\", key);\n// after\nif (session.getCluster().getMetadata().getKeyspace(\"mykeyspace\") == null) {\n    throw new IllegalStateException(\"Keyspace mykeyspace was dropped; aborting request\");\n}\nsession.execute(\"SELECT * FROM mykeyspace.mytable WHERE k = ?\", key);","handlingStrategy":"try-catch","validationCode":"KeyspaceMetadata ksm = session.getCluster().getMetadata().getKeyspace(keyspace);\nif (ksm == null) throw new IllegalArgumentException(\"Keyspace \" + keyspace + \" does not exist\");","typeGuard":null,"tryCatchPattern":"try { router.metadata(cm, keyspace, table, ...); }\ncatch (InvalidRequestException e) {\n    // keyspace dropped concurrently; refresh schema and decide retry vs. abort\n}","preventionTips":["Check keyspace existence via driver metadata before issuing requests","Avoid DDL (DROP KEYSPACE) concurrent with steady-state traffic; drain first","Watch for schema-disagreement alerts after drops"],"tags":["schema","invalid-request","race-condition"],"backgroundTag":"entity-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}