davsclaus opened a new pull request, #30749: URL: https://github.com/apache/camel/pull/30749
_Claude Code on behalf of davsclaus_ https://issues.apache.org/jira/browse/CAMEL-26993 ### What was wrong With `allowManualCommit=true` and the `DefaultKafkaManualCommitFactory` or the `DefaultKafkaManualAsyncCommitFactory`, `KafkaRecordStreamingProcessor.processExchange` records the offset of every processed record in the `OffsetCache` of the commit manager (`SyncCommitManager`, `AsyncCommitManager`). When a partition is revoked (`ClassicRebalanceListener` / `ResumeRebalanceListener.onPartitionsRevoked`, which also runs on stop through the unsubscribe), `commit(partition)` committed that cached offset: the last processed record, also when the route had not committed it. Records the route still held, for example in an aggregation group that is not complete, were committed on a rebalance or a stop and were not consumed again; if the held exchanges were lost, so were the records. CAMEL-23997 removed the commit after each poll for manual commits, but the revoke and stop paths still used the cache. ### What changed The two commit managers used with manual commits keep two offsets per partition apart: - the last **processed** offset (the `OffsetCache`, unchanged), used by `breakOnFirstError`; - the offset the route **committed** with `KafkaManualCommit.commit()`: `DefaultKafkaManualSyncCommit` commits it at once (`forceCommit`), `DefaultKafkaManualAsyncCommit` requests it and the consumer thread commits it before its next poll. `AsyncCommitManager.requestCommit` no longer also writes it into the `OffsetCache`. `CommitManager` gets a new default method `commitProcessedOffset(partition)` (defaults to `commit(partition)`). With `allowManualCommit=true`, `commit(partition)` now commits only the offset that the route committed and that is not committed yet: - `SyncCommitManager`: nothing (the route's commits are already committed by `forceCommit`); - `AsyncCommitManager`: the requested offset that the consumer thread has not committed yet, if any. Without manual commits, `commit(partition)` behaves as before. `NoopCommitManager` and `CommitToOffsetManager` are unchanged (the latter is never used with manual commits). The paths that call `commit(partition)` and so now commit only what the route committed: the revoke (rebalance), the stop (unsubscribe revokes the partitions), the pausable consumer pausing after a failed record (`KafkaConsumerListener.afterProcess`), and the per-poll flush of the batching consumer (which with manual commits only ever flushed the requested async commits, so nothing changes there). The batching processor with auto commit and `breakOnFirstError` (`CommitSynchronization`) is unchanged, as it is not a manual-commit path. ### breakOnFirstError `KafkaRecordStreamingProcessor.processException` now calls `commitProcessedOffset(partition)`: as before, it commits the records processed before the failed one, whether the route committed them or not, so that the failed one is polled again. This commit is an explicit step of `breakOnFirstError` and stays as is. After the break, the consumer unsubscribes; that revoke commits only a route commit still pending (normally nothing, as the break already committed further). ### Behaviour change With manual commits, a rebalance or a stop no longer commits records the route did not commit. Those records are consumed again after the rebalance or the restart, so they may be processed more than once, where before they could be lost. This includes a commit the route makes only after the partition was revoked (for example an aggregator completing its group after the Kafka route stopped): such a commit is dropped (as since CAMEL-26978), and the records are consumed again. Upgrade guide entry added in `camel-4x-upgrade-guide-4_24.adoc`, and the manual commit section of the Kafka component doc (and its catalog copy) describes the revoke/stop behaviour. ### Tests - `CommitManagerRebalanceTest`: 7 new tests (sync and async): a revoke with manual commits commits nothing when the route committed nothing; it commits up to what the route committed (offset 3 when the route committed offset 2 and processed up to 4); `commitProcessedOffset` (breakOnFirstError) still commits the processed records, and the following revoke has nothing left to commit. The existing non-manual tests are unchanged. - `KafkaManualCommitRevokeTest` (new, `MockConsumer` + route, sync and async): the route commits record `a` and holds `b` and `c`; a revoke and a route stop commit offset 1, not 3. All 4 fail without the fix. - `KafkaRecordStreamingProcessorTest`: breakOnFirstError with manual commit calls `commitProcessedOffset`, not `commit`. - `DefaultKafkaManualAsyncCommitTest.testCommitAfterRevokeIsNotCommitted`: the revoke now commits nothing (the route did not commit), was offset 2. - `KafkaConsumerManualCommitStopIT` (new, Kafka testcontainer): the route commits messages 0-2 out of 0-4, is stopped and started: messages 3 and 4 are consumed again. Fails without the fix. - `KafkaConsumerAsyncManualCommitIT` stopped the Kafka route before its aggregator committed the records and passed only because the stop committed them; it now waits for the commits before the stop. Runs: all camel-kafka unit tests, 1450 tests (including 1000 seeds of `KafkaConsumerDstTest`), 0 failures. ITs run with Docker: the manual commit, breakOnFirstError and batching manual-commit ITs (`integration/commit/*`, `KafkaConsumerAsyncManualCommitIT`, `KafkaBreakOnFirstError*IT`, `KafkaBatchingProcessingManualCommitIT`, `KafkaBatchingProcessingBreakOnFirstErrorManualCommitIT`), 20 tests, all passing after the IT fix above. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
