davsclaus commented on code in PR #27311:
URL: https://github.com/apache/camel/pull/27311#discussion_r4171955724
##########
components/camel-consul/src/main/java/org/apache/camel/component/consul/cluster/ConsulClusterView.java:
##########
@@ -269,16 +329,29 @@ public void onComplete(ConsulResponse<Optional<Value>>
consulResponse) {
public void onFailure(Throwable throwable) {
LOGGER.debug("{}", throwable.getMessage(), throwable);
- if (sessionId.get() != null) {
- keyValueClient.releaseLock(configuration.getRootPath(),
sessionId.get());
+ // the leadership cannot be confirmed: give it up, and release the
lock if Consul can still be reached
+ localMember.setMaster(false);
+
+ String sid = sessionId.get();
+ if (sid != null) {
+ try {
+ keyValueClient.releaseLock(path, sid);
+ } catch (Exception e) {
+ LOGGER.debug("Failed to release lock on path '{}' with id
'{}': {}", path, sid, e.getMessage(), e);
+ }
}
Review Comment:
Please do not release the lock here. A transient failed query would let
another node take leadership right away (an explicit release skips Consul's
`lock-delay`), while this node's routes are still stopping asynchronously
(CAMEL-25062), so for a while there are two leaders. Keep `setMaster(false)`
and the scheduled re-watch, but leave the lock to the session TTL and
lock-delay: a node that really is cut off loses its session and with it the
lock.
##########
components/camel-consul/src/main/java/org/apache/camel/component/consul/cluster/ConsulClusterView.java:
##########
@@ -95,11 +99,11 @@ protected void doStart() throws Exception {
client = configuration.createConsulClient(getCamelContext());
sessionClient = client.sessionClient();
keyValueClient = client.keyValueClient();
+ // to watch again after a failed query
+ executorService =
getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(this,
Review Comment:
Minor: if `createSession()` fails during start, the service ends up FAILED,
`stop()` does nothing, and this executor stays alive until the context shuts
down. Consider creating it after the session has been created.
--
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]