Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id F05E6200C1E for ; Fri, 17 Feb 2017 22:12:51 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id EEF5F160B6D; Fri, 17 Feb 2017 21:12:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 47E25160B46 for ; Fri, 17 Feb 2017 22:12:51 +0100 (CET) Received: (qmail 97662 invoked by uid 500); 17 Feb 2017 21:12:50 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 97569 invoked by uid 99); 17 Feb 2017 21:12:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Feb 2017 21:12:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 327D0DFC63; Fri, 17 Feb 2017 21:12:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: clebertsuconic@apache.org To: commits@activemq.apache.org Date: Fri, 17 Feb 2017 21:12:50 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] activemq-artemis git commit: ARTEMIS-978 replicating live restarts as backup archived-at: Fri, 17 Feb 2017 21:12:52 -0000 Repository: activemq-artemis Updated Branches: refs/heads/master 41737c8f3 -> 06688f5c3 ARTEMIS-978 replicating live restarts as backup In a cluster of replicated live/backup pairs if a backup crashes and then its live crashes the cluster will retain the topology information of the live such that when the live server restarts it will check the cluster to see if its nodeID is present (which it will be) and then it will activate as a backup rather than a live. To prevent this situation an additional check is necessary to see if the server with the matching nodeID is actually active or not which is done by attempting to make a connection to it. Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/5bd19804 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/5bd19804 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/5bd19804 Branch: refs/heads/master Commit: 5bd198043850ec64c68e9bf0659543b9aebd90b6 Parents: 41737c8 Author: Justin Bertram Authored: Wed Feb 15 09:19:30 2017 -0600 Committer: Justin Bertram Committed: Fri Feb 17 12:55:11 2017 -0600 ---------------------------------------------------------------------- .../impl/SharedNothingLiveActivation.java | 29 +++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/5bd19804/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java ---------------------------------------------------------------------- diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java index ce05638..b36326c 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingLiveActivation.java @@ -29,7 +29,10 @@ import org.apache.activemq.artemis.api.core.Pair; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.TransportConfiguration; import org.apache.activemq.artemis.api.core.client.ActiveMQClient; +import org.apache.activemq.artemis.api.core.client.ClientSession; +import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.ClusterTopologyListener; +import org.apache.activemq.artemis.api.core.client.ServerLocator; import org.apache.activemq.artemis.api.core.client.TopologyMember; import org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal; import org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal; @@ -402,7 +405,7 @@ public class SharedNothingLiveActivation extends LiveActivation { @Override public void nodeUP(TopologyMember topologyMember, boolean last) { boolean isOurNodeId = nodeId != null && nodeId.toString().equals(topologyMember.getNodeId()); - if (isOurNodeId) { + if (isOurNodeId && isActive(topologyMember.getLive())) { isNodePresent = true; } if (isOurNodeId || last) { @@ -410,6 +413,30 @@ public class SharedNothingLiveActivation extends LiveActivation { } } + /** + * In a cluster of replicated live/backup pairs if a backup crashes and then its live crashes the cluster will + * retain the topology information of the live such that when the live server restarts it will check the + * cluster to see if its nodeID is present (which it will be) and then it will activate as a backup rather than + * a live. To prevent this situation an additional check is necessary to see if the server with the matching + * nodeID is actually active or not which is done by attempting to make a connection to it. + * + * @param transportConfiguration + * @return + */ + private boolean isActive(TransportConfiguration transportConfiguration) { + boolean result = false; + + try (ServerLocator serverLocator = ActiveMQClient.createServerLocator(false, transportConfiguration); + ClientSessionFactory clientSessionFactory = serverLocator.createSessionFactory(); + ClientSession clientSession = clientSessionFactory.createSession();) { + result = true; + } catch (Exception e) { + // ignore + } + + return result; + } + @Override public void nodeDown(long eventUID, String nodeID) { // no-op