{"record":{"id":"39a5ca8b18fcce70","repo":"apache/cassandra","slug":"cannot-set-source-data-center-to-be-local-data-cen","errorCode":null,"errorMessage":"Cannot set source data center to be local data center, when excludeLocalDataCenter flag is set","messagePattern":"Cannot set source data center to be local data center, when excludeLocalDataCenter flag is set","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/Rebuild.java","lineNumber":86,"sourceCode":"\n    @VisibleForTesting\n    public static void unsafeResetRebuilding()\n    {\n        isRebuilding.set(false);\n    }\n\n    public static void rebuild(String sourceDc, String keyspace, String tokens, String specificSources, boolean excludeLocalDatacenterNodes)\n    {\n        // check ongoing rebuild\n        if (!isRebuilding.compareAndSet(false, true))\n        {\n            throw new IllegalStateException(\"Node is still rebuilding. Check nodetool netstats.\");\n        }\n\n        if (sourceDc != null)\n        {\n            if (sourceDc.equals(DatabaseDescriptor.getLocalDataCenter()) && excludeLocalDatacenterNodes) // fail if source DC is local and --exclude-local-dc is set\n                throw new IllegalArgumentException(\"Cannot set source data center to be local data center, when excludeLocalDataCenter flag is set\");\n            Set<String> availableDCs = ClusterMetadata.current().directory.knownDatacenters();\n            if (!availableDCs.contains(sourceDc))\n            {\n                throw new IllegalArgumentException(String.format(\"Provided datacenter '%s' is not a valid datacenter, available datacenters are: %s\",\n                                                                 sourceDc, String.join(\",\", availableDCs)));\n            }\n        }\n\n        try\n        {\n            // check the arguments\n            if (keyspace == null && tokens != null)\n            {\n                throw new IllegalArgumentException(\"Cannot specify tokens without keyspace.\");\n            }\n\n            logger.info(\"rebuild from dc: {}, {}, {}\", sourceDc == null ? \"(any dc)\" : sourceDc,\n                        keyspace == null ? \"(All keyspaces)\" : keyspace,","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/Rebuild.java#L68-L104","documentation":"rebuild validates that when the --exclude-local-datacenter flag is set, the chosen source DC must not equal the local data center, since excluding local DC nodes leaves no possible sources if the source is the local DC itself.","triggerScenarios":"Calling rebuild(sourceDc=X, ..., excludeLocalDatacenterNodes=true) where X equals DatabaseDescriptor.getLocalDataCenter().","commonSituations":"Operator runs `nodetool rebuild --exlude-local-dc` (or -dl) and still passes the local DC as source; copy-pasted runbook command with wrong DC name; misconfigured local data center in cassandra-rackdc.properties so the 'remote' DC name matches local.","solutions":["Omit the sourceDc argument so rebuild picks a non-local DC automatically","Pass a source DC different from the local data center","Remove the --exclude-local-datacenter flag if streaming from the local DC is actually intended"],"exampleFix":"// before\nnodetool rebuild --exlude-local-dc dc1\ndc1\n// after (source must differ from local DC)\nnodetool rebuild -- dc2","handlingStrategy":"validation","validationCode":"String local = DatabaseDescriptor.getLocalDataCenter();\nif (excludeLocalDc && sourceDc != null && sourceDc.equals(local))\n    throw new IllegalArgumentException(\"sourceDc must differ from local DC when excludeLocalDatacenterNodes=true\");","typeGuard":null,"tryCatchPattern":"try { rebuild(sourceDc, ..., true); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"excludeLocalDataCenter\")) rebuild(null, ...); else throw e; }","preventionTips":["Never combine --exclude-local-datacenter with an explicit source DC equal to the local DC","Verify cassandra-rackdc.properties local_dc value matches the DC name you pass","Prefer omitting sourceDc and letting rebuild pick a remote DC automatically"],"tags":["configuration","rebuild","validation"],"backgroundTag":"conflicting-config-options","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}