{"record":{"id":"3fad8a776053e979","repo":"provectus/kafka-ui","slug":"replication-factor-already-equals-requested","errorCode":null,"errorMessage":"Replication factor already equals requested","messagePattern":"Replication factor already equals requested","errorType":"validation","errorClass":"ValidationException","httpStatus":400,"severity":"warning","filePath":"kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/TopicsService.java","lineNumber":349,"sourceCode":"        // Iterate brokers and try to remove them from assignment\n        // while partition replicas count != requested replication factor\n        for (Integer broker : brokersUsageList) {\n          // Check is the broker the leader of partition\n          if (!topic.getPartitions().get(partition).getLeader()\n              .equals(broker)) {\n            brokers.remove(broker);\n            brokersUsage.merge(broker, -1, Integer::sum);\n          }\n          if (brokers.size() == replicationFactorChange.getTotalReplicationFactor()) {\n            break;\n          }\n        }\n        if (brokers.size() != replicationFactorChange.getTotalReplicationFactor()) {\n          throw new ValidationException(\"Something went wrong during removing replicas\");\n        }\n      }\n    } else {\n      throw new ValidationException(\"Replication factor already equals requested\");\n    }\n\n    // Return result map\n    return currentAssignment.entrySet().stream().collect(toMap(\n        e -> new TopicPartition(topic.getName(), e.getKey()),\n        e -> Optional.of(new NewPartitionReassignment(e.getValue()))\n    ));\n  }\n\n  private Map<Integer, List<Integer>> getCurrentAssignment(InternalTopic topic) {\n    return topic.getPartitions().values().stream()\n        .collect(toMap(\n            InternalPartition::getPartition,\n            p -> p.getReplicas().stream()\n                .map(InternalReplica::getBroker)\n                .collect(toList())\n        ));\n  }","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/provectus/kafka-ui/blob/83b5a60cc08501b570a0c4d0b4cdfceb1b88d6b7/kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/TopicsService.java#L331-L367","documentation":"TopicsService.getPartitionsReassignments computes a new partition assignment to change a topic's replication factor. If the topic's current replication factor already equals the requested one, no reassignment is possible or needed, and a ValidationException with 'Replication factor already equals requested' is thrown before any assignment is produced.","triggerScenarios":"Calling the changeReplicationFactor API (PUT topic replication factor) with a target replication factor identical to the topic's current replication factor.","commonSituations":"Re-submitting an already-applied replication factor change; scripted/CI jobs that compute a target factor matching current config; copy-pasted requests using the same factor as the topic.","solutions":["Check the topic's current replication factor before calling the API and only send a different value","Delete the redundant call or make it a no-op when target equals current","Verify the correct topic name was used (a same-factor topic implies no change was intended)","If an increase/decrease was intended, confirm broker count allows the target factor"],"exampleFix":"// before\nint targetFactor = topic.getReplicationFactor(); // equals current\n// after\nint current = describeTopic(topicName).replicationFactor();\nint targetFactor = Math.min(current + 1, brokers.size());","handlingStrategy":"validation","validationCode":"// Java (caller)\nint current = topicsService.getTopicDetails(cluster, topicName)\n    .getTopicDescription().partitions().get(0).replicas().size();\nif (targetFactor == current) {\n  throw new IllegalArgumentException(\"Replication factor already \" + current + \"; nothing to change\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  topicsService.changeReplicationFactor(cluster, topicName, targetFactor);\n} catch (ValidationException e) {\n  if (e.getMessage().contains(\"already equals requested\")) {\n    log.info(\"No-op: replication factor already {}\", targetFactor); // treat as success\n  } else { throw e; }\n}","preventionTips":["Fetch current topic config before submitting a replication factor change","Treat 'already equals requested' as an idempotent success in automation","Clamp target factor between 1 and broker count","Avoid re-submitting the same change after retries — check state first"],"tags":["kafka","validation","replication-factor","topic-config"],"backgroundTag":"invalid-state-transition","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"}