{"record":{"id":"4a56d145d9956987","repo":"apache/cassandra","slug":"keyspace-keyspacename-does-not-exist","errorCode":null,"errorMessage":"Keyspace \" + keyspaceName + \" does not exist","messagePattern":"Keyspace \" \\+ keyspaceName \\+ \" does not exist","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/Keyspace.java","lineNumber":233,"sourceCode":"    }\n\n    public ColumnFamilyStore getIfExists(TableId id)\n    {\n        return columnFamilyStores.get(id);\n    }\n\n    public boolean hasColumnFamilyStore(TableId id)\n    {\n        return columnFamilyStores.containsKey(id);\n    }\n\n    public static void verifyKeyspaceIsValid(String keyspaceName)\n    {\n        if (null != VirtualKeyspaceRegistry.instance.getKeyspaceNullable(keyspaceName))\n            throw new IllegalArgumentException(\"Cannot perform any operations against virtual keyspace \" + keyspaceName);\n\n        if (!Schema.instance.getKeyspaces().contains(keyspaceName))\n            throw new IllegalArgumentException(\"Keyspace \" + keyspaceName + \" does not exist\");\n    }\n\n    public static Keyspace getValidKeyspace(String keyspaceName)\n    {\n        verifyKeyspaceIsValid(keyspaceName);\n        return Keyspace.open(keyspaceName);\n    }\n\n    /**\n     * @return A list of open SSTableReaders\n     */\n    public List<SSTableReader> getAllSSTables(SSTableSet sstableSet)\n    {\n        List<SSTableReader> list = new ArrayList<>(columnFamilyStores.size());\n        for (ColumnFamilyStore cfStore : columnFamilyStores.values())\n            Iterables.addAll(list, cfStore.getSSTables(sstableSet));\n        return list;\n    }","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/Keyspace.java#L215-L251","documentation":"Keyspace.verifyKeyspaceIsValid validates a keyspace name before opening it: it rejects virtual keyspaces outright and throws IllegalArgumentException when the name is not present in the local schema. It is a fast-fail guard so callers like getValidKeyspace never attempt operations against a nonexistent or virtual keyspace.","triggerScenarios":"Calling Keyspace.getValidKeyspace(name) or verifyKeyspaceIsValid(name) with a keyspace that was never created, was dropped, or has not yet propagated via schema agreement to this node; also when the name refers to a virtual keyspace (a different IllegalArgumentException is thrown).","commonSituations":"Typos in keyspace name in application config or cqlsh; running against a node that has not yet learned about a newly created keyspace (schema disagreement); tools like nodetool/repair invoked right after keyspace creation; case-sensitivity mistakes (quoted vs unquoted identifiers).","solutions":["Verify the exact keyspace name with `SELECT keyspace_name FROM system_schema.keyspaces;` and correct any typo in the caller/config.","Run `nodetool describecluster` / check schema versions and run `nodetool resettm`-free remedies: wait for schema agreement or restart the out-of-sync node so the keyspace propagates.","Create the keyspace if it is genuinely missing: `CREATE KEYSPACE ... WITH replication = {...}`."],"exampleFix":"// before\nKeyspace ks = Keyspace.getValidKeyspace(\"UserKeySpace\");\n// after\nString ksName = schemaAwareConfig.getKeyspace(); // verified via system_schema.keyspaces\nif (!Schema.instance.getKeyspaces().contains(ksName)) throw newConfigurationException(...);\nKeyspace ks = Keyspace.getValidKeyspace(ksName);","handlingStrategy":"validation","validationCode":"if (!Schema.instance.getKeyspaces().contains(ksName))\n    throw new IllegalArgumentException(\"keyspace missing: \" + ksName);\nif (VirtualKeyspaceRegistry.instance.getKeyspaceNullable(ksName) != null)\n    throw new IllegalArgumentException(\"virtual keyspace: \" + ksName);","typeGuard":null,"tryCatchPattern":"try { ks = Keyspace.getValidKeyspace(name); } catch (IllegalArgumentException e) { LOG.error(\"keyspace invalid: {}\", name, e); return null; }","preventionTips":["Centralize keyspace-name constants; never hardcode names inline.","After CREATE KEYSPACE, wait for schema agreement before using it from other nodes.","Verify names against system_schema.keyspaces at startup."],"tags":["keyspace","schema","illegal-argument","resource-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}