allthingssecurity opened a new pull request, #30862: URL: https://github.com/apache/camel/pull/30862
# Description [CAMEL-27566](https://issues.apache.org/jira/browse/CAMEL-27566) When the leader's read or write of the cluster data fails once, `FileLockClusterView` gives up the leadership and releases the lock. The data file still holds the member's id, so in the next check the member reads its own id and tries to take the leadership back at once. If that one attempt fails too (a timeout or an I/O error while it resolves or opens the lock file), the member keeps its own id as the previous observation. From then on every check finds its own id in both the previous and the latest observation and takes the "Backoff so the current cluster leader can notice leadership is relinquished" return. Only a leader writes the data file, so nothing changes it and the backoff never ends. With another live member, that member finds the heartbeat stale and takes over. With a single member (or when the other members are stopped), nobody is leader again until a restart, although the file system is healthy again. `singleClusterMemberRecoversLeadershipIfLockFileDeleted` in camel-master shows that a single member is meant to recover. The fix: the backoff lasts one check. When the member backs off, it forgets the observation of its own id (`compareAndSet` of the reference it just stored to null), so the next check tries the lock again. The backoff still gives a member that has just taken the lock one interval to write its id. A member whose attempts keep failing now tries every second check, and the OS lock decides; a try while another member holds the lock just fails, as it does today for a follower that finds the leader stale. Model: found with a TLA+ model of the file lock cluster view (liveness: if failures stop and a view stays started, some view is eventually leader for good). On main the model loops in the backoff forever with one view; with the backoff lasting one check the property holds with one and with two views, and the safety properties (at most one leader) still hold. Tests: new `FileLockClusterViewReclaimLeadershipTest` (camel-core, next to the other file cluster tests), one member on a local directory: - the leader's read of the cluster data fails once, and every attempt of the task that resolves the lock file path fails in the first attempt to take the leadership back; once the file system is healthy the member must be leader again (within 10 seconds, at a 100 ms interval); - control: only the failed read; the member takes the leadership back at once. On main the first test fails (the member is not leader again within 10 seconds) and the control passes. With the change both pass, and so do the tests of camel-file (54), the file and cluster tests of camel-core (629 run, 0 failures, 12 skipped) and the tests of camel-master (34, with `singleClusterMemberRecoversLeadershipIfLockFileDeleted` and the other failover tests). The new class 20 times in one JVM: 40 run, 0 failures. No upgrade guide entry: nothing to change for users. The backoff was added with CAMEL-22430 (4.14.1 and 4.15.0), so the 4.14.x and 4.18.x lines have the same bug, and the change applies there as it is. The fix of the second finding of the same review (a lock-file open that outlives its timeout, separate PR) depends on this one: without it, a reclaim whose open times out once leaves a single member without a leader, so this one should be merged and backported first. # 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): [CAMEL-27566](https://issues.apache.org/jira/browse/CAMEL-27566). # 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 commits carry 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]
