{"record":{"id":"7ac0456d2ca0cd9b","repo":"apache/cassandra","slug":"configuration-for-at-least-one-datacenter-must-be","errorCode":null,"errorMessage":"Configuration for at least one datacenter must be present","messagePattern":"Configuration for at least one datacenter must be present","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/locator/NetworkTopologyStrategy.java","lineNumber":356,"sourceCode":"                           .forEach(e -> options.putIfAbsent(e.getKey(), e.getValue()));\n        }\n\n        if (replication != null) {\n            ReplicationFactor defaultReplicas = ReplicationFactor.fromString(replication);\n            Datacenters.getValidDatacenters(ClusterMetadata.current())\n                       .forEach(dc -> options.putIfAbsent(dc, defaultReplicas.toParseableString()));\n        }\n\n        options.values().removeAll(Collections.singleton(\"0\"));\n    }\n\n    @Override\n    public void validateExpectedOptions(ClusterMetadata metadata) throws ConfigurationException\n    {\n        // Do not accept query with no data centers specified.\n        if (this.configOptions.isEmpty())\n        {\n            throw new ConfigurationException(\"Configuration for at least one datacenter must be present\");\n        }\n\n        // Validate the data center names\n        super.validateExpectedOptions(metadata);\n\n        if (keyspaceName.equalsIgnoreCase(SchemaConstants.AUTH_KEYSPACE_NAME))\n        {\n            Set<String> differenceSet = Sets.difference(metadata.directory.knownDatacenters(), configOptions.keySet());\n            if (!differenceSet.isEmpty())\n            {\n                throw new ConfigurationException(\"Following datacenters have active nodes and must be present in replication options for keyspace \" + SchemaConstants.AUTH_KEYSPACE_NAME + \": \" + differenceSet.toString());\n            }\n        }\n        logger.info(\"Configured datacenter replicas are {}\", FBUtilities.toString(datacenters));\n    }\n\n    @Override\n    public void validateOptions() throws ConfigurationException","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/locator/NetworkTopologyStrategy.java#L338-L374","documentation":"NetworkTopologyStrategy requires at least one datacenter option because replication is defined per DC. validateExpectedOptions rejects an empty options map with this ConfigurationException, so a keyspace cannot be created/validated with zero datacenter configuration.","triggerScenarios":"validateExpectedOptions is invoked (keyspace creation/alter or query validation) and this.configOptions is empty — e.g. replication = {'class':'NetworkTopologyStrategy'} with no DC entries.","commonSituations":"CREATE KEYSPACE statement with the strategy class but no DC arguments; ALTER TABLE dropping all DC options; templating tools rendering an empty DC list; drivers building the replication map dynamically from an empty collection.","solutions":["Add at least one datacenter with its replication factor: {'class':'NetworkTopologyStrategy','dc1':'3'}","List datacenters via SELECT * FROM system.local (or nodetool status) to get correct DC names","Fix templating/tooling so the DC options collection is non-empty before rendering the CREATE statement","Use SimpleStrategy temporarily only for single-node dev clusters, not production"],"exampleFix":"// before\nCREATE KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy'};\n// after\nCREATE KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy','datacenter1':'3'};","handlingStrategy":"validation","validationCode":"Map<String,String> opts = replicationOptions;\nif (\"NetworkTopologyStrategy\".equals(opts.getOrDefault(\"class\",\"\")) && opts.size() <= 1) throw new IllegalArgumentException(\"Specify at least one datacenter with replication factor\");","typeGuard":null,"tryCatchPattern":"try { session.execute(createKs); }\ncatch (InvalidQueryException e) { /* add per-DC options and retry */ }","preventionTips":["Always enumerate DC names (nodetool status / system.peers) before defining keyspaces","Make schema templates fail fast when the DC list is empty","Include a required-DCs check in schema CI pipelines"],"tags":["cql","replication","schema","networktopologystrategy","validation"],"backgroundTag":"missing-required-config-field","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"}