{"record":{"id":"964f1c8f82587d8b","repo":"apache/cassandra","slug":"can-not-alter-a-keyspace-to-use-metareplicationstr","errorCode":null,"errorMessage":"Can not alter a keyspace to use MetaReplicationStrategy","messagePattern":"Can not alter a keyspace to use MetaReplicationStrategy","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/AlterKeyspaceStatement.java","lineNumber":98,"sourceCode":"    {\n        attrs.validate();\n\n        Keyspaces schema = metadata.schema.getKeyspaces();\n        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);\n        if (null == keyspace)\n        {\n            if (!ifExists)\n                throw ire(\"Keyspace '%s' doesn't exist\", keyspaceName);\n            return schema;\n        }\n\n        KeyspaceMetadata newKeyspace = keyspace.withSwapped(attrs.asAlteredKeyspaceParams(keyspace.params));\n\n        if (attrs.getReplicationStrategyClass() != null && attrs.getReplicationStrategyClass().equals(SimpleStrategy.class.getSimpleName()))\n            Guardrails.simpleStrategyEnabled.ensureEnabled(state);\n\n        if (keyspace.params.replication.isMeta() && !keyspace.name.equals(SchemaConstants.METADATA_KEYSPACE_NAME))\n            throw ire(\"Can not alter a keyspace to use MetaReplicationStrategy\");\n\n        if (newKeyspace.params.replication.klass.equals(LocalStrategy.class))\n            throw ire(\"Unable to use given strategy class: LocalStrategy is reserved for internal use.\");\n\n        newKeyspace.params.validate(keyspaceName, state, metadata);\n        newKeyspace.replicationStrategy.validate(metadata);\n\n        validateNoRangeMovements();\n        validateTransientReplication(keyspace, newKeyspace);\n\n        // Because we used to not properly validate unrecognized options, we only log a warning if we find one.\n        try\n        {\n            newKeyspace.replicationStrategy.validateExpectedOptions(metadata);\n        }\n        catch (ConfigurationException e)\n        {\n            logger.warn(\"Ignoring {}\", e.getMessage());","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/AlterKeyspaceStatement.java#L80-L116","documentation":"The keyspace's current replication strategy is MetaReplicationStrategy, and replication metadata keyspaces may not be altered (except the reserved metadata keyspace itself). apply() rejects the change to prevent users from altering replication of special internal keyspaces that would acquire Meta strategy.","triggerScenarios":"Altering a keyspace whose params.replication.isMeta() is true while its name is not SchemaConstants.METADATA_KEYSPACE_NAME; i.e., attempting to ALTER KEYSPACE on a keyspace using MetaReplicationStrategy.","commonSituations":"Internal/replication-metadata keyspaces targeted by automated migration scripts; confusion over which keyspaces are system-managed.","solutions":["Do not alter keyspaces using MetaReplicationStrategy; they are managed internally","Target a user keyspace with a normal (Simple/NetworkTopology) strategy instead","Verify the keyspace's strategy class before altering"],"exampleFix":"// before\nALTER KEYSPACE meta_ks WITH replication = {'class':'SimpleStrategy','replication_factor':1};\n// after\n// skip meta-strategy keyspaces; alter only user keyspaces\nALTER KEYSPACE user_ks WITH replication = {'class':'NetworkTopologyStrategy','dc1':3};","handlingStrategy":"validation","validationCode":"TableMetadata unused; KeyspaceMetadata ks = cluster.getMetadata().getKeyspace(keyspace); if (ks != null && ks.getReplication() != null && ks.getReplication().containsKey(\"class\") && ks.getReplication().get(\"class\").endsWith(\"MetaReplicationStrategy\")) throw new IllegalStateException(\"meta-strategy keyspace cannot be altered\");","typeGuard":null,"tryCatchPattern":"try { session.execute(alterCql); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"MetaReplicationStrategy\")) { /* skip internal keyspace */ } else throw e; }","preventionTips":["Maintain an allowlist of user keyspaces for migration tooling","Skip keyspaces whose replication class ends in MetaReplicationStrategy or starts with system","Never template internal keyspace settings onto user keyspaces"],"tags":["cql","keyspace","replication","schema"],"backgroundTag":"unsupported-operation","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"}