apoorvmittal10 commented on code in PR #17322:
URL: https://github.com/apache/kafka/pull/17322#discussion_r1808343973


##########
core/src/main/java/kafka/server/share/SharePartition.java:
##########
@@ -1658,6 +1706,26 @@ private long findLastOffsetAcknowledged() {
         return lastOffsetAcknowledged;
     }
 
+    /**
+     * Find the last offset from the batch which contains the request offset. 
If found, return the last offset
+     * of the batch, otherwise return the request offset.
+     *
+     * @param batches The batches to search for the request offset.
+     * @param offset The request offset to find.
+     * @return The last offset of the batch which contains the request offset, 
otherwise the request offset.
+     */
+    private long findLastOffsetFromBatchWithRequestOffset(
+        Iterable<? extends RecordBatch> batches,
+        long offset
+    ) {
+        for (RecordBatch batch : batches) {
+            if (offset >= batch.baseOffset() && offset <= batch.lastOffset()) {

Review Comment:
   That's a great suggestion.
   
   Just for my understanding, I was wondering if really `lastOffset` call does 
additional loading i.e looking at implementation of DefaultRecordBatch it seems 
lastOffset is just getting additional information from already loaded buffer. I 
might be missing something, hence can you please help me learn more so I can 
optimize code at other places as well.



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