dajac commented on a change in pull request #10960: URL: https://github.com/apache/kafka/pull/10960#discussion_r662991037
########## File path: core/src/main/scala/kafka/log/LogSegment.scala ########## @@ -99,21 +99,22 @@ class LogSegment private[log] (val log: FileRecords, // volatile for LogCleaner to see the update @volatile private var rollingBasedTimestamp: Option[Long] = None + /* The maximum timestamp and offset we see so far */ + @volatile private var _maxTimestampAndOffsetSoFar: (Option[Long], Option[Long]) = (None, None) + def maxTimestampAndOffsetSoFar_= (timestampAndOffset: (Long, Long)) : Unit = _maxTimestampAndOffsetSoFar = (Some(timestampAndOffset._1), Some(timestampAndOffset._2)) + def maxTimestampAndOffsetSoFar: (Long,Long) = { + if (_maxTimestampAndOffsetSoFar._1.isEmpty || _maxTimestampAndOffsetSoFar._2.isEmpty) + _maxTimestampAndOffsetSoFar = (Some(timeIndex.lastEntry.timestamp), Some(timeIndex.lastEntry.offset)) + (_maxTimestampAndOffsetSoFar._1.get, _maxTimestampAndOffsetSoFar._2.get) + } Review comment: Have you considered using a case class instead of `(Option[Long], Option[Long])` here? We could do something like this: ``` case class TimestampAndOffset(timestamp: Long, offset: Long) object TimestampAndOffset { val empty = TimestampAndOffset(RecordBatch.NO_TIMESTAMP, 0L) // Not sure about 0 by default here. } ``` Then, we could define: ``` @volatile private var _maxTimestampAndOffsetSoFar: TimestampAndOffset = TimestampAndOffset.empty. def maxTimestampAndOffsetSoFar: TimestampAndOffset = { if (_maxTimestampAndOffsetSoFar == TimestampAndOffset.empty) _maxTimestampAndOffsetSoFar = TimestampAndOffset(...) _maxTimestampAndOffsetSoFar } ... ``` One point which is not clear to me is wether we really could use `TimestampAndOffset.empty` as a sentinel or we must wrap it in an `Option`. I need to dig a bit in the code to better understand it here. Perhaps, `TimestampAndOffset` already exists in the codebase. I haven't checked. -- 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