andymg3 opened a new pull request, #13788:
URL: https://github.com/apache/kafka/pull/13788

   ### JIRA
   https://issues.apache.org/jira/browse/KAFKA-14791
   
   ### Description
   This creates a builder for `PartitionRegistration`. The motivation for the 
builder is that the constructor of `PartitionRegistration` has four arguments 
all of type `int[]` which makes it easy to make a mistake when using it. Right 
now the constructor has the signature:
   ```
   public PartitionRegistration(int[] replicas, int[] isr, int[] 
removingReplicas,
                                int[] addingReplicas, int leader, 
LeaderRecoveryState leaderRecoveryState,
                                int leaderEpoch, int partitionEpoch) {
   ```
   It's easy to mix up any of `replicas`, `isr`, `removingReplicas` and 
`addingReplicas`. 
   
   With this change the constructor is made `protected` so only code in the 
same package can use it, which is helpful for unit testing. All other code must 
use the builder. The code will look like:
   ```
                       partitionRegistration = new 
PartitionRegistration.Builder().
                           
setReplicas(Replicas.toArray(assignment.brokerIds())).
                           setIsr(Replicas.toArray(isr)).
                           setRemovingReplicas(Replicas.NONE).
                           setAddingReplicas(Replicas.NONE).
                           setLeader(isr.get(0)).
                           
setLeaderRecoveryState(LeaderRecoveryState.RECOVERED).
                           setLeaderEpoch(0).
                           setPartitionEpoch(0).
                           build();
   ```
   This makes it less likely to make a mistake when setting any of `replicas`, 
`isr`, `removingReplicas` and `addingReplicas`. 
   
   ### Testing
   This updates all the unit tests to use the new builder. This also adds unit 
tests to `PartitionRegistrationTest` testing the builder's validation and 
object constructions.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to