cxm940188 commented on code in PR #23525:
URL: https://github.com/apache/kafka/pull/23525#discussion_r4067960621
##########
metadata/src/main/java/org/apache/kafka/controller/QuorumController.java:
##########
@@ -915,22 +915,18 @@ static long appendRecords(
// The appender callback will create an in-memory snapshot for
each batch,
// since we might need to revert to any of them. We will only
return the final
// offset of the last batch, however.
- int startIndex = 0, numBatches = 0;
- while (true) {
+ int numBatches = 0;
+ long lastOffset = -1;
+ for (int startIndex = 0; startIndex < records.size();
startIndex += maxRecordsPerBatch) {
numBatches++;
- int endIndex = startIndex + maxRecordsPerBatch;
- if (endIndex > records.size()) {
Review Comment:
Thanks @kevin-wu24 for the review. My current fix is also correct: with the
loop bound `startIndex < records.size()`, the iteration that would append an
empty batch never runs. That said, I agree that checking `endIndex >=
records.size()` makes the final batch explicit and is cleaner, so I'll adopt
your suggestion and keep the source change to a minimum.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]