jeqo commented on a change in pull request #9138: URL: https://github.com/apache/kafka/pull/9138#discussion_r477436882
########## File path: streams/src/main/java/org/apache/kafka/streams/state/internals/CachingWindowStore.java ########## @@ -416,26 +552,43 @@ private long currentSegmentLastTime() { } private void getNextSegmentIterator() { - ++currentSegmentId; - lastSegmentId = cacheFunction.segmentId(Math.min(timeTo, maxObservedTimestamp.get())); + if (forward) { + ++currentSegmentId; + lastSegmentId = cacheFunction.segmentId(Math.min(timeTo, maxObservedTimestamp.get())); - if (currentSegmentId > lastSegmentId) { - current = null; - return; - } + if (currentSegmentId > lastSegmentId) { + current = null; + return; + } - setCacheKeyRange(currentSegmentBeginTime(), currentSegmentLastTime()); + setCacheKeyRange(currentSegmentBeginTime(), currentSegmentLastTime()); - current.close(); - current = context.cache().range(cacheName, cacheKeyFrom, cacheKeyTo); + current.close(); + + current = context.cache().range(cacheName, cacheKeyFrom, cacheKeyTo); + } else { + --currentSegmentId; +// lastSegmentId = cacheFunction.segmentId(Math.min(timeTo, maxObservedTimestamp.get())); Review comment: actually it could be removed: `lastSegmentId` should be stable going backwards based on `timeFrom`. On the `if` branch, I assume that `lastSegmentId` could change in between iterations if `maxObservedTimestamp` is updated right? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org