Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in Kafka consumer when negative acknowledgements are received #3691

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,20 @@ private void addAcknowledgedOffsets(final TopicPartition topicPartition, final R

if (Objects.isNull(commitTracker) && errLogRateLimiter.isAllowed(System.currentTimeMillis())) {
LOG.error("Commit tracker not found for TopicPartition: {}", topicPartition);
return;
}

final OffsetAndMetadata offsetAndMetadata =
partitionCommitTrackerMap.get(partitionId).addCompletedOffsets(offsetRange);
final OffsetAndMetadata offsetAndMetadata = commitTracker.addCompletedOffsets(offsetRange);
updateOffsetsToCommit(topicPartition, offsetAndMetadata);
}

private void resetOffsets() {
// resetting offsets is similar to committing acknowledged offsets. Throttle the frequency of resets by
// checking current time with last commit time. Same "lastCommitTime" and commit interval are used in both cases
long currentTimeMillis = System.currentTimeMillis();
if ((currentTimeMillis - lastCommitTime) < topicConfig.getCommitInterval().toMillis()) {
return;
}
if (partitionsToReset.size() > 0) {
partitionsToReset.forEach(partition -> {
try {
Expand All @@ -244,6 +250,8 @@ private void resetOffsets() {
consumer.seek(partition, offsetAndMetadata);
}
partitionCommitTrackerMap.remove(partition.partition());
final long epoch = getCurrentTimeNanos();
ownedPartitionsEpoch.put(partition, epoch);
} catch (Exception e) {
LOG.error("Failed to seek to last committed offset upon negative acknowledgement {}", partition, e);
}
Expand Down Expand Up @@ -493,7 +501,6 @@ public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
continue;
}
LOG.info("Assigned partition {}", topicPartition);
partitionCommitTrackerMap.remove(topicPartition.partition());
ownedPartitionsEpoch.put(topicPartition, epoch);
}
}
Expand Down
Loading