public ColocatedActivation(ActiveMQServerImpl activeMQServer, ColocatedPolicy colocatedPolicy, LiveActivation liveActivation) { server = activeMQServer; this.colocatedPolicy = colocatedPolicy; this.liveActivation = liveActivation; colocatedHAManager = new ColocatedHAManager(colocatedPolicy, server); }
public synchronized boolean activateBackup(int backupSize, String journalDirectory, String bindingsDirectory, String largeMessagesDirectory, String pagingDirectory, SimpleString nodeID) throws Exception { if (backupServers.size() >= haPolicy.getMaxBackups() || backupSize != backupServers.size()) { return false; } if (haPolicy.getBackupPolicy().isSharedStore()) { return activateSharedStoreBackup(journalDirectory, bindingsDirectory, largeMessagesDirectory, pagingDirectory); } else { return activateReplicatedBackup(nodeID); } }
/** * update the backups configuration * * @param backupConfiguration the configuration to update * @param name the new name of the backup * @param portOffset the offset for the acceptors and any connectors that need changing * @param remoteConnectors the connectors that don't need off setting, typically remote * @param journalDirectory * @param bindingsDirectory * @param largeMessagesDirectory * @param pagingDirectory * @param fullServer */ private static void updateSharedStoreConfiguration(Configuration backupConfiguration, String name, int portOffset, List<String> remoteConnectors, String journalDirectory, String bindingsDirectory, String largeMessagesDirectory, String pagingDirectory, boolean fullServer) { backupConfiguration.setName(name); backupConfiguration.setJournalDirectory(journalDirectory); backupConfiguration.setBindingsDirectory(bindingsDirectory); backupConfiguration.setLargeMessagesDirectory(largeMessagesDirectory); backupConfiguration.setPagingDirectory(pagingDirectory); updateAcceptorsAndConnectors(backupConfiguration, portOffset, remoteConnectors, fullServer); }
@Override public Vote vote(Vote vote) { int size = colocatedHAManager.getBackupServers().size(); return new RequestBackupVote(size, server.getNodeID().toString(), size < colocatedPolicy.getMaxBackups()); }
private static void updateAcceptorsAndConnectors(Configuration backupConfiguration, int portOffset, List<String> remoteConnectors, boolean fullServer) { //we only do this if we are a full server, if scale down then our acceptors wont be needed and our connectors will // be the same as the parent server if (fullServer) { Set<TransportConfiguration> acceptors = backupConfiguration.getAcceptorConfigurations(); for (TransportConfiguration acceptor : acceptors) { updatebackupParams(backupConfiguration.getName(), portOffset, acceptor.getParams()); } Map<String, TransportConfiguration> connectorConfigurations = backupConfiguration.getConnectorConfigurations(); for (Map.Entry<String, TransportConfiguration> entry : connectorConfigurations.entrySet()) { //check to make sure we aren't a remote connector as this shouldn't be changed if (!remoteConnectors.contains(entry.getValue().getName())) { updatebackupParams(backupConfiguration.getName(), portOffset, entry.getValue().getParams()); } } } else { //if we are scaling down then we wont need any acceptors but clear anyway for belts and braces backupConfiguration.getAcceptorConfigurations().clear(); } }
@Override public void allVotesCast(Topology voteTopology) { //if we have any nodes that we can request then send a request if (nodes.size() > 0) { Pair<String, Integer> decision = getDecision(); TopologyMemberImpl member = voteTopology.getMember(decision.getA()); try { boolean backupStarted = colocatedHAManager.requestBackup(member.getConnector(), decision.getB().intValue(), !colocatedPolicy.isSharedStore()); if (!backupStarted) { nodes.clear(); server.getScheduledPool().schedule(new Runnable() { @Override public void run() { server.getClusterManager().getQuorumManager().vote(new RequestBackupQuorumVote()); } }, colocatedPolicy.getBackupRequestRetryInterval(), TimeUnit.MILLISECONDS); } } catch (Exception e) { ActiveMQServerLogger.LOGGER.failedToSendRequestToNode(e); } } else { nodes.clear(); server.getScheduledPool().schedule(new Runnable() { @Override public void run() { server.getClusterManager().getQuorumManager().vote(RequestBackupQuorumVote.this); } }, colocatedPolicy.getBackupRequestRetryInterval(), TimeUnit.MILLISECONDS); } }
private synchronized boolean activateSharedStoreBackup(String journalDirectory, String bindingsDirectory, String largeMessagesDirectory, String pagingDirectory) throws Exception { Configuration configuration = server.getConfiguration().copy(); ActiveMQServer backup = server.createBackupServer(configuration); try { int portOffset = haPolicy.getBackupPortOffset() * (backupServers.size() + 1); String name = "colocated_backup_" + backupServers.size() + 1; //make sure we don't restart as we are colocated haPolicy.getBackupPolicy().setRestartBackup(false); //set the backup policy backup.setHAPolicy(haPolicy.getBackupPolicy()); updateSharedStoreConfiguration(configuration, name, portOffset, haPolicy.getExcludedConnectors(), journalDirectory, bindingsDirectory, largeMessagesDirectory, pagingDirectory, haPolicy.getBackupPolicy().getScaleDownPolicy() == null); backupServers.put(configuration.getName(), backup); backup.start(); } catch (Exception e) { backup.stop(); ActiveMQServerLogger.LOGGER.activateSharedStoreSlaveFailed(e); return false; } ActiveMQServerLogger.LOGGER.activatingSharedStoreSlave(); return true; }
@Override public void handlePacket(Packet packet) { if (packet.getType() == PacketImpl.BACKUP_REQUEST) { BackupRequestMessage backupRequestMessage = (BackupRequestMessage) packet; boolean started = false; try { started = colocatedHAManager.activateBackup(backupRequestMessage.getBackupSize(), backupRequestMessage.getJournalDirectory(), backupRequestMessage.getBindingsDirectory(), backupRequestMessage.getLargeMessagesDirectory(), backupRequestMessage.getPagingDirectory(), backupRequestMessage.getNodeID()); } catch (Exception e) { ActiveMQServerLogger.LOGGER.failedToActivateBackup(e); } channel.send(new BackupResponseMessage(started)); } else if (activationChannelHandler != null) { activationChannelHandler.handlePacket(packet); } } };
updateReplicatedConfiguration(configuration, name, portOffset, haPolicy.getExcludedConnectors(), haPolicy.getBackupPolicy().getScaleDownPolicy() == null); backup.addActivationParam(ActivationParams.REPLICATION_ENDPOINT, member); backupServers.put(configuration.getName(), backup);
/** * update the backups configuration * * @param backupConfiguration the configuration to update * @param name the new name of the backup * @param portOffset the offset for the acceptors and any connectors that need changing * @param remoteConnectors the connectors that don't need off setting, typically remote */ private static void updateReplicatedConfiguration(Configuration backupConfiguration, String name, int portOffset, List<String> remoteConnectors, boolean fullServer) { backupConfiguration.setName(name); backupConfiguration.setJournalDirectory(backupConfiguration.getJournalDirectory() + name); backupConfiguration.setPagingDirectory(backupConfiguration.getPagingDirectory() + name); backupConfiguration.setLargeMessagesDirectory(backupConfiguration.getLargeMessagesDirectory() + name); backupConfiguration.setBindingsDirectory(backupConfiguration.getBindingsDirectory() + name); updateAcceptorsAndConnectors(backupConfiguration, portOffset, remoteConnectors, fullServer); }