allthingssecurity opened a new pull request, #29202: URL: https://github.com/apache/camel/pull/29202
# Description [CAMEL-26577](https://issues.apache.org/jira/browse/CAMEL-26577) `RebalancingCamelClusterService` looks at the views of its delegate on every pass of `reconcile()` through `delegate.getView(namespace)` (in `members()`, `owned()` and `setDisabled()`) and never releases them. `AbstractCamelClusterService.getView` takes a reference on the view and starts it on the first one, and `releaseView` stops it when the last one is released. So with the rebalancing service: - the view of a clustered route that is removed keeps running, as the rebalancer still holds references: this node stays in the election and, while it is the leader, no other node runs the route; - a view that was already released (stopped) is started again by the next pass. This is the case CAMEL-25089 fixed for a restart of the cluster service ("a released view has been stopped"), brought back by the rebalancer. Found with a TLA+ model of the reference count of one namespace (route policy retain/release, rebalancing thread, service stop/start): on main, route added, route removed, one pass -> the view runs with no user. The fixed model holds. ## The fix - `AbstractCamelClusterService` gets two package-private methods: `retainViewIfInUse` (takes a reference only when the view already has one, so it neither creates nor starts a view) and `isViewInUse`. - `RebalancingCamelClusterService` balances only the namespaces in use, and releases every view it takes in a `finally`. A delegate that does not extend `AbstractCamelClusterService` (none in Camel) gets `getView`/`releaseView` pairs, so a released view of such a delegate is started and stopped again by a pass instead of being kept running. Note: the members are now compared only over the views in use. While a clustered route is being removed node by node, a node that still has it can see different members on that view and skip balancing (`members()` returns null) until the other nodes have caught up, as it already does whenever the views disagree. ## Tests `RebalancingClusterServiceReleaseViewTest` (camel-core, test cluster service, no Kubernetes): - `testRemovedRouteStopsView`: a `ClusteredRoutePolicy` route on the rebalancing service, one pass, `removeRoute`: the view is stopped (fails on main: `Started`); - `testRebalancingDoesNotStartReleasedView`: a view released through the API stays stopped after a pass, and is not even started and stopped within the pass (fails on main); - `testRebalancingStillOpensViewInUse`: a view in use that this member does not own is still opened by a pass, and is stopped once released (control for the rebalancing itself). The passes are run from the test (the period is one hour), no sleeps. _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]
