{"record":{"id":"9c6ef89e4eb5a1c9","repo":"apache/cassandra","slug":"keyspace-keyspace-not-found-in-cluster-metadata","errorCode":null,"errorMessage":"Keyspace ${keyspace} not found in cluster metadata.","messagePattern":"Keyspace (.+?) not found in cluster metadata\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/CMSOfflineTool.java","lineNumber":772,"sourceCode":"     * Prints read and write replica placements for a specific keyspace, sorted by token range.\n     * Requires the {@code -ks} option to specify the target keyspace.\n     */\n    @Command(name = \"printdataplacements\", description = \"Prints data placements in cluster metadata file.\")\n    static class PrintDataPlacements extends ClusterMetadataToolCmd\n    {\n        @Option(names = { \"-ks\", \"--keyspace\" }, required = true,\n        description = \"Keyspace to use for printing data placements.\")\n        private String keyspace;\n\n        @Override\n        protected void execute(Output output) throws IOException\n        {\n            ClusterMetadata metadata = parseClusterMetadata();\n\n            KeyspaceMetadata keyspaceMetadata = metadata.schema.getKeyspaces().getNullable(keyspace);\n            if (keyspaceMetadata == null)\n            {\n                throw new IllegalArgumentException(\"Keyspace \" + keyspace + \" not found in cluster metadata.\");\n            }\n\n            DataPlacement placement = metadata.placement(keyspaceMetadata.params.replication);\n            List<Object[]> rows = new ArrayList<>();\n            rows.addAll(replicaGroupsToRows(placement.reads, \"read\"));\n            rows.addAll(replicaGroupsToRows(placement.writes, \"write\"));\n\n            rows.sort((o1, o2) -> {\n                Range<Token> left = (Range<Token>) o1[0];\n                Range<Token> right = (Range<Token>) o2[0];\n                return left.compareTo(right);\n            });\n\n            int rangeMaxLength = 0;\n            for (Object[] objects : rows)\n            {\n                rangeMaxLength = Math.max(rangeMaxLength, objects[0].toString().length());\n            }","sourceCodeStart":754,"sourceCodeEnd":790,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/CMSOfflineTool.java#L754-L790","documentation":"Thrown by the placement/describe subcommand of CMSOfflineTool when the requested keyspace does not exist in metadata.schema.getKeyspaces() of the loaded offline cluster metadata. The tool needs the keyspace's replication params to compute DataPlacement, so an unknown keyspace aborts.","triggerScenarios":"Calling the tool with a --keyspace value absent from the schema in the metadata snapshot: misspelled name, keyspace created after the snapshot, or wrong cluster's metadata file.","commonSituations":"Case-sensitivity mistakes (keyspace names are case-sensitive unless quoted); running against a pre-creation metadata snapshot; typos like 'keyspace1' vs 'ks'.","solutions":["Verify the exact keyspace name (case-sensitive) against metadata.schema.getKeyspaces().","Regenerate the cluster metadata snapshot after the keyspace was created.","Ensure you are pointing the tool at the intended cluster's metadata file."],"exampleFix":"// before\n// cms offline placement --keyspace KeySpace1\n// after\n// cms offline placement --keyspace keyspace1","handlingStrategy":"validation","validationCode":"if (metadata.schema.getKeyspaces().getNullable(keyspace) == null)\n    throw new IllegalArgumentException(\"Keyspace \" + keyspace + \" not in metadata; known: \" + metadata.schema.getKeyspaces().names());","typeGuard":null,"tryCatchPattern":"try { tool.describePlacement(keyspace); } catch (IllegalArgumentException e) { logger.error(\"Keyspace check: \" + e.getMessage()); }","preventionTips":["Verify keyspace names with CQL before running the tool","Respect case sensitivity of keyspace names","Use a metadata snapshot taken after schema changes"],"tags":["cluster-metadata","keyspace","schema","not-found"],"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-14T16:17:12.679Z"}