gnodet commented on PR #29564:
URL: https://github.com/apache/camel/pull/29564#issuecomment-6820487595

   Thank you both for the thorough analysis.
   
   @davsclaus @oscerd: The latest commit 
([c50da04](https://github.com/apache/camel/pull/29564/commits/c50da046c96383aebc471d795b3bacb5ce9af227))
 replaces the previous two-step approach entirely with the transactional 
strategy you both proposed — a `TransactionContext` with `ONE_PHASE` semantics 
(the same approach the non-optimistic path already uses):
   
   ```java
   tCtx.beginTransaction();
   TransactionalMap tCache = tCtx.getMap(cache.getName());
   TransactionalMap tPersistentCache = tCtx.getMap(persistedCache.getName());
   
   if (!tCache.remove(key, holder)) {   // conditional remove inside the 
transaction
       tCtx.rollbackTransaction();
       throw new OptimisticLockingException();
   }
   tPersistentCache.put(exchange.getExchangeId(), holder);
   tCtx.commitTransaction();
   ```
   
   This addresses all three failure modes from @davsclaus's table:
   - **Race**: the loser's `tCache.remove()` returns `false` inside the 
transaction; it never reaches `tPersistentCache`, so it cannot corrupt the 
winner's entry.
   - **Crash / put failure**: the uncommitted transaction rolls back, so the 
group re-appears in the operational repository for safe duplicate delivery 
rather than permanent loss.
   - **Consistency with non-optimistic path**: both branches now use the same 
ONE_PHASE transaction pattern.
   
   The `removeFromRecoverableStorage()` helper is gone (dead code once the 
cleanup path no longer exists). Tests updated:
   - Removed the two tests covering the old cleanup path.
   - Added `checkOptimisticRemoveRaceDoesNotDeleteWinnersRecoveryEntry()` 
(deterministic regression test for the race).
   - Added `checkOptimisticRemoveKeepsTheGroupWhenTheTransactionFails()` 
(replaces the old `...KeepsTheGroupWhenTheRecoverableStorageFails` to cover the 
CAMEL-26663 guarantee under the new transactional path).
   
   _On behalf of gnodet — Hermes/forgebot_


-- 
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]

Reply via email to