satishd commented on code in PR #15213:
URL: https://github.com/apache/kafka/pull/15213#discussion_r1481778242


##########
core/src/main/scala/kafka/log/UnifiedLog.scala:
##########
@@ -1300,18 +1301,29 @@ class UnifiedLog(@volatile var logStartOffset: Long,
       } else if (targetTimestamp == 
ListOffsetsRequest.EARLIEST_LOCAL_TIMESTAMP) {
         val curLocalLogStartOffset = localLogStartOffset()
 
-        val earliestLocalLogEpochEntry = leaderEpochCache.asJava.flatMap(cache 
=> {
-          val epoch = cache.epochForOffset(curLocalLogStartOffset)
-          if (epoch.isPresent) cache.epochEntry(epoch.getAsInt) else 
Optional.empty[EpochEntry]()
-        })
-
-        val epochOpt = if (earliestLocalLogEpochEntry.isPresent && 
earliestLocalLogEpochEntry.get().startOffset <= curLocalLogStartOffset)
-          Optional.of[Integer](earliestLocalLogEpochEntry.get().epoch)
-        else Optional.empty[Integer]()
+        var epochResult: Optional[Integer] = Optional.empty()
+        if (leaderEpochCache.isDefined) {
+          val epochOpt = 
leaderEpochCache.get.epochForOffset(curLocalLogStartOffset)
+          if (epochOpt.isPresent) epochResult = Optional.of(epochOpt.getAsInt)
+        }
 
-        Some(new TimestampAndOffset(RecordBatch.NO_TIMESTAMP, 
curLocalLogStartOffset, epochOpt))
+        Some(new TimestampAndOffset(RecordBatch.NO_TIMESTAMP, 
curLocalLogStartOffset, epochResult))
       } else if (targetTimestamp == ListOffsetsRequest.LATEST_TIMESTAMP) {
         Some(new TimestampAndOffset(RecordBatch.NO_TIMESTAMP, logEndOffset, 
latestEpochAsOptional(leaderEpochCache)))
+      } else if (targetTimestamp == 
ListOffsetsRequest.LATEST_TIERED_TIMESTAMP) {
+        if (remoteLogEnabled()) {
+          val curHighestRemoteOffset = highestOffsetInRemoteStorage()
+
+          var epochResult: Optional[Integer] = if (curHighestRemoteOffset == 
-1) Optional.of(RecordBatch.NO_PARTITION_LEADER_EPOCH) else Optional.empty()

Review Comment:
   Can we use `val` instead of `var` here?
   
   ```
   val epochResult: Optional[Integer] =
               if (leaderEpochCache.isDefined) {
                 val epochOpt = 
leaderEpochCache.get.epochForOffset(curHighestRemoteOffset)
                 if (epochOpt.isPresent) Optional.of(epochOpt.getAsInt) else 
Optional.of(RecordBatch.NO_PARTITION_LEADER_EPOCH)
               } else Optional.of(RecordBatch.NO_PARTITION_LEADER_EPOCH)
   ```



##########
core/src/main/scala/kafka/log/UnifiedLog.scala:
##########
@@ -1300,18 +1301,29 @@ class UnifiedLog(@volatile var logStartOffset: Long,
       } else if (targetTimestamp == 
ListOffsetsRequest.EARLIEST_LOCAL_TIMESTAMP) {
         val curLocalLogStartOffset = localLogStartOffset()
 
-        val earliestLocalLogEpochEntry = leaderEpochCache.asJava.flatMap(cache 
=> {
-          val epoch = cache.epochForOffset(curLocalLogStartOffset)
-          if (epoch.isPresent) cache.epochEntry(epoch.getAsInt) else 
Optional.empty[EpochEntry]()
-        })
-
-        val epochOpt = if (earliestLocalLogEpochEntry.isPresent && 
earliestLocalLogEpochEntry.get().startOffset <= curLocalLogStartOffset)
-          Optional.of[Integer](earliestLocalLogEpochEntry.get().epoch)
-        else Optional.empty[Integer]()
+        var epochResult: Optional[Integer] = Optional.empty()

Review Comment:
   Can we use `val` instead of `var` here?
   
   ```
           val epochResult: Optional[Integer] =
             if (leaderEpochCache.isDefined) {
               val epochOpt = 
leaderEpochCache.get.epochForOffset(curLocalLogStartOffset)
               if (epochOpt.isPresent) Optional.of(epochOpt.getAsInt) else 
Optional.of(RecordBatch.NO_PARTITION_LEADER_EPOCH)
             } else Optional.of(RecordBatch.NO_PARTITION_LEADER_EPOCH)
   
   ``` 



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