chia7712 commented on code in PR #19214:
URL: https://github.com/apache/kafka/pull/19214#discussion_r1999450816


##########
clients/src/main/java/org/apache/kafka/common/record/FileRecords.java:
##########
@@ -298,11 +298,28 @@ public int writeTo(TransferableChannel destChannel, int 
offset, int length) thro
      * @return the batch's base offset, its physical position, and its size 
(including log overhead)
      */
     public LogOffsetPosition searchForOffsetWithSize(long targetOffset, int 
startingPosition) {
+        FileChannelRecordBatch prevBatch = null;
+
         for (FileChannelRecordBatch batch : batchesFrom(startingPosition)) {
-            long offset = batch.lastOffset();
-            if (offset >= targetOffset)
-                return new LogOffsetPosition(batch.baseOffset(), 
batch.position(), batch.sizeInBytes());
+            // This indicates that either the current batch or the previous 
batch 
+            // contains the target we are looking for.
+            if (batch.baseOffset() >= targetOffset) {

Review Comment:
   @m1a2st it appears the previous version provided greater clarity and 
optimization. Hence, please add the case `if (batch.baseOffset() == 
targetOffset) ` back.



-- 
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]

Reply via email to