Skip to content

kafka connect: use a stable coordinator transactional id to fence stale coordinators - #18039

Open
twthorn wants to merge 2 commits into
apache:mainfrom
twthorn:kafka-connect-coordinator-fencing
Open

kafka connect: use a stable coordinator transactional id to fence stale coordinators#18039
twthorn wants to merge 2 commits into
apache:mainfrom
twthorn:kafka-connect-coordinator-fencing

Conversation

@twthorn

@twthorn twthorn commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #18038

Add support for coordinator fencing. This can prevent stale ("zombie") coordinators from committing stale consumer offsets.

Implementation

Currently, we generate a new UUID for every new coordinator. This means that the Kafka transaction we use trivially passes since no epoch fencing can be performed on the newly generated ID (e.g., between a stale or an up to date coordinator).

The change is to use a persistent transactional ID for the coordinator. We name this using the connect group ID which is unique to that connector. Then any leader change of that group will trigger Kafka to update the epoch of the transaction, and correctly fence stale coordinators. A stale coordinator will identify that it has been fenced, and exit the coordinator thread. We leave the worker task running and defer to Kafka Connect on determining its lifecycle.

Note: we introduced a in-memory monotonic increasing offset guard to make offsets monotonically increasing (values that are non-increasing are not committed). This was a tightly scoped fix to reduce the risk of a coordinator committing old offsets (which can cause data loss). However, it is theoretically possible that offsets could still be updated if an older coordinator wrote a higher offset than it last stored, but is less than another coordinator's written offset. The way to solve this and the canonical one in Kafka is with producer fencing. So we add the offset commit in its own transaction, and defer to kafka for epoch fencing.

Note: we also intentionally make the commit consumer offsets its separate transaction. It is outside the scope of this PR to refactor the offset transaction semantics (eg grouping the control topic offset write with the consumer offset commit). This delivers the minimal set of changes to have fenced consumer offset commits.

Testing

Used an integration test to reproduce this failure scenario first (ie a stale coordinator with an increasing offset but is older than another offset of a newer coordinator). Also added unit tests as well.

Related Work

In-memory monotonic offset guard:

Larger scoped coordinator refactor (PR is stale, has merge conflicts):

Related preventative setting offset reset strategy:

…le coordinators

Signed-off-by: Thomas Thornton <thomaswilliamthornton@gmail.com>
Signed-off-by: Thomas Thornton <thomaswilliamthornton@gmail.com>
@twthorn

twthorn commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@laskoviymishka could you review this when you get a free moment? Thanks!

@laskoviymishka
laskoviymishka self-requested a review September 10, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable Kafka coordinator fencing when committing consumer offsets

1 participant