Skip to content

Commit cdf025f

Browse files
committed
refactor: address PR review feedback
Remove redundant RF validation and fix field naming consistency
1 parent 7275088 commit cdf025f

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

e2e/partition_planner.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ func (p *PartitionPlanner) Plan(meta *kmsg.MetadataResponse) (*Plan, error) {
4848
if len(meta.Brokers) == 0 {
4949
return nil, fmt.Errorf("metadata response has no brokers")
5050
}
51-
if p.cfg.ReplicationFactor < 1 {
52-
return nil, fmt.Errorf("replication factor must be >= 1 (got %d)", p.cfg.ReplicationFactor)
53-
}
5451
if p.cfg.ReplicationFactor > len(meta.Brokers) {
5552
return nil, fmt.Errorf("replication factor %d exceeds available brokers %d", p.cfg.ReplicationFactor, len(meta.Brokers))
5653
}
@@ -122,8 +119,8 @@ type PlanBuilder struct {
122119
// view is our predictive map: partitionID -> replicas (preferred leader at idx 0)
123120
view map[int32][]int32
124121

125-
reassign []Reassignment // staged reassignments for existing partitions
126-
creates []CreateAssignment // staged creations of new partitions
122+
reassignments []Reassignment // staged reassignments for existing partitions
123+
creations []CreateAssignment // staged creations of new partitions
127124
}
128125

129126
// Reassignment captures a single partition’s new replica list.
@@ -169,22 +166,22 @@ func NewPlanBuilder(state ClusterState, desired Desired, tracker *LoadTracker) *
169166
// partition count as current + number of creates.
170167
func (b *PlanBuilder) Build() *Plan {
171168
return &Plan{
172-
Reassignments: b.reassign,
173-
CreateAssignments: b.creates,
174-
FinalPartitionCount: len(b.state.Partitions) + len(b.creates),
169+
Reassignments: b.reassignments,
170+
CreateAssignments: b.creations,
171+
FinalPartitionCount: len(b.state.Partitions) + len(b.creations),
175172
}
176173
}
177174

178175
// CommitReassignment records a reassignment and updates the predictive view.
179176
func (b *PlanBuilder) CommitReassignment(pid int32, reps []int32) {
180-
b.reassign = append(b.reassign, Reassignment{Partition: pid, Replicas: reps})
177+
b.reassignments = append(b.reassignments, Reassignment{Partition: pid, Replicas: reps})
181178
b.view[pid] = reps
182179
}
183180

184181
// CommitCreate records a new-partition assignment. The final partition count is
185182
// computed when building the Plan.
186183
func (b *PlanBuilder) CommitCreate(reps []int32) {
187-
b.creates = append(b.creates, CreateAssignment{Replicas: reps})
184+
b.creations = append(b.creations, CreateAssignment{Replicas: reps})
188185
}
189186

190187
// fixReplicationAndRack enforces configured RF on each existing partition
@@ -407,7 +404,7 @@ func ensureLeaderCoverage(b *PlanBuilder, sel ReplicaSelector) {
407404
b.CommitCreate(reps)
408405

409406
// Track a synthetic partition ID so counts stay consistent within this loop.
410-
newPID := int32(len(b.state.Partitions) + len(b.creates) - 1)
407+
newPID := int32(len(b.state.Partitions) + len(b.creations) - 1)
411408
leadersByBroker[target] = append(leadersByBroker[target], newPID)
412409
}
413410
}
@@ -421,7 +418,7 @@ func ensureLeaderCoverage(b *PlanBuilder, sel ReplicaSelector) {
421418
// the fewest partitions (stable tie-breaker via leastLoadedLeader).
422419
func ensurePartitionCount(b *PlanBuilder, sel ReplicaSelector) {
423420
desiredTotal := b.desired.DesiredPartitions
424-
total := len(b.state.Partitions) + len(b.creates)
421+
total := len(b.state.Partitions) + len(b.creations)
425422
if total >= desiredTotal || len(b.state.BrokerIDs) == 0 {
426423
return
427424
}
@@ -434,7 +431,7 @@ func ensurePartitionCount(b *PlanBuilder, sel ReplicaSelector) {
434431
}
435432
}
436433
// Also include leaders from staged creates (from phase 2 and any prior adds)
437-
for _, ca := range b.creates {
434+
for _, ca := range b.creations {
438435
if len(ca.Replicas) > 0 {
439436
leaderCount[ca.Replicas[0]]++
440437
}

0 commit comments

Comments
 (0)