Search in sources :

Example 1 with ReplicationManager

use of org.apache.activemq.artemis.core.replication.ReplicationManager in project activemq-artemis by apache.

the class JournalStorageManager method stop.

@Override
public synchronized void stop(boolean ioCriticalError, boolean sendFailover) throws Exception {
    if (!started) {
        return;
    }
    if (!ioCriticalError) {
        performCachedLargeMessageDeletes();
        // Must call close to make sure last id is persisted
        if (journalLoaded && idGenerator != null)
            idGenerator.persistCurrentID();
    }
    final CountDownLatch latch = new CountDownLatch(1);
    try {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                latch.countDown();
            }
        });
        latch.await(30, TimeUnit.SECONDS);
    } catch (RejectedExecutionException ignored) {
    // that's ok
    }
    // We cache the variable as the replicator could be changed between here and the time we call stop
    // since sendLiveIsStopping may issue a close back from the channel
    // and we want to ensure a stop here just in case
    ReplicationManager replicatorInUse = replicator;
    if (replicatorInUse != null) {
        if (sendFailover) {
            final OperationContext token = replicator.sendLiveIsStopping(ReplicationLiveIsStoppingMessage.LiveStopping.FAIL_OVER);
            if (token != null) {
                try {
                    token.waitCompletion(5000);
                } catch (Exception e) {
                // ignore it
                }
            }
        }
        replicatorInUse.stop();
    }
    bindingsJournal.stop();
    messageJournal.stop();
    journalLoaded = false;
    started = false;
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) ReplicationManager(org.apache.activemq.artemis.core.replication.ReplicationManager) CountDownLatch(java.util.concurrent.CountDownLatch) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)

Example 2 with ReplicationManager

use of org.apache.activemq.artemis.core.replication.ReplicationManager in project activemq-artemis by apache.

the class SharedNothingLiveActivation method startReplication.

public void startReplication(CoreRemotingConnection rc, final ClusterConnection clusterConnection, final Pair<TransportConfiguration, TransportConfiguration> pair, final boolean isFailBackRequest) throws ActiveMQException {
    if (replicationManager != null) {
        throw new ActiveMQAlreadyReplicatingException();
    }
    if (!activeMQServer.isStarted()) {
        throw new ActiveMQIllegalStateException();
    }
    synchronized (replicationLock) {
        if (replicationManager != null) {
            throw new ActiveMQAlreadyReplicatingException();
        }
        ReplicationFailureListener listener = new ReplicationFailureListener();
        rc.addCloseListener(listener);
        rc.addFailureListener(listener);
        replicationManager = new ReplicationManager(rc, clusterConnection.getCallTimeout(), replicatedPolicy.getInitialReplicationSyncTimeout(), activeMQServer.getExecutorFactory());
        replicationManager.start();
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    activeMQServer.getStorageManager().startReplication(replicationManager, activeMQServer.getPagingManager(), activeMQServer.getNodeID().toString(), isFailBackRequest && replicatedPolicy.isAllowAutoFailBack(), replicatedPolicy.getInitialReplicationSyncTimeout());
                    clusterConnection.nodeAnnounced(System.currentTimeMillis(), activeMQServer.getNodeID().toString(), replicatedPolicy.getGroupName(), replicatedPolicy.getScaleDownGroupName(), pair, true);
                    if (isFailBackRequest && replicatedPolicy.isAllowAutoFailBack()) {
                        BackupTopologyListener listener1 = new BackupTopologyListener(activeMQServer.getNodeID().toString(), clusterConnection.getConnector());
                        clusterConnection.addClusterTopologyListener(listener1);
                        if (listener1.waitForBackup()) {
                            // if we have to many backups kept or are not configured to restart just stop, otherwise restart as a backup
                            activeMQServer.fail(true);
                            ActiveMQServerLogger.LOGGER.restartingReplicatedBackupAfterFailback();
                            // activeMQServer.moveServerData(replicatedPolicy.getReplicaPolicy().getMaxSavedReplicatedJournalsSize());
                            activeMQServer.setHAPolicy(replicatedPolicy.getReplicaPolicy());
                            activeMQServer.start();
                        } else {
                            ActiveMQServerLogger.LOGGER.failbackMissedBackupAnnouncement();
                        }
                    }
                } catch (Exception e) {
                    if (activeMQServer.getState() == ActiveMQServerImpl.SERVER_STATE.STARTED) {
                        /*
                   * The reasoning here is that the exception was either caused by (1) the
                   * (interaction with) the backup, or (2) by an IO Error at the storage. If (1), we
                   * can swallow the exception and ignore the replication request. If (2) the live
                   * will crash shortly.
                   */
                        ActiveMQServerLogger.LOGGER.errorStartingReplication(e);
                    }
                    try {
                        ActiveMQServerImpl.stopComponent(replicationManager);
                    } catch (Exception amqe) {
                        ActiveMQServerLogger.LOGGER.errorStoppingReplication(amqe);
                    } finally {
                        synchronized (replicationLock) {
                            replicationManager = null;
                        }
                    }
                }
            }
        });
        t.start();
    }
}
Also used : ReplicationManager(org.apache.activemq.artemis.core.replication.ReplicationManager) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQAlreadyReplicatingException(org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQDisconnectedException(org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQAlreadyReplicatingException(org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)

Example 3 with ReplicationManager

use of org.apache.activemq.artemis.core.replication.ReplicationManager in project activemq-artemis by apache.

the class ReplicationTest method testConnectIntoNonBackup.

@Test
public void testConnectIntoNonBackup() throws Exception {
    setupServer(false);
    try {
        ClientSessionFactory sf = createSessionFactory(locator);
        manager = new ReplicationManager((CoreRemotingConnection) sf.getConnection(), sf.getServerLocator().getCallTimeout(), sf.getServerLocator().getCallTimeout(), factory);
        addActiveMQComponent(manager);
        manager.start();
        Assert.fail("Exception was expected");
    } catch (ActiveMQNotConnectedException nce) {
    // ok
    } catch (ActiveMQException expected) {
        fail("Invalid Exception type:" + expected.getType());
    }
}
Also used : ReplicationManager(org.apache.activemq.artemis.core.replication.ReplicationManager) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) Test(org.junit.Test)

Example 4 with ReplicationManager

use of org.apache.activemq.artemis.core.replication.ReplicationManager in project activemq-artemis by apache.

the class SharedNothingLiveActivation method sendLiveIsStopping.

@Override
public void sendLiveIsStopping() {
    final ReplicationManager localReplicationManager = replicationManager;
    if (localReplicationManager != null) {
        localReplicationManager.sendLiveIsStopping(ReplicationLiveIsStoppingMessage.LiveStopping.STOP_CALLED);
        // Schedule for 10 seconds
        // this pool gets a 'hard' shutdown, no need to manage the Future of this Runnable.
        activeMQServer.getScheduledPool().schedule(new Runnable() {

            @Override
            public void run() {
                localReplicationManager.clearReplicationTokens();
            }
        }, 30, TimeUnit.SECONDS);
    }
}
Also used : ReplicationManager(org.apache.activemq.artemis.core.replication.ReplicationManager)

Aggregations

ReplicationManager (org.apache.activemq.artemis.core.replication.ReplicationManager)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ActiveMQAlreadyReplicatingException (org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)1 ActiveMQDisconnectedException (org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException)1 ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)1 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 OperationContext (org.apache.activemq.artemis.core.persistence.OperationContext)1 CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)1 Test (org.junit.Test)1