{"record":{"id":"0ee53f60a5a84522","repo":"apache/cassandra","slug":"can-not-create-a-keyspace-with-metareplicationstra","errorCode":null,"errorMessage":"Can not create a keyspace with MetaReplicationStrategy","messagePattern":"Can not create a keyspace with MetaReplicationStrategy","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateKeyspaceStatement.java","lineNumber":107,"sourceCode":"            if (ifNotExists)\n                return schema;\n\n            throw new AlreadyExistsException(keyspaceName);\n        }\n\n        // we deduplicate ReplicationParams here to use the same objects in KeyspaceMetadata\n        // as we have as keys in metadata.placements to have a fast map lookup\n        // ReplicationParams are immutable, so it is a safe optimization\n        KeyspaceParams keyspaceParams = attrs.asNewKeyspaceParams();\n        ReplicationParams replicationParams = metadata.placements().deduplicateReplicationParams(keyspaceParams.replication);\n        keyspaceParams = keyspaceParams.withSwapped(replicationParams);\n        KeyspaceMetadata keyspaceMetadata = KeyspaceMetadata.create(keyspaceName, keyspaceParams);\n\n        if (keyspaceMetadata.params.replication.klass.equals(LocalStrategy.class))\n            throw ire(\"Unable to use given strategy class: LocalStrategy is reserved for internal use.\");\n\n        if (keyspaceMetadata.params.replication.isMeta())\n            throw ire(\"Can not create a keyspace with MetaReplicationStrategy\");\n\n        keyspaceMetadata.params.validate(keyspaceName, state, metadata);\n        keyspaceMetadata.replicationStrategy.validateExpectedOptions(metadata);\n\n        expandedCql = keyspaceMetadata.toCqlString(false, true, ifNotExists);\n        verifyExpandedCql(expandedCql);\n        return schema.withAddedOrUpdated(keyspaceMetadata);\n    }\n\n    SchemaChange schemaChangeEvent(KeyspacesDiff diff)\n    {\n        return new SchemaChange(Change.CREATED, keyspaceName);\n    }\n\n    public void authorize(ClientState client)\n    {\n        client.ensureAllKeyspacesPermission(Permission.CREATE);\n    }","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateKeyspaceStatement.java#L89-L125","documentation":"MetaReplicationStrategy (used for coordinated system metadata keyspaces) cannot be assigned to a user-created keyspace. CREATE KEYSPACE rejects any replication params that resolve to the meta replication strategy.","triggerScenarios":"`CREATE KEYSPACE ks WITH replication = {'class': 'org.apache.cassandra.locator.MetaStrategy'};` (or a subclass) — keyspaceMetadata.params.replication.isMeta() returns true in apply().","commonSituations":"Attempting to replicate the internal metadata keyspaces manually; copying replication configs out of internal schema/metadata keyspaces; experimentation with internal locator classes.","solutions":["Use SimpleStrategy or NetworkTopologyStrategy for user keyspaces.","Remove the MetaStrategy class from the replication map and pick a supported strategy.","Do not attempt to create keyspaces mirroring internal metadata replication; let Cassandra manage those."],"exampleFix":"// before\nCREATE KEYSPACE ks WITH replication = {'class': 'org.apache.cassandra.locator.MetaStrategy'};\n\n// after\nCREATE KEYSPACE ks WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': 3};","handlingStrategy":"validation","validationCode":"String cls = extractReplicationClass(cql); if (cls != null && cls.endsWith(\"MetaStrategy\")) throw new IllegalArgumentException(\"MetaStrategy cannot be used for user keyspaces\");","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (InvalidQueryException e) { if (e.getMessage().contains(\"MetaReplicationStrategy\")) { /* use a supported strategy */ } else throw e; }","preventionTips":["Restrict replication strategy classes in DDL tooling to public ones","Do not mirror internal metadata keyspace configs","Code-review any replication config lifted from system keyspaces"],"tags":["cassandra","cql","keyspace","replication","internal"],"backgroundTag":"invalid-enum-value","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"}