apache/cassandra · error · InvalidRequestException

Can not create a keyspace with MetaReplicationStrategy

Error message

Can not create a keyspace with MetaReplicationStrategy

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateKeyspaceStatement.java:107

            if (ifNotExists)
                return schema;

            throw new AlreadyExistsException(keyspaceName);
        }

        // we deduplicate ReplicationParams here to use the same objects in KeyspaceMetadata
        // as we have as keys in metadata.placements to have a fast map lookup
        // ReplicationParams are immutable, so it is a safe optimization
        KeyspaceParams keyspaceParams = attrs.asNewKeyspaceParams();
        ReplicationParams replicationParams = metadata.placements().deduplicateReplicationParams(keyspaceParams.replication);
        keyspaceParams = keyspaceParams.withSwapped(replicationParams);
        KeyspaceMetadata keyspaceMetadata = KeyspaceMetadata.create(keyspaceName, keyspaceParams);

        if (keyspaceMetadata.params.replication.klass.equals(LocalStrategy.class))
            throw ire("Unable to use given strategy class: LocalStrategy is reserved for internal use.");

        if (keyspaceMetadata.params.replication.isMeta())
            throw ire("Can not create a keyspace with MetaReplicationStrategy");

        keyspaceMetadata.params.validate(keyspaceName, state, metadata);
        keyspaceMetadata.replicationStrategy.validateExpectedOptions(metadata);

        expandedCql = keyspaceMetadata.toCqlString(false, true, ifNotExists);
        verifyExpandedCql(expandedCql);
        return schema.withAddedOrUpdated(keyspaceMetadata);
    }

    SchemaChange schemaChangeEvent(KeyspacesDiff diff)
    {
        return new SchemaChange(Change.CREATED, keyspaceName);
    }

    public void authorize(ClientState client)
    {
        client.ensureAllKeyspacesPermission(Permission.CREATE);
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Use SimpleStrategy or NetworkTopologyStrategy for user keyspaces.
  2. Remove the MetaStrategy class from the replication map and pick a supported strategy.
  3. Do not attempt to create keyspaces mirroring internal metadata replication; let Cassandra manage those.

Example fix

// before
CREATE KEYSPACE ks WITH replication = {'class': 'org.apache.cassandra.locator.MetaStrategy'};

// after
CREATE KEYSPACE ks WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': 3};
Defensive patterns

Strategy: validation

Validate before calling

String cls = extractReplicationClass(cql); if (cls != null && cls.endsWith("MetaStrategy")) throw new IllegalArgumentException("MetaStrategy cannot be used for user keyspaces");

Try / catch

try { session.execute(ddl); } catch (InvalidQueryException e) { if (e.getMessage().contains("MetaReplicationStrategy")) { /* use a supported strategy */ } else throw e; }

Prevention

When it happens

Trigger: `CREATE KEYSPACE ks WITH replication = {'class': 'org.apache.cassandra.locator.MetaStrategy'};` (or a subclass) — keyspaceMetadata.params.replication.isMeta() returns true in apply().

Common situations: Attempting to replicate the internal metadata keyspaces manually; copying replication configs out of internal schema/metadata keyspaces; experimentation with internal locator classes.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/0ee53f60a5a84522. Report an issue: GitHub.