Skip to content

Explicitly use OFFSET_STORED in assign(), add tests for offset resume#33

Merged
jghoman merged 2 commits intomainfrom
test-offset-resume
Apr 2, 2026
Merged

Explicitly use OFFSET_STORED in assign(), add tests for offset resume#33
jghoman merged 2 commits intomainfrom
test-offset-resume

Conversation

@jghoman
Copy link
Copy Markdown
Collaborator

@jghoman jghoman commented Apr 2, 2026

Summary

Makes the committed-offset resume behavior explicit in consumer.assign(). Previously relied on librdkafka's implicit default (OFFSET_INVALID → same as OFFSET_STORED). Now explicitly passes OFFSET_STORED so the intent is clear in code.

Why this matters: When replica count changes (e.g. 4 → 2 pods), partitions get reassigned to different pods. Each pod must resume from the offset committed by whichever pod previously owned that partition — not replay from earliest. OFFSET_STORED fetches the committed offset from __consumer_offsets, falling back to auto.offset.reset=earliest only if no offset has ever been committed.

No functional change — just making the invariant explicit and tested.

Test plan

  • 137 unit tests pass (2 new)
  • test_assign_uses_stored_offsets — verifies every partition uses OFFSET_STORED
  • test_auto_offset_reset_is_earliest — verifies fallback for new partitions

Makes the committed-offset resume behavior explicit rather than relying
on librdkafka's implicit default. Critical invariant: replica count
changes must resume from committed offsets, not replay from earliest.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the consumer’s committed-offset resume behavior explicit by passing OFFSET_STORED in Consumer.assign(), and adds unit tests to ensure the assignment uses stored offsets and that auto.offset.reset is configured as earliest.

Changes:

  • Explicitly assign partitions with OFFSET_STORED to resume from committed offsets.
  • Add unit test verifying every assigned TopicPartition uses OFFSET_STORED.
  • Add unit test asserting auto.offset.reset is set to earliest (fallback behavior for never-committed partitions).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
millpond/consumer.py Passes OFFSET_STORED explicitly in consumer.assign() and documents the rationale.
tests/unit/test_consumer.py Adds unit tests covering OFFSET_STORED usage in assignments and auto.offset.reset configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/unit/test_consumer.py
@jghoman jghoman merged commit 11a7c4a into main Apr 2, 2026
15 checks passed
@jghoman jghoman deleted the test-offset-resume branch April 2, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants