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

   # Description
   
   [CAMEL-25212](https://issues.apache.org/jira/browse/CAMEL-25212)
   
   `InfinispanEmbeddedClusterView` and `InfinispanRemoteClusterView` elect a 
leader with a task scheduled with `scheduleAtFixedRate`. The task did not catch 
exceptions, so one exception from a cache operation (a timeout, an 
`AvailabilityException` in a partition, a HotRod `TransportException` while the 
server is unreachable, or a listener) cancelled all later runs. The leader then 
stopped refreshing the leader key while its local member kept reporting itself 
as the leader, so another node could take the expired key and both acted as 
leader until the former leader handled the expired event of the key (or for 
good if that event was missed, for example when a remote server restart lost 
the key).
   
   Also, stopping the view removed the leader key but left the local member as 
the leader and fired no event, so listeners still registered on the view (for 
example after a JMX `stopView`) kept acting as the leader.
   
   This change:
   
   - the leadership task catches the exception, logs it and gives up the 
leadership until its next run (which takes it again if the key is free or still 
held by this node); the periodic task keeps running;
   - stopping the view gives up the leadership (in a `finally`, after removing 
the keys), which fires the event;
   - `LocalMember.setLeader(false)` fires the event even if the current leader 
cannot be looked up.
   
   About the event on stop: CAMEL-24545 removed it from the ZooKeeper view, 
because a listener (ClusteredRoutePolicy) could deadlock with the view during 
shutdown; CAMEL-25062 has since moved the policy's work to its own thread, 
CAMEL-25089 made the FileLock view fire the event on stop (the same problem as 
here), and the Consul view fires it too. The ZooKeeper view does reset its flag 
on stop, which the Infinispan views did not do at all. If you prefer the 
ZooKeeper behaviour here, the stop part can be reduced to resetting the flag 
without the event.
   
   Tests: new `InfinispanEmbeddedClusterViewLeadershipTest`:
   - `leadershipIsRefreshedAfterAnError`: a cache wrapper fails the next 
`replace` of the leader key; the key must still be refreshed afterwards and the 
node must be the leader again. Without the change `replace` is never called 
again (condition timeout).
   - `stoppingTheViewGivesUpTheLeadership`: after `view.stop()` the local 
member is not the leader and a leadership event was fired. Without the change 
neither happens.
   
   I ran the camel-infinispan-embedded tests (96 pass; 
`InfinispanEmbeddedClusteredConsumerTest`, a clustered-cache consumer test that 
does not use the cluster view and is disabled on Linux by CAMEL-21438, hung on 
this Mac and was excluded) and the camel-infinispan unit tests (13 pass). The 
remote view's ITs need Docker and were not run.
   
   # 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.
     (I built and tested the affected modules, including the formatter and 
import-sort plugins. I did not run the full root build.)
   
   # 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.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 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]

Reply via email to