ammachado opened a new pull request, #31224:
URL: https://github.com/apache/camel/pull/31224

   # Description
   
   [CAMEL-28002](https://issues.apache.org/jira/browse/CAMEL-28002)
   
   In optimistic mode, `JCacheAggregationRepository.add(ctx, key, null, 
newExchange)` (a new group) used `Cache#getAndPut`, which writes 
unconditionally. When two nodes created the same group concurrently, the second 
node overwrote the group of the first one and only then threw 
`OptimisticLockingException`. The aggregator retried the second exchange, but 
the exchange of the first node was already lost.
   
   The fix uses `Cache#putIfAbsent`, as `HazelcastAggregationRepository` 
already does with `IMap#putIfAbsent`, so a failed add leaves the cache 
unchanged. JCache's `putIfAbsent` returns a `boolean` rather than the previous 
value, so the error log now names only the key (reading the existing exchange 
with a second `get` would be racy). The log text no longer refers to the 
Hazelcast API (`IMap#putIfAbsend`).
   
   Test: `checkOptimisticAddOfNewExchangeKeepsGroupCreatedByAnotherNode` 
creates a group from one repository, tries to create the same group from a 
second one, and asserts both the `OptimisticLockingException` and that the 
stored group still holds the first body. Against the previous code it fails 
with `expected: <The group created first, by node one.> but was: <The group 
created concurrently, by node two.>`; with the fix all 111 tests of 
`camel-jcache` pass.
   
   No upgrade-guide entry: the only behavior change is the bug fix.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
     Built and tested `components/camel-jcache` only (plus `formatter:format 
impsort:sort`); the working tree stayed clean. The change touches no generated 
metadata.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
Adriano Machado (@ammachado)
   
   _This was generated by an AI agent and may contain inaccuracies. Please 
verify before relying on it._


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