{"record":{"id":"48c315980ca80d17","repo":"provectus/kafka-ui","slug":"something-went-wrong-during-adding-replicas","errorCode":null,"errorMessage":"Something went wrong during adding replicas","messagePattern":"Something went wrong during adding replicas","errorType":"validation","errorClass":"ValidationException","httpStatus":400,"severity":"error","filePath":"kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/TopicsService.java","lineNumber":315,"sourceCode":"        // Get brokers list sorted by usage\n        var brokers = brokersUsage.entrySet().stream()\n            .sorted(Map.Entry.comparingByValue())\n            .map(Map.Entry::getKey)\n            .collect(toList());\n\n        // Iterate brokers and try to add them in assignment\n        // while partition replicas count != requested replication factor\n        for (Integer broker : brokers) {\n          if (!assignmentList.contains(broker)) {\n            assignmentList.add(broker);\n            brokersUsage.merge(broker, 1, Integer::sum);\n          }\n          if (assignmentList.size() == replicationFactorChange.getTotalReplicationFactor()) {\n            break;\n          }\n        }\n        if (assignmentList.size() != replicationFactorChange.getTotalReplicationFactor()) {\n          throw new ValidationException(\"Something went wrong during adding replicas\");\n        }\n      }\n\n      // If we should to decrease Replication factor\n    } else if (replicationFactorChange.getTotalReplicationFactor() < currentReplicationFactor) {\n      for (Map.Entry<Integer, List<Integer>> assignmentEntry : currentAssignment.entrySet()) {\n        var partition = assignmentEntry.getKey();\n        var brokers = assignmentEntry.getValue();\n\n        // Get brokers list sorted by usage in reverse order\n        var brokersUsageList = brokersUsage.entrySet().stream()\n            .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))\n            .map(Map.Entry::getKey)\n            .collect(toList());\n\n        // Iterate brokers and try to remove them from assignment\n        // while partition replicas count != requested replication factor\n        for (Integer broker : brokersUsageList) {","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/provectus/kafka-ui/blob/83b5a60cc08501b570a0c4d0b4cdfceb1b88d6b7/kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/TopicsService.java#L297-L333","documentation":"TopicsService.getPartitionsReassignments builds new partition replica assignments when increasing a topic's replication factor. It greedily appends brokers from the available list to each partition's assignment; if, after the loop, the assignment list is still smaller than the requested total replication factor, the service cannot satisfy the request (not enough eligible brokers) and throws this ValidationException. It is a guard against producing an incomplete reassignment plan.","triggerScenarios":"PATCHing a topic's replication factor (POST /api/clusters/{cluster}/topics/{name}/replication-factor or changeReplicationFactor) with a totalReplicationFactor larger than the number of eligible brokers available for assignment, or when the broker pool is exhausted mid-assignment (e.g., brokers offline, filtered out, or already holding constrained placements).","commonSituations":"Requesting RF=3 on a cluster with only 2 brokers; brokers marked offline/unhealthy are excluded from candidate assignment; topic with partition constraints (leader placement rules) leaving too few candidate brokers; mixed-version clusters where some brokers are excluded from reassignment.","solutions":["Add more brokers to the cluster or bring offline brokers back so the requested replication factor is satisfiable.","Request a replication factor <= number of healthy brokers.","Verify broker health (GET /api/clusters/{cluster}/brokers) and fix any brokers excluded from assignment.","Check the requested replicationFactorChange payload — ensure totalReplicationFactor is the intended final RF."],"exampleFix":"// before: RF=3 requested on a 2-broker cluster\nPATCH /api/clusters/local/topics/orders\n{ \"totalReplicationFactor\": 3 }\n// after: request a factor the cluster can satisfy\nPATCH /api/clusters/local/topics/orders\n{ \"totalReplicationFactor\": 2 }","handlingStrategy":"validation","validationCode":"const brokers = await fetch(`/api/clusters/${cluster}/brokers`).then(r => r.json());\nif (targetRF > brokers.length) {\n  throw new Error(`Cannot set RF=${targetRF}: cluster has only ${brokers.length} brokers`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await changeReplicationFactor(cluster, topic, { totalReplicationFactor: rf });\n} catch (e) {\n  if (e.message.includes('adding replicas')) {\n    // insufficient healthy brokers — reduce RF or add brokers\n  } else { throw e; }\n}","preventionTips":["Keep the requested replication factor <= number of healthy brokers.","Check broker health before scheduling RF increases in automation.","For RF > broker count, provision additional brokers first."],"tags":["kafka","replication-factor","topic-reassignment","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"83b5a60cc08501b570a0c4d0b4cdfceb1b88d6b7","analyzedAt":"2026-09-08T04:35:39.002Z","contentChangedAt":"2026-09-08T04:35:39.002Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}