Skip to content

KAFKA-13185: Clear pending records after pre-commit rewind - #23048

Open
lh0156 wants to merge 1 commit into
apache:trunkfrom
lh0156:agent/KAFKA-13185-clear-message-batch
Open

KAFKA-13185: Clear pending records after pre-commit rewind#23048
lh0156 wants to merge 1 commit into
apache:trunkfrom
lh0156:agent/KAFKA-13185-clear-message-batch

Conversation

@lh0156

@lh0156 lh0156 commented Aug 3, 2026

Copy link
Copy Markdown

Closes KAFKA-13185

Summary

  • Clear the pending messageBatch when a sink task pre-commit fails and the consumer is rewound to the last committed position.
  • Clear the matching origOffsets as well, so the discarded batch cannot advance currentOffsets during the recovery poll.
  • Add a regression test covering a retriable put, a failed preCommit, and the subsequent empty delivery.

When SinkTask.put raises a RetriableException, WorkerSinkTask keeps the batch for redelivery. If the following preCommit also fails, the worker seeks to the last committed offset but previously retained that batch. The next poll could therefore deliver stale records, and retaining origOffsets could reintroduce offsets that had just been rewound. The recovery path now discards both pieces of pending state before polling again.

Tests

  • ./gradlew :connect:runtime:test --tests org.apache.kafka.connect.runtime.WorkerSinkTaskTest.testPreCommitFailureClearsPendingMessageBatch --no-build-cache --console=plain
  • ./gradlew :connect:runtime:spotlessCheck :connect:runtime:test --tests org.apache.kafka.connect.runtime.WorkerSinkTaskTest --no-build-cache --console=plain
  • ./gradlew :connect:runtime:test --no-build-cache --console=plain

The regression test was verified RED before the fix because the stale batch was delivered with one record, then GREEN after the fix with an empty delivery and last-committed offsets preserved.

Clear the pending message batch and its associated offsets when a sink task pre-commit fails and the consumer is rewound to the last committed position. Add a regression test covering a retriable put followed by a failed pre-commit.

Generated-by: OpenAI Codex (GPT-5)

Signed-off-by: Yunseop Eom <62834176+lh0156@users.noreply.github.com>
@github-actions github-actions Bot added triage PRs from the community connect small Small PRs labels Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

connect small Small PRs triage PRs from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant