{"record":{"id":"c3d9faa1c9eff194","repo":"apache/cassandra","slug":"cannot-combine-dc-and-hosts-options","errorCode":null,"errorMessage":"Cannot combine -dc and -hosts options.","messagePattern":"Cannot combine -dc and -hosts options\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/repair/messages/RepairOption.java","lineNumber":287,"sourceCode":"        if (cfStr != null)\n        {\n            Collection<String> columnFamilies = new HashSet<>();\n            StringTokenizer tokenizer = new StringTokenizer(cfStr, \",\");\n            while (tokenizer.hasMoreTokens())\n            {\n                columnFamilies.add(tokenizer.nextToken().trim());\n            }\n            option.getColumnFamilies().addAll(columnFamilies);\n        }\n\n        // validate options\n        if (jobThreads > MAX_JOB_THREADS)\n        {\n            throw new IllegalArgumentException(\"Too many job threads. Max is \" + MAX_JOB_THREADS);\n        }\n        if (!dataCenters.isEmpty() && !hosts.isEmpty())\n        {\n            throw new IllegalArgumentException(\"Cannot combine -dc and -hosts options.\");\n        }\n        if (primaryRange && ((!dataCenters.isEmpty() && !option.isInLocalDCOnly()) || !hosts.isEmpty()))\n        {\n            throw new IllegalArgumentException(\"You need to run primary range repair on all nodes in the cluster.\");\n        }\n        if (pullRepair)\n        {\n            if (hosts.size() != 2)\n            {\n                throw new IllegalArgumentException(\"Pull repair can only be performed between two hosts. Please specify two hosts, one of which must be this host.\");\n            }\n            else if (ranges.isEmpty())\n            {\n                throw new IllegalArgumentException(\"Token ranges must be specified when performing pull repair. Please specify at least one token range which both hosts have in common.\");\n            }\n        }\n\n        return option;","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/repair/messages/RepairOption.java#L269-L305","documentation":"RepairOption.parse rejects repair requests that specify both datacenter and host restrictions. A repair is scoped either by datacenters or by explicit hosts, never both, so supplying both -dc and -hosts is treated as a contradictory request. IllegalArgumentException is thrown before the repair starts.","triggerScenarios":"nodetool repair -dc dc1 -hosts 127.0.0.1 (or RepairOption.parse with options containing both DATACENTERS and HOSTS entries non-empty).","commonSituations":"Scripts accumulated flags over time; operators combining a DC filter with a specific endpoint to 'narrow further'; copy-paste from two different runbooks.","solutions":["Use only -hosts when targeting specific nodes","Use only -dc when scoping the repair to whole datacenters","Remove one of the two flags in your script/config"],"exampleFix":"// before\nnodetool repair -dc dc1 -hosts 10.0.0.1 keyspace1\n// after\nnodetool repair -dc dc1 keyspace1","handlingStrategy":"validation","validationCode":"if (dcList != null && !dcList.isEmpty() && hostList != null && !hostList.isEmpty())\n    throw new IllegalArgumentException(\"Specify either -dc or -hosts for repair, not both\");","typeGuard":null,"tryCatchPattern":"try { RepairOption.parse(opts); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Cannot combine -dc and -hosts\")) { /* drop one scope and re-invoke */ } else throw e; }","preventionTips":["Let repair scripts accept a single 'scope' parameter that maps to either -dc or -hosts","Audit shared repair scripts for accumulated flags","Document scoping semantics in runbooks"],"tags":["repair","cli","conflicting-options"],"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-14T16:17:12.679Z"}