Chia-Ping Tsai created KAFKA-21297:
--------------------------------------

             Summary: Refactor the maybeUpdateLimitOffsetsForStandbyChangelogs
                 Key: KAFKA-21297
                 URL: https://issues.apache.org/jira/browse/KAFKA-21297
             Project: Kafka
          Issue Type: Improvement
            Reporter: Chia-Ping Tsai
            Assignee: Chia-Ping Tsai


{code:java}
            for (final TopicPartition partition : changelogsWithLimitOffsets) {
                if (!changelogs.get(partition).bufferedRecords().isEmpty()) {
                    
updateLimitOffsetsForStandbyChangelogs(committedOffsetForChangelogs(tasks, 
changelogsWithLimitOffsets));
                    lastUpdateOffsetTime = time.milliseconds();
                    break;
                }
            } {code}
The “break” definitely misled me into thinking we skip the other committed 
offsets. Then I realized what it actually does is update “all” if “any” matches.

It could be simplified by following code
{code:java}
if (changelogsWithLimitOffsets.stream().anyMatch(p -> 
!changelogs.get(p).bufferedRecords().isEmpty())) {
    updateLimitOffsetsForStandbyChangelogs(committedOffsetForChangelogs(tasks, 
changelogsWithLimitOffsets));
    lastUpdateOffsetTime = time.milliseconds();
} {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to