private void checkTopology(
      final HornetQServer serverParameter,
      final String clusterName,
      final String nodeId1,
      final String nodeId2,
      final TransportConfiguration cfg1,
      final TransportConfiguration cfg2) {
    Topology topology =
        serverParameter.getClusterManager().getClusterConnection(clusterName).getTopology();

    TopologyMemberImpl member1 = topology.getMember(nodeId1);
    TopologyMemberImpl member2 = topology.getMember(nodeId2);
    Assert.assertEquals(member1.getLive().getParams().toString(), cfg1.getParams().toString());
    Assert.assertEquals(member2.getLive().getParams().toString(), cfg2.getParams().toString());
  }
  public synchronized void informClusterOfBackup() {
    String nodeID = server.getNodeID().toString();

    TopologyMemberImpl localMember = new TopologyMemberImpl(nodeID, null, null, connector);

    topology.updateAsLive(nodeID, localMember);
  }
  public void nodeAnnounced(
      final long uniqueEventID,
      final String nodeID,
      final String nodeName,
      final Pair<TransportConfiguration, TransportConfiguration> connectorPair,
      final boolean backup) {
    if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
      HornetQServerLogger.LOGGER.debug(
          this + "::NodeAnnounced, backup=" + backup + nodeID + connectorPair);
    }

    TransportConfiguration live = connectorPair.getA();
    TransportConfiguration backupTC = connectorPair.getB();
    TopologyMemberImpl newMember = new TopologyMemberImpl(nodeID, nodeName, live, backupTC);
    newMember.setUniqueEventID(uniqueEventID);
    if (backup) {
      topology.updateBackup(new TopologyMemberImpl(nodeID, nodeName, live, backupTC));
    } else {
      topology.updateMember(uniqueEventID, nodeID, newMember);
    }
  }
Example #4
0
  private boolean isLiveDown() {
    Collection<TopologyMemberImpl> nodes = topology.getMembers();
    Collection<ServerLocator> locatorsList = new LinkedList<ServerLocator>();
    AtomicInteger pingCount = new AtomicInteger(0);
    int total = 0;
    for (TopologyMemberImpl tm : nodes) if (useIt(tm)) total++;

    if (total < 1) return true;

    final CountDownLatch voteLatch = new CountDownLatch(total);
    try {
      for (TopologyMemberImpl tm : nodes) {
        Pair<TransportConfiguration, TransportConfiguration> pair = tm.getConnector();

        TransportConfiguration serverTC = pair.getA();
        if (useIt(tm)) {
          ServerLocatorImpl locator =
              (ServerLocatorImpl) HornetQClient.createServerLocatorWithoutHA(serverTC);
          locatorsList.add(locator);
          executor.submit(
              new QuorumVoteServerConnect(voteLatch, total, pingCount, locator, serverTC));
        }
      }

      try {
        voteLatch.await(LATCH_TIMEOUT, TimeUnit.SECONDS);
      } catch (InterruptedException interruption) {
        // No-op. The best the quorum can do now is to return the latest number it has
      }
      // -1: because the live server is not being filtered out.
      boolean vote = nodeIsDown(total, pingCount.get());
      HornetQServerLogger.LOGGER.trace(
          "quorum vote is liveIsDown=" + vote + ", count=" + pingCount);
      return vote;
    } finally {
      for (ServerLocator locator : locatorsList) {
        try {
          locator.close();
        } catch (Exception e) {
          // no-op
        }
      }
    }
  }
  @Test
  public void testSimpleDistributionBackupStrategyFull() throws Exception {
    HornetQServer server0 = createServer(0, 1, BackupStrategy.FULL);
    HornetQServer server1 = createServer(1, 0, BackupStrategy.FULL);
    TransportConfiguration liveConnector0 =
        getConnectorTransportConfiguration("liveConnector" + 0, 0);
    TransportConfiguration liveConnector1 =
        getConnectorTransportConfiguration("liveConnector" + 1, 1);

    try (ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(liveConnector0)) {
      server0.start();
      server1.start();
      ClientSessionFactory sessionFactory0 = serverLocator.createSessionFactory(liveConnector0);
      waitForRemoteBackup(sessionFactory0, 10);
      ClientSessionFactory sessionFactory1 = serverLocator.createSessionFactory(liveConnector1);
      waitForRemoteBackup(sessionFactory1, 10);
      Topology topology = serverLocator.getTopology();
      Collection<TopologyMemberImpl> members = topology.getMembers();
      assertEquals(members.size(), 2);
      Map<String, HornetQServer> backupServers0 =
          server0.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers0.size(), 1);
      Map<String, HornetQServer> backupServers1 =
          server1.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers1.size(), 1);
      HornetQServer backupServer0 = backupServers0.values().iterator().next();
      HornetQServer backupServer1 = backupServers1.values().iterator().next();
      waitForRemoteBackupSynchronization(backupServer0);
      waitForRemoteBackupSynchronization(backupServer1);
      assertEquals(server0.getNodeID(), backupServer1.getNodeID());
      assertEquals(server1.getNodeID(), backupServer0.getNodeID());
      Set<TransportConfiguration> backupAcceptors0 =
          backupServer0.getConfiguration().getAcceptorConfigurations();
      assertEquals(1, backupAcceptors0.size());
      assertEquals("5545", backupAcceptors0.iterator().next().getParams().get("port"));
      Set<TransportConfiguration> backupAcceptors1 =
          backupServer1.getConfiguration().getAcceptorConfigurations();
      assertEquals(1, backupAcceptors1.size());
      assertEquals("5546", backupAcceptors1.iterator().next().getParams().get("port"));
      Map<String, TransportConfiguration> connectorConfigurations0 =
          backupServer0.getConfiguration().getConnectorConfigurations();
      assertEquals(2, connectorConfigurations0.size());
      assertEquals("5545", connectorConfigurations0.get("liveConnector0").getParams().get("port"));
      assertEquals(
          "5446", connectorConfigurations0.get("remoteConnector0").getParams().get("port"));
      Map<String, TransportConfiguration> connectorConfigurations1 =
          backupServer1.getConfiguration().getConnectorConfigurations();
      assertEquals(2, connectorConfigurations1.size());
      assertEquals("5546", connectorConfigurations1.get("liveConnector1").getParams().get("port"));
      assertEquals(
          "5445", connectorConfigurations1.get("remoteConnector1").getParams().get("port"));
      if (policyType == HAPolicy.POLICY_TYPE.COLOCATED_SHARED_STORE) {
        assertEquals(
            server0.getConfiguration().getJournalDirectory(),
            backupServer1.getConfiguration().getJournalDirectory());
        assertEquals(
            server0.getConfiguration().getBindingsDirectory(),
            backupServer1.getConfiguration().getBindingsDirectory());
        assertEquals(
            server0.getConfiguration().getLargeMessagesDirectory(),
            backupServer1.getConfiguration().getLargeMessagesDirectory());
        assertEquals(
            server0.getConfiguration().getPagingDirectory(),
            backupServer1.getConfiguration().getPagingDirectory());
        assertEquals(
            server1.getConfiguration().getJournalDirectory(),
            backupServer0.getConfiguration().getJournalDirectory());
        assertEquals(
            server1.getConfiguration().getBindingsDirectory(),
            backupServer0.getConfiguration().getBindingsDirectory());
        assertEquals(
            server1.getConfiguration().getLargeMessagesDirectory(),
            backupServer0.getConfiguration().getLargeMessagesDirectory());
        assertEquals(
            server1.getConfiguration().getPagingDirectory(),
            backupServer0.getConfiguration().getPagingDirectory());
      } else {
        assertNotEquals(
            server0.getConfiguration().getJournalDirectory(),
            backupServer1.getConfiguration().getJournalDirectory());
        assertNotEquals(
            server0.getConfiguration().getBindingsDirectory(),
            backupServer1.getConfiguration().getBindingsDirectory());
        assertNotEquals(
            server0.getConfiguration().getLargeMessagesDirectory(),
            backupServer1.getConfiguration().getLargeMessagesDirectory());
        assertNotEquals(
            server0.getConfiguration().getPagingDirectory(),
            backupServer1.getConfiguration().getPagingDirectory());
        assertNotEquals(
            server1.getConfiguration().getJournalDirectory(),
            backupServer0.getConfiguration().getJournalDirectory());
        assertNotEquals(
            server1.getConfiguration().getBindingsDirectory(),
            backupServer0.getConfiguration().getBindingsDirectory());
        assertNotEquals(
            server1.getConfiguration().getLargeMessagesDirectory(),
            backupServer0.getConfiguration().getLargeMessagesDirectory());
        assertNotEquals(
            server1.getConfiguration().getPagingDirectory(),
            backupServer0.getConfiguration().getPagingDirectory());
      }
    } finally {
      server0.stop();
      server1.stop();
    }
  }
  @Test
  public void testSimpleDistributionOfBackupsMaxBackupsExceeded() throws Exception {
    HornetQServer server0 = createServer(0, 1, BackupStrategy.FULL);
    HornetQServer server1 = createServer(1, 0, BackupStrategy.FULL);
    HornetQServer server2 = createServer(2, 0, BackupStrategy.FULL);
    HornetQServer server3 = createServer(3, 0, BackupStrategy.FULL);
    TransportConfiguration liveConnector0 =
        getConnectorTransportConfiguration("liveConnector" + 0, 0);
    TransportConfiguration liveConnector1 =
        getConnectorTransportConfiguration("liveConnector" + 1, 1);
    TransportConfiguration liveConnector2 =
        getConnectorTransportConfiguration("liveConnector" + 2, 2);
    TransportConfiguration liveConnector3 =
        getConnectorTransportConfiguration("liveConnector" + 3, 3);

    try (ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(liveConnector0)) {
      server0.start();
      server1.start();
      ClientSessionFactory sessionFactory0 = serverLocator.createSessionFactory(liveConnector0);
      waitForRemoteBackup(sessionFactory0, 10);
      ClientSessionFactory sessionFactory1 = serverLocator.createSessionFactory(liveConnector1);
      waitForRemoteBackup(sessionFactory1, 10);
      Topology topology = serverLocator.getTopology();
      Collection<TopologyMemberImpl> members = topology.getMembers();
      assertEquals(members.size(), 2);
      Map<String, HornetQServer> backupServers0 =
          server0.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers0.size(), 1);
      Map<String, HornetQServer> backupServers1 =
          server1.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers1.size(), 1);
      HornetQServer backupServer0 = backupServers0.values().iterator().next();
      HornetQServer backupServer1 = backupServers1.values().iterator().next();
      waitForRemoteBackupSynchronization(backupServer0);
      waitForRemoteBackupSynchronization(backupServer1);
      assertEquals(server0.getNodeID(), backupServer1.getNodeID());
      assertEquals(server1.getNodeID(), backupServer0.getNodeID());
      server2.start();
      // just give server2 time to try both server 0 and 1
      ClientSessionFactory sessionFactory2 = serverLocator.createSessionFactory(liveConnector2);
      server3.start();
      ClientSessionFactory sessionFactory3 = serverLocator.createSessionFactory(liveConnector3);
      waitForRemoteBackup(sessionFactory2, 10);
      waitForRemoteBackup(sessionFactory3, 10);
      assertEquals(members.size(), 2);
      Map<String, HornetQServer> backupServers2 =
          server2.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers2.size(), 1);
      Map<String, HornetQServer> backupServers3 =
          server3.getClusterManager().getHAManager().getBackupServers();
      assertEquals(backupServers3.size(), 1);
      HornetQServer backupServer2 = backupServers2.values().iterator().next();
      HornetQServer backupServer3 = backupServers3.values().iterator().next();
      waitForRemoteBackupSynchronization(backupServer2);
      waitForRemoteBackupSynchronization(backupServer3);
      assertEquals(server0.getNodeID(), backupServer1.getNodeID());
      assertEquals(server1.getNodeID(), backupServer0.getNodeID());
      assertEquals(server2.getNodeID(), backupServer3.getNodeID());
      assertEquals(server3.getNodeID(), backupServer2.getNodeID());
    } finally {
      server0.stop();
      server1.stop();
      server2.stop();
      server3.stop();
    }
  }
  private synchronized void activate() throws Exception {
    if (!started) {
      return;
    }

    if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
      HornetQServerLogger.LOGGER.debug(
          "Activating cluster connection nodeID="
              + nodeManager.getNodeId()
              + " for server="
              + this.server);
    }

    liveNotifier = new LiveNotifier();
    liveNotifier.updateAsLive();
    liveNotifier.schedule();

    serverLocator = clusterConnector.createServerLocator();

    if (serverLocator != null) {

      if (!useDuplicateDetection) {
        HornetQServerLogger.LOGGER.debug(
            "DuplicateDetection is disabled, sending clustered messages blocked");
      }

      final TopologyMember currentMember = topology.getMember(manager.getNodeId());

      if (currentMember == null) {
        // sanity check only
        throw new IllegalStateException(
            "InternalError! The ClusterConnection doesn't know about its own node = " + this);
      }

      serverLocator.setNodeID(nodeManager.getNodeId().toString());
      serverLocator.setIdentity("(main-ClusterConnection::" + server.toString() + ")");
      serverLocator.setReconnectAttempts(0);
      serverLocator.setClusterConnection(true);
      serverLocator.setClusterTransportConfiguration(connector);
      serverLocator.setInitialConnectAttempts(-1);
      serverLocator.setClientFailureCheckPeriod(clientFailureCheckPeriod);
      serverLocator.setConnectionTTL(connectionTTL);
      serverLocator.setConfirmationWindowSize(confirmationWindowSize);
      // if not using duplicate detection, we will send blocked
      serverLocator.setBlockOnDurableSend(!useDuplicateDetection);
      serverLocator.setBlockOnNonDurableSend(!useDuplicateDetection);
      serverLocator.setCallTimeout(callTimeout);
      serverLocator.setCallFailoverTimeout(callFailoverTimeout);
      // No producer flow control on the bridges, as we don't want to lock the queues
      serverLocator.setProducerWindowSize(-1);

      if (retryInterval > 0) {
        this.serverLocator.setRetryInterval(retryInterval);
      }

      addClusterTopologyListener(this);

      serverLocator.setAfterConnectionInternalListener(this);

      serverLocator.start(server.getExecutorFactory().getExecutor());
    }

    if (managementService != null) {
      TypedProperties props = new TypedProperties();
      props.putSimpleStringProperty(new SimpleString("name"), name);
      Notification notification =
          new Notification(
              nodeManager.getNodeId().toString(),
              NotificationType.CLUSTER_CONNECTION_STARTED,
              props);
      HornetQServerLogger.LOGGER.debug("sending notification: " + notification);
      managementService.sendNotification(notification);
    }
  }
 public void removeClusterTopologyListener(final ClusterTopologyListener listener) {
   topology.removeClusterTopologyListener(listener);
 }
 public void addClusterTopologyListener(final ClusterTopologyListener listener) {
   topology.addClusterTopologyListener(listener);
 }
Example #10
0
 private TopologyMember getLocalMember() {
   return topology.getMember(manager.getNodeId());
 }