davsclaus commented on code in PR #30909:
URL: https://github.com/apache/camel/pull/30909#discussion_r4717120036
##########
components/camel-master/src/main/java/org/apache/camel/component/master/MasterConsumer.java:
##########
@@ -290,19 +296,35 @@ private boolean startDelegatedConsumer(BackgroundTask
task, AtomicReference<Cons
throw new TaskRunFailureException(message, cause);
}
- if (!leadershipTaken || !isRunAllowed()) {
- // the leadership went away while the consumer was starting,
so stop what was just started
- // instead of publishing it. No leadership event is going to
do it, delegatedConsumer is unset
- LOG.info("Leadership lost while the consumer was starting.
Stopping consumer: {}", delegatedEndpoint);
- ServiceHelper.stopAndShutdownServices(consumer,
delegatedEndpoint);
+ // an attempt of an earlier lifecycle of this consumer (a stop and
start of the same instance) runs on the
+ // pool of that lifecycle. Within one lifecycle, a task newer than
this one only exists when the leadership
+ // was lost and taken again while this attempt was starting, and
as the pool has a single thread, that task
+ // has not run yet: this attempt publishes its consumer below and
cancels it
+ boolean earlierLifecycle = pool != leaderPool;
+ if (earlierLifecycle || delegatedConsumer != null ||
!leadershipTaken || !isRunAllowed()) {
+ // the leadership went away, or this consumer was stopped (and
maybe started again), while the
+ // consumer was starting. This attempt is no longer the
current one, so stop what it started instead
+ // of publishing it over the consumer of a newer attempt. Only
the consumer: the endpoint is shared
+ // with that newer consumer, and onLeadershipLost and doStop
stop it. And only stop it, not shut it
+ // down: a shutdown cannot be undone, and it would also shut
down the processor of the route, which
+ // a newer consumer uses
+ LOG.info("Leadership lost or consumer stopped while the
delegated consumer was starting. Stopping it: {}",
+ delegatedEndpoint);
+ ServiceHelper.stopService(consumer);
+ if (delegatedConsumer != null) {
+ // stopping a consumer also stops its processor, the
processor of the route, which the
+ // running delegated consumer uses too
+ ServiceHelper.startService(processor);
+ }
Review Comment:
Fixed in fcd8f3f: the comment on the stale branch now describes the window
while the processor is stopped. The case where the new consumer is still
starting is raised separately in my review.
_Claude Code on behalf of Claus Ibsen_
##########
components/camel-master/src/main/java/org/apache/camel/component/master/MasterConsumer.java:
##########
@@ -290,19 +296,35 @@ private boolean startDelegatedConsumer(BackgroundTask
task, AtomicReference<Cons
throw new TaskRunFailureException(message, cause);
}
- if (!leadershipTaken || !isRunAllowed()) {
- // the leadership went away while the consumer was starting,
so stop what was just started
- // instead of publishing it. No leadership event is going to
do it, delegatedConsumer is unset
- LOG.info("Leadership lost while the consumer was starting.
Stopping consumer: {}", delegatedEndpoint);
- ServiceHelper.stopAndShutdownServices(consumer,
delegatedEndpoint);
+ // an attempt of an earlier lifecycle of this consumer (a stop and
start of the same instance) runs on the
+ // pool of that lifecycle. Within one lifecycle, a task newer than
this one only exists when the leadership
+ // was lost and taken again while this attempt was starting, and
as the pool has a single thread, that task
+ // has not run yet: this attempt publishes its consumer below and
cancels it
+ boolean earlierLifecycle = pool != leaderPool;
+ if (earlierLifecycle || delegatedConsumer != null ||
!leadershipTaken || !isRunAllowed()) {
+ // the leadership went away, or this consumer was stopped (and
maybe started again), while the
+ // consumer was starting. This attempt is no longer the
current one, so stop what it started instead
+ // of publishing it over the consumer of a newer attempt. Only
the consumer: the endpoint is shared
+ // with that newer consumer, and onLeadershipLost and doStop
stop it. And only stop it, not shut it
+ // down: a shutdown cannot be undone, and it would also shut
down the processor of the route, which
+ // a newer consumer uses
Review Comment:
Fixed in fcd8f3f: the comment explains why it is `stopService` and not
`stopAndShutdownServices` (`DefaultConsumer.doShutdown` shuts down the route
processor, which cannot be undone).
_Claude Code on behalf of Claus Ibsen_
--
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]