davsclaus commented on code in PR #25611:
URL: https://github.com/apache/camel/pull/25611#discussion_r3862903904
##########
components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusterView.java:
##########
@@ -142,15 +145,20 @@ private String getFullPath() {
private final class CamelLeaderElectionListener extends
LeaderSelectorListenerAdapter {
@Override
public void takeLeadership(CuratorFramework curatorFramework) throws
Exception {
+ leader = true;
fireLeadershipChangedEvent(localMember);
BlockingTask task =
Tasks.foregroundTask().withBudget(Budgets.iterationBudget()
.withMaxIterations(IterationBoundedBudget.UNLIMITED_ITERATIONS)
.withInterval(Duration.ofSeconds(5))
.build())
.build();
-
- task.run(getCamelContext(), () -> !isRunAllowed());
+ try {
+ task.run(getCamelContext(), () -> !isRunAllowed() ||
!leaderSelector.hasLeadership());
+ } finally {
+ leader = false;
+ fireLeadershipChangedEvent((CamelClusterMember) null);
+ }
fireLeadershipChangedEvent(getLeader().orElse(null));
Review Comment:
Fixed — the leftover trailing
`fireLeadershipChangedEvent(getLeader().orElse(null));` line has been removed.
Only the `finally` block fires the leadership-lost event now.
##########
components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusterView.java:
##########
@@ -119,8 +121,9 @@ protected void doStart() throws Exception {
@Override
protected void doStop() throws Exception {
if (leaderSelector != null) {
+ leader = false;
leaderSelector.interruptLeadership();
- fireLeadershipChangedEvent(getLeader().orElse(null));
+ fireLeadershipChangedEvent((CamelClusterMember) null);
Review Comment:
Fixed — `doStop()` no longer fires the event itself. It now sets `leader =
false` and calls `selector.close()` (instead of `interruptLeadership()`), which
unblocks the `takeLeadership()` thread and lets its `finally` block fire the
single leadership-lost event. Verified: a deliberate stop now emits the
notification exactly once.
##########
components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusterView.java:
##########
@@ -110,6 +111,7 @@ protected void doStart() throws Exception {
if (leaderSelector == null) {
leaderSelector = new LeaderSelector(client, getFullPath(), new
CamelLeaderElectionListener());
leaderSelector.setId(getClusterService().getId());
+ leaderSelector.autoRequeue();
Review Comment:
Resolved by the same change: `doStop()` now nulls out `leaderSelector` and
calls `close()` (not just `interruptLeadership()`), and Curator does not
auto-requeue after `close()`. I confirmed in `BaseService.shutdown()`
(core/camel-api) that `stop()`/`doStop()` always runs before `doShutdown()`, so
a deliberate stop closes the selector immediately and cannot reclaim leadership
before shutdown. This also fixes the double-`close()` exception mentioned in
the commit message.
--
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]