fluss icon indicating copy to clipboard operation
fluss copied to clipboard

[server] Support writer epoch for Fluss writers

Open dstolis opened this issue 3 weeks ago • 0 comments

Search before asking

  • [x] I searched in the issues and found nothing similar.

Motivation

Part of #5088. When a writer is idle for a long time, the server expires its writer state. The client then continues with its old sequence, the write fails with OutOfOrderSequenceException, and a Flink task may restart. This happens for example with a CDC pipeline that resumes after a quiet period. Kafka solves this with producer epochs (KIP-360).

Solution

  • The writer state keeps the current epoch. A batch with a higher epoch resets the state and must start at sequence 0.
  • A batch from an older epoch is rejected with InvalidWriterEpochException (error code 81). Followers and log recovery keep an older-epoch batch the leader already accepted, and log a warning.
  • The duplicate and order checks use the first and last sequence of a batch, taken from the sequence mode bit, so batches that number their records (#5092) are checked correctly.
  • The writer snapshot also stores the epoch and the first sequence of the last batch. Snapshots without them read as epoch 0.
  • When its writer state is unknown or expired, the client bumps its epoch and restarts its sequence instead of failing.
  • Define how in-flight batches and batches with an uncertain outcome are handled during an epoch bump.
  • Native writers write the epoch into the V3 header and keep attributes bit 1 clear, so their sequence still counts batches.
  • The client writes V3 only when the leader negotiated PRODUCE_LOG v2. Otherwise it keeps the old format and today's behaviour.
  • Depends on #5089 and #5187.
  • Tests: an idle writer whose state expires and then resumes, batches from an old epoch being rejected, and writer state recovery on leaders and followers.

Willingness to contribute

  • [x] I'm willing to submit a PR!

dstolis avatar Nov 07 '26 08:11 dstolis