{"record":{"id":"d21c8b5788461565","repo":"apache/cassandra","slug":"you-need-to-run-primary-range-repair-on-all-nodes-d21c8b","errorCode":null,"errorMessage":"You need to run primary range repair on all nodes in the cluster.","messagePattern":"You need to run primary range repair on all nodes in the cluster\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/StorageService.java","lineNumber":3161,"sourceCode":"        RepairOption option = RepairOption.parse(repairSpec, partitioner);\n        return repair(keyspace, option, listeners);\n    }\n\n    public Pair<Integer, Future<?>> repair(String keyspace, RepairOption option, List<ProgressListener> listeners)\n    {\n        // if ranges are not specified\n        if (option.getRanges().isEmpty())\n        {\n            if (option.isPrimaryRange())\n            {\n                // when repairing only primary range, neither dataCenters nor hosts can be set\n                if (option.getDataCenters().isEmpty() && option.getHosts().isEmpty())\n                    option.getRanges().addAll(getPrimaryRanges(keyspace));\n                    // except dataCenters only contain local DC (i.e. -local)\n                else if (option.isInLocalDCOnly())\n                    option.getRanges().addAll(getPrimaryRangesWithinDC(keyspace));\n                else\n                    throw new IllegalArgumentException(\"You need to run primary range repair on all nodes in the cluster.\");\n            }\n            else\n            {\n                Iterables.addAll(option.getRanges(), getLocalReplicas(keyspace).onlyFull().ranges());\n            }\n        }\n        if (option.getRanges().isEmpty() || Keyspace.open(keyspace).getReplicationStrategy().getReplicationFactor().allReplicas < 2)\n            return Pair.create(0, ImmediateFuture.success(null));\n\n        int cmd = nextRepairCommand.incrementAndGet();\n        return Pair.create(cmd, repairCommandExecutor().submit(createRepairTask(cmd, keyspace, option, listeners)));\n    }\n\n    /**\n     * Create collection of ranges that match ring layout from given tokens.\n     *\n     * @param beginToken beginning token of the range\n     * @param endToken end token of the range","sourceCodeStart":3143,"sourceCodeEnd":3179,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/StorageService.java#L3143-L3179","documentation":"When a repair is requested with -pr (primary ranges) and the option neither specifies datacenters nor hosts, the node must compute the primary ranges for the whole cluster; if the request is restricted to the local DC only (inLocalDCOnly) the full-cluster primary range set cannot be derived, so IllegalArgumentException is thrown. Effectively, -local and -pr are incompatible in this path.","triggerScenarios":"Invoking `nodetool repair -pr -local <keyspace>` or calling StorageService.repairAsync with RepairOption where isPrimaryRange()=true, isInLocalDCOnly()=true, and datacenters/hosts are empty.","commonSituations":"Operator combining -pr with -local in nodetool scripts assuming they compose; migrating old repair scripts to newer Cassandra versions where option validation tightened.","solutions":["Remove -local when using -pr (run primary-range repair cluster-wide, on all nodes)","Or drop -pr and keep -local to repair all ranges in the local DC","Or use -pr with explicit -dc list including the local DC"],"exampleFix":"// before\nnodetool repair -pr -local my_keyspace\n// after\nnodetool repair -pr my_keyspace   # run on every node, no -local","handlingStrategy":"validation","validationCode":"RepairOption opt = RepairOption.parse(...);\nif (opt.isPrimaryRange() && opt.isInLocalDCOnly())\n    throw new IllegalArgumentException(\"-pr and -local cannot be combined\");","typeGuard":null,"tryCatchPattern":"try { ss.repairAsync(ks, opt); } catch (IllegalArgumentException e) { /* adjust repair flags */ }","preventionTips":["Audit nodetool scripts for combined -pr -local flags","Run primary-range repair on every node without -local","Prefer subrange repairs with explicit -dc instead of flag combinations"],"tags":["cassandra","repair","nodetool","incompatible-options"],"backgroundTag":"mutually-exclusive-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"}