{"record":{"id":"69570a901ee4a8fe","repo":"apache/cassandra","slug":"table-with-id-tableid-does-not-exist","errorCode":null,"errorMessage":"Table with id {tableId} does not exist","messagePattern":"Table with id (.+?) does not exist","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/consensus/migration/ConsensusRequestRouter.java","lineNumber":208,"sourceCode":"    {\n        TableMetadata metadata = getTableMetadata(cm, tableId);\n        // Non-distributed tables always take the Paxos path\n        if (metadata == null)\n            return pickPaxos();\n        return routeAndMaybeMigrate(cm, metadata, key, consistencyLevel, requestTime, timeoutNanos, isForWrite);\n    }\n\n    public static TableMetadata getTableMetadata(ClusterMetadata cm, TableId tableId)\n    {\n        TableMetadata tm = cm.schema.getTableMetadata(tableId);\n        if (tm == null)\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            TableMetadata tm2 = localKeyspaces.getTableOrViewNullable(tableId);\n            if (tm2 == null)\n                throw new InvalidRequestException(\"Table with id \" + tableId + \" does not exist\");\n            return null;\n        }\n        return tm;\n    }\n\n    protected ConsensusRoutingDecision routeAndMaybeMigrate(ClusterMetadata cm, @Nonnull TableMetadata tmd, @Nonnull DecoratedKey key, ConsistencyLevel consistencyLevel, Dispatcher.RequestTime requestTime, long timeoutNanos, boolean isForWrite)\n    {\n        if (!tmd.params.transactionalMigrationFrom.isMigrating())\n            return decisionFor(tmd.params.transactionalMode);\n\n        TableMigrationState tms = cm.consensusMigrationState.tableStates.get(tmd.id);\n        if (tms == null)\n            return decisionFor(tmd.params.transactionalMigrationFrom.from);\n\n        Token token = key.getToken();\n        if (tms.migratedRanges.intersects(token))\n            return pickMigrated(tms.targetProtocol, IAccordService.NO_HLC);\n","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/consensus/migration/ConsensusRequestRouter.java#L190-L226","documentation":"ConsensusRequestRouter.getTableMetadata(TableId) resolves a TableId to TableMetadata; when the id is not in the schema it throws InvalidRequestException. Like the name-based variants, this is expected mainly when a DROP TABLE races in-flight routing for a request that carries only the table's id.","triggerScenarios":"Routing calls (metadata, isKeyManagedByAccordForReadAndWrite/Write, tableMetadata, tm) receiving a TableId absent from ClusterMetadata/local schema — a dropped table's id still referenced by in-flight requests or cached routing state.","commonSituations":"DROP TABLE racing Accord traffic; stale prepared statements / cached TableIds in the driver after a table was recreated (new id); version-skew or schema disagreement between nodes.","solutions":["Re-prepare statements / refresh cluster metadata so the client picks up the new TableId after re-creating a table","Retry with backoff if the drop was intentional; stop sending requests for the dropped table","Check schema agreement and force a schema reload on the routing node","If the table should exist, verify it was not accidentally dropped (audit DDL history)"],"exampleFix":"// before\nPreparedStatement ps = session.prepare(\"SELECT * FROM ks.tbl WHERE k = ?\"); // cached across a DROP/CREATE cycle\n// after\n// re-prepare on 'table doesn't exist' style errors, e.g. after a DROP+CREATE\nsession.getCluster().getMetadata().checkSchemaAgreement();\nPreparedStatement ps = session.prepare(\"SELECT * FROM ks.tbl WHERE k = ?\");","handlingStrategy":"try-catch","validationCode":"TableMetadata tm = session.getCluster().getMetadata().getTable(tableId);\nif (tm == null) throw new IllegalArgumentException(\"Table with id \" + tableId + \" does not exist\");","typeGuard":null,"tryCatchPattern":"try { TableMetadata tmd = router.getTableMetadata(cm, tableId); }\ncatch (InvalidRequestException e) { /* TableId stale: re-resolve from name, re-prepare statements */ }","preventionTips":["Never cache TableId across DROP/CREATE cycles; resolve from (keyspace, table) each time","Re-prepare driver statements after table recreation","Track DDL audit logs to correlate 'table with id' errors with drops"],"tags":["schema","invalid-request","table-id","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"}