Skip to content

KAFKA-20635: Spurious "Writing records..." failed errors in the group coordinator after partition leadership change (4.0) - #22509

Closed
dajac wants to merge 1 commit into
apache:4.0from
dajac:worktree-KAFKA-20635-4.0
Closed

dajac wants to merge 1 commit into
apache:4.0from
dajac:worktree-KAFKA-20635-4.0

Conversation

@dajac

@dajac dajac commented Jun 8, 2026

Copy link
Copy Markdown
Member

Backport of #22466 to 4.0.

This branch predates the adaptive-flush refactor, so the change is adapted:

  • the flushCurrentBatch log classification and the completeTransaction
    transaction-marker logging are applied as in the original;
  • the new withActiveContext helper is added and the single (linger)
    FlushBatch event uses it (there is no enqueueAdaptiveFlush here);
  • the new too-large message uses the existing maxBatchSize field on
    CoordinatorBatch (the original patch added that field on trunk, but it
    already exists on this branch).

Compiled and CoordinatorRuntimeTest passes on the branch.

… coordinator after partition leadership change (apache#22466)

During routine `__consumer_offsets` partition leadership changes, the
group coordinator spams ERROR-level logs for every in-flight write at
the moment of transition:

```
[GroupCoordinator id=N] Writing records to __consumer_offsets-N
failed due to: For requests intended only for the leader, this error
indicates that the broker is not the current leader ...
[GroupCoordinator id=N] Execution of FlushBatch failed due to For
requests intended only for the leader, this error indicates that the
broker is not the current leader ...
```

These appear on the group coordinator that lost leadership and last for
the duration of the in-flight batch queue. The behavior is correct:
`NotLeaderOrFollowerException` propagates through `failCurrentBatch` to
the deferred events and is mapped to `NOT_COORDINATOR` for clients via
`CoordinatorOperationExceptionHelper`, so clients retry against the new
coordinator. This is purely a logging-noise issue.

This patch classifies the flush failures in `flushCurrentBatch`:

- `NotLeaderOrFollowerException` (leadership change) and
  `InvalidProducerEpochException` (fenced producer) are logged at DEBUG;
- `RecordTooLargeException` and `RecordBatchTooLargeException` remain at
  ERROR with added context (record count and maximum batch size);
- `NotCoordinatorException`, thrown when the state machine is out of
  sync, is not re-logged since that condition is already logged;
- any other failure is logged at ERROR as an unexpected error.

The redundant re-log from the `FlushBatch` event is also suppressed so
that a failure is logged once.

Reviewers: Dongnuo Lyu <dlyu@confluent.io>, Sean Quah
 <squah@confluent.io>
@dajac dajac changed the title KAFKA-20635: Spurious "Writing records..." failed errors in the group coordinator after partition leadership change KAFKA-20635: Spurious "Writing records..." failed errors in the group coordinator after partition leadership change (4.0) Jun 8, 2026
@chia7712

chia7712 commented Jun 8, 2026

Copy link
Copy Markdown
Member

I assume 4.0 is archived since there are 4.1, 4.2, and 4.3

@dajac

dajac commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

As CI is broken in 4.0, I will cherry-pick it manually from 4.1 just in case we would ever release a new version of 4.0.

@dajac dajac closed this Jun 8, 2026
@dajac
dajac deleted the worktree-KAFKA-20635-4.0 branch June 8, 2026 18:50
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.

3 participants