Croway opened a new pull request, #30072: URL: https://github.com/apache/camel/pull/30072
JIRA: [CAMEL-26995](https://issues.apache.org/jira/browse/CAMEL-26995) ### What was wrong With a `RecoverableAggregationRepository`, `AggregateOnCompletion.onComplete` (`AggregateProcessor`) adds a processed aggregated exchange to `unconfirmedCompleteExchanges` only when `confirmWithResult` returns `false`. That set was added by CAMEL-17613: "If the remove failed, retry it in the RecoverTask, but do not redeliver the exchange". When `confirmWithResult` **throws**, that step is skipped. The `finally` removes the id from `inProgressCompleteExchanges`, and `UnitOfWorkHelper` logs and ignores the exception. On its next pass, `RecoverTask` finds the id in the completed store, neither in progress nor unconfirmed, so it recovers the exchange and sends it again (`CamelRedelivered=true`), although it was processed. `JdbcAggregationRepository` throws when the database or the connection is not available during its `DELETE`; fault-injection tests against PostgreSQL showed it. The other recoverable repositories (cassandraql, hazelcast, infinispan, redis, caffeine, ehcache, `KeyValueAggregationRepository`) use the default `confirmWithResult`, which calls `confirm`, so they throw whatever their store throws. `RecoverTask.retryConfirm` had the same gap. A retried confirm that throws ended the whole recover pass, so the exchanges after it in the scan were neither confirmed nor recovered. As long as that confirm keeps failing and comes first in the scan, they never are. ### The fix - `onComplete`: a `confirmWithResult` that throws is handled like one that returns `false`. It is logged at WARN with the exchange id and the stack trace, the exchange is kept in `unconfirmedCompleteExchanges` and its redelivery state is removed. The recover task then confirms it again and does not send it again. - `retryConfirm`: an exception is handled like `false` (WARN `Still unable to confirm removal of exchange ...` with the cause, and the stack trace at DEBUG), and the pass goes on with the next exchange. - A `VirtualMachineError` is rethrown in both places, as elsewhere in this class since CAMEL-26881. - The javadoc of `RecoverableAggregationRepository.confirmWithResult` now says what happens when it returns `false` or throws. ### Tests New `AggregateRecoverableConfirmFailureTest` (camel-core). It uses an in-memory recoverable repository that moves completed groups to a completed store, as `JdbcAggregationRepository` does, and can make a confirm throw or return `false`: - `testConfirmThrows`: the confirm of `A+B` throws once. Before the fix it fails: `expected: <[A+B]> but was: <[A+B, A+B (redelivered)]>`. - `testConfirmReturnsFalse`: the CAMEL-17613 case, as a control. It passes before and after. - `testRetriedConfirmThrows`: the confirm of `A+B` always throws, and `C+D`'s throws once. Before the fix, both groups are sent again. With only the `onComplete` change, `C+D` is never confirmed (await timeout), because `A+B` comes first in the scan. With the fix, `mvnd test -pl core/camel-core -am -Dtest='*Aggregat*Test'` passes (305 tests, 5 skipped), and so do the camel-sql `*Jdbc*Aggregat*Test` tests, which use the real `JdbcAggregationRepository` (63 tests). No upgrade-guide entry: a processed exchange is no longer sent a second time, which is the documented behaviour ("Only when an Exchange has been successfully processed it will be marked as complete ..."). A custom repository already gets `confirmWithResult` again from the recover task after a `false`, and now also after an exception. ### For reviewers - If a confirm throws *after* the row was deleted (an ambiguous commit), the scan no longer returns the id, so the id stays in `unconfirmedCompleteExchanges`. The same already happens for a `false` result whose row is gone (see CAMEL-26739): one id per such failure, instead of a duplicate delivery today. I did not add pruning of that set against the scan, to keep the change small. - Not changed: the `confirm` after a recovered exchange was moved to the dead letter channel. If it throws, the pass ends, and the exchange is sent to the DLC again on the next pass. That is a separate path (it calls `confirm`, not `confirmWithResult`), and I can open a follow-up if wanted. _Claude Code on behalf of Croway_ -- 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]
