Source:
public void run() { try (Timer.Context c = metrics.timer("offset-committer.duration").time()) { ReducingConsumer committedOffsetsReducer = processCommittedOffsets(); Map<SubscriptionPartition, Long> maxDrainedCommittedOffsets = committedOffsetsReducer.reduced; updateMaxCommittedOffsets(maxDrainedCommittedOffsets); ReducingConsumer inflightOffsetReducer = processInflightOffsets(committedOffsetsReducer.all); Map<SubscriptionPartition, Long> minInflightOffsets = inflightOffsetReducer.reduced; int scheduledToCommitCount = 0; int obsoleteCount = 0; Set<SubscriptionPartition> committedOffsetToBeRemoved = new HashSet<>(); OffsetsToCommit offsetsToCommit = new OffsetsToCommit(); for (SubscriptionPartition partition : Sets.union(minInflightOffsets.keySet(), maxCommittedOffsets.keySet())) { if (partitionAssignmentState.isAssignedPartitionAtCurrentTerm(partition)) { long minInflight = minInflightOffsets.getOrDefault(partition, Long.MAX_VALUE); long maxCommitted = maxCommittedOffsets.getOrDefault(partition, Long.MAX_VALUE); long offsetToBeCommitted = Math.min(minInflight, maxCommitted); if (offsetToBeCommitted >= 0 && offsetToBeCommitted < Long.MAX_VALUE) { scheduledToCommitCount++; offsetsToCommit.add(new SubscriptionPartitionOffset(partition, offsetToBeCommitted)); if (maxCommitted == offsetToBeCommitted) { committedOffsetToBeRemoved.add(partition); } } } else { obsoleteCount++; } } committedOffsetToBeRemoved.forEach(maxCommittedOffsets::remove); messageCommitter.commitOffsets(offsetsToCommit); metrics.counter("offset-committer.obsolete").inc(obsoleteCount); metrics.counter("offset-committer.committed").inc(scheduledToCommitCount); cleanupStoredOffsetsWithObsoleteTerms(); } catch (Exception exception) { logger.error("Failed to run offset committer: {}", exception.getMessage(), exception); } }

Target:
public void run() { try (Timer.Context c = metrics.timer("offset-committer.duration").time()) { ReducingConsumer committedOffsetsReducer = processCommittedOffsets(); Map<SubscriptionPartition, Long> maxDrainedCommittedOffsets = committedOffsetsReducer.reduced; updateMaxCommittedOffsets(maxDrainedCommittedOffsets); ReducingConsumer inflightOffsetReducer = processInflightOffsets(committedOffsetsReducer.all); Map<SubscriptionPartition, Long> minInflightOffsets = inflightOffsetReducer.reduced; int scheduledToCommitCount = 0; int obsoleteCount = 0; Set<SubscriptionPartition> committedOffsetToBeRemoved = new HashSet<>(); OffsetsToCommit offsetsToCommit = new OffsetsToCommit(); for (SubscriptionPartition partition : Sets.union(minInflightOffsets.keySet(), maxCommittedOffsets.keySet())) { if (partitionAssignmentState.isAssignedPartitionAtCurrentTerm(partition)) { long minInflight = minInflightOffsets.getOrDefault(partition, Long.MAX_VALUE); long maxCommitted = maxCommittedOffsets.getOrDefault(partition, Long.MAX_VALUE); long offsetToBeCommitted = Math.min(minInflight, maxCommitted); if (offsetToBeCommitted >= 0 && offsetToBeCommitted < Long.MAX_VALUE) { scheduledToCommitCount++; offsetsToCommit.add(new SubscriptionPartitionOffset(partition, offsetToBeCommitted)); if (maxCommitted == offsetToBeCommitted) { committedOffsetToBeRemoved.add(partition); } } else { logger.warn("Skipping offset out of bounds for subscription {}: partition={}, offset={}", partition.getSubscriptionName(), partition.getPartition(), offsetToBeCommitted); } } else { obsoleteCount++; } } committedOffsetToBeRemoved.forEach(maxCommittedOffsets::remove); messageCommitter.commitOffsets(offsetsToCommit); metrics.counter("offset-committer.obsolete").inc(obsoleteCount); metrics.counter("offset-committer.committed").inc(scheduledToCommitCount); cleanupStoredOffsetsWithObsoleteTerms(); } catch (Exception exception) { logger.error("Failed to run offset committer: {}", exception.getMessage(), exception); } }