kafka/tools/assigner/actions/balancemodules/count.py
Function process_cluster
has a Cognitive Complexity of 105 (exceeds 5 allowed). Consider refactoring. Open
Open
def process_cluster(self):
log.info("Starting partition balance by count")
# Figure out the max RF for the cluster and sort all partition lists by size (ascending)
max_pos = self.cluster.max_replication_factor()
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
Open
if diff == 0:
break
if (pos in target.partitions) and (target.num_partitions_at_position(pos) > (max_count[pos][0] + 1)):
Avoid deeply nested control flow statements. Open
Open
if pos not in source.partitions:
continue
Avoid deeply nested control flow statements. Open
Open
if (pos in target.partitions) and (target.num_partitions_at_position(pos) > (max_count[pos][0] + 1)):
continue
Avoid deeply nested control flow statements. Open
Open
for partition in iterlist:
# If we have moved enough partitions to this broker, exit out of the inner loop
if ((pos in target.partitions) and (target.num_partitions_at_position(pos) >= max_count[pos][0])) or (diff == 0):
break
# Skip partitions that are already on the target broker or are being excluded
Avoid deeply nested control flow statements. Open
Open
for partition in iterlist:
# If we have moved enough partitions from this broker, exit out of the inner loop
if (source.num_partitions_at_position(pos) < max_count[pos][0]) or (diff == 0):
break
Avoid deeply nested control flow statements. Open
Open
if diff == 0:
break
if pos not in source.partitions: