aliehsaeedii commented on code in PR #14957: URL: https://github.com/apache/kafka/pull/14957#discussion_r1424265799
########## streams/src/main/java/org/apache/kafka/streams/state/internals/LogicalSegmentIterator.java: ########## @@ -69,23 +73,49 @@ public boolean hasNext() { if (!open) { throw new IllegalStateException("The iterator is out of scope."); } - // since data is stored in descending order in the segments, check whether there is any previous record, if the order is Ascending. - final boolean hasStillLoad = order.equals(ResultOrder.ASCENDING) ? iterator.hasPrevious() : iterator.hasNext(); - return hasStillLoad || maybeFillIterator(); + if (this.next != null) { + return true; + } + + while ((currentDeserializedSegmentValue != null || currentRawSegmentValue != null || segmentIterator.hasNext()) && this.next == null) { + boolean hasSegmentValue = currentDeserializedSegmentValue != null || currentRawSegmentValue != null; + if (!hasSegmentValue) { + hasSegmentValue = maybeFillCurrentSegmentValue(); + } + if (hasSegmentValue) { + this.next = getNextRecord(); + if (this.next == null) { + prepareToFetchNextSegment(); + } + } + } + return this.next != null; } @Override - public Object next() { - if (hasNext()) { - // since data is stored in descending order in the segments, retrieve previous record, if the order is Ascending. - return order.equals(ResultOrder.ASCENDING) ? iterator.previous() : iterator.next(); + public VersionedRecord<byte[]> next() { + if (this.next == null) { + if (!hasNext()) { + throw new NoSuchElementException(); + } } - throw new NoSuchElementException(); + assert this.next != null; Review Comment: > We usually don't use `assert`. Can be removed. Otherwise, there will be a warning, and we have to suppress it. But I will remove it. -- 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