Repository navigation
Conversation
…st-streaming#606) Kafka's committed offset is the next offset to process, but the head-gap check in Consumer._new_offset treated it as the last processed offset. With concurrency > 1, if the message at the committed offset was still being processed while later ones were acked, the consumer committed past it and the message was lost on crash. - _new_offset: don't commit while the first acked offset is above the committed offset (and handle a committed offset of 0). - _add_gap: clip gaps at the committed offset, not committed + 1, since the committed offset itself may be missing (e.g. a transaction marker). - Store position - 1 in _read_offset after a seek so gap detection also sees a missing message right at the committed position. The last two are needed so the stricter check does not stall commits on topics with gaps at the committed offset.
Author
|
Tested against a real broker (Kafka 3.8, single node):
Messages 2–8 finished in both runs, with no errors in the logs. |
Author
|
I didn't see #707 before opening this. Different approach: #707 caps commits at the smallest unacked offset, which also covers the no-committed-offset case. This PR fixes the head-gap check directly and also corrects gap trimming at the committed offset and the read offset after seeks; without those, a missing message at the committed position can stall commits. The broker results above apply to either fix. Happy to fold the gap/seek changes and the broker test into #707, or rebase this on top of it, whichever is easier to review. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #606.
With
concurrency > 1, Faust can commit an offset past a message that is still being processed. If the worker then dies, that message is lost.Root cause
Kafka's committed offset is the next offset to process, but the head-gap check in
Consumer._new_offsettreated it as the last processed offset:Using the numbers from the issue: the committed offset was 2585, message 2585 was still processing, and 2586–2588 were acked.
2586 - 2585 = 1passed the check, so 2589 was committed and 2585 was lost after the restart.Changes
_new_offset: don't commit while the first acked offset is above the committed offset. It also usesis not None, so a committed offset of0is checked too._add_gap: gaps are now trimmed atcommitted, notcommitted + 1. The committed offset itself can be missing, for example a transaction marker.perform_seek,seek, aiokafka_seek_wait): storeposition - 1, matching the "last offset read" meaning the drain loop expects. Otherwise a missing message right at the committed position is never recorded as a gap.The last two changes are needed together with the first. The old off-by-one was hiding them, and without them the stricter check would stop commits on topics with a gap at the committed offset (e.g. transactional input topics).
Tests
_add_gapincluding the committed offset. They fail onmasterand pass with this change._new_offsetcase that treated the committed offset as already processed.pytest tests/unit: 2037 passed, 12 skipped.Known limitation
When a partition has no committed offset (a new consumer group), there's no starting point to check against, so behavior there is unchanged.
Broker test
Reproduced #606 on Faust 0.15.5 and verified the fix on a real broker; see results.