Search in sources :

Example 1 with SharedNothingBackupActivation

use of org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation in project activemq-artemis by apache.

the class BackupSyncDelay method intercept.

@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
    if (packet.getType() == PacketImpl.BACKUP_REGISTRATION) {
        try {
            SharedNothingBackupActivation activation = (SharedNothingBackupActivation) backup.getActivation();
            ReplicationEndpoint repEnd = activation.getReplicationEndpoint();
            handler.addSubHandler(repEnd);
            Channel repChannel = repEnd.getChannel();
            repChannel.setHandler(handler);
            handler.setChannel(repChannel);
            live.getRemotingService().removeIncomingInterceptor(this);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return true;
}
Also used : ReplicationEndpoint(org.apache.activemq.artemis.core.replication.ReplicationEndpoint) Channel(org.apache.activemq.artemis.core.protocol.core.Channel) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 2 with SharedNothingBackupActivation

use of org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation in project activemq-artemis by apache.

the class HAPolicyConfigurationTest method ReplicaTest3.

@Test
public void ReplicaTest3() throws Exception {
    Configuration configuration = createConfiguration("replica-hapolicy-config3.xml");
    ActiveMQServerImpl server = new ActiveMQServerImpl(configuration);
    try {
        server.start();
        Activation activation = server.getActivation();
        assertTrue(activation instanceof SharedNothingBackupActivation);
        HAPolicy haPolicy = server.getHAPolicy();
        assertTrue(haPolicy instanceof ReplicaPolicy);
        ReplicaPolicy replicaPolicy = (ReplicaPolicy) haPolicy;
        assertEquals(replicaPolicy.getGroupName(), "tiddles");
        assertEquals(replicaPolicy.getMaxSavedReplicatedJournalsSize(), 22);
        assertEquals(replicaPolicy.getClusterName(), "33rrrrr");
        assertFalse(replicaPolicy.isRestartBackup());
        ScaleDownPolicy scaleDownPolicy = replicaPolicy.getScaleDownPolicy();
        assertNull(scaleDownPolicy);
    } finally {
        server.stop();
    }
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) HAPolicyConfiguration(org.apache.activemq.artemis.core.config.HAPolicyConfiguration) HAPolicy(org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy) ReplicaPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ReplicaPolicy) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation) ColocatedActivation(org.apache.activemq.artemis.core.server.impl.ColocatedActivation) Activation(org.apache.activemq.artemis.core.server.impl.Activation) SharedNothingLiveActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingLiveActivation) SharedStoreLiveActivation(org.apache.activemq.artemis.core.server.impl.SharedStoreLiveActivation) SharedStoreBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedStoreBackupActivation) LiveOnlyActivation(org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation) ScaleDownPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ScaleDownPolicy) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation) Test(org.junit.Test)

Example 3 with SharedNothingBackupActivation

use of org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation in project activemq-artemis by apache.

the class HAPolicyConfigurationTest method ReplicaTest.

@Test
public void ReplicaTest() throws Exception {
    Configuration configuration = createConfiguration("replica-hapolicy-config.xml");
    ActiveMQServerImpl server = new ActiveMQServerImpl(configuration);
    try {
        server.start();
        Activation activation = server.getActivation();
        assertTrue(activation instanceof SharedNothingBackupActivation);
        HAPolicy haPolicy = server.getHAPolicy();
        assertTrue(haPolicy instanceof ReplicaPolicy);
        ReplicaPolicy replicaPolicy = (ReplicaPolicy) haPolicy;
        assertEquals(replicaPolicy.getGroupName(), "tiddles");
        assertEquals(replicaPolicy.getMaxSavedReplicatedJournalsSize(), 22);
        assertEquals(replicaPolicy.getClusterName(), "33rrrrr");
        assertFalse(replicaPolicy.isRestartBackup());
        assertTrue(replicaPolicy.isAllowFailback());
        assertEquals(replicaPolicy.getInitialReplicationSyncTimeout(), 9876);
        ScaleDownPolicy scaleDownPolicy = replicaPolicy.getScaleDownPolicy();
        assertNotNull(scaleDownPolicy);
        assertEquals(scaleDownPolicy.getGroupName(), "boo!");
        assertEquals(scaleDownPolicy.getDiscoveryGroup(), "wahey");
        List<String> connectors = scaleDownPolicy.getConnectors();
        assertNotNull(connectors);
        assertEquals(connectors.size(), 0);
    } finally {
        server.stop();
    }
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) HAPolicyConfiguration(org.apache.activemq.artemis.core.config.HAPolicyConfiguration) HAPolicy(org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy) ReplicaPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ReplicaPolicy) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation) ColocatedActivation(org.apache.activemq.artemis.core.server.impl.ColocatedActivation) Activation(org.apache.activemq.artemis.core.server.impl.Activation) SharedNothingLiveActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingLiveActivation) SharedStoreLiveActivation(org.apache.activemq.artemis.core.server.impl.SharedStoreLiveActivation) SharedStoreBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedStoreBackupActivation) LiveOnlyActivation(org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation) ScaleDownPolicy(org.apache.activemq.artemis.core.server.cluster.ha.ScaleDownPolicy) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation) Test(org.junit.Test)

Example 4 with SharedNothingBackupActivation

use of org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation in project activemq-artemis by apache.

the class GroupingFailoverTestBase method testGroupingLocalHandlerFailsMultipleGroups.

@Test
public void testGroupingLocalHandlerFailsMultipleGroups() throws Exception {
    setupBackupServer(2, 0, isFileStorage(), isSharedStore(), isNetty());
    setupLiveServer(0, isFileStorage(), isSharedStore(), isNetty(), false);
    setupLiveServer(1, isFileStorage(), isSharedStore(), isNetty(), false);
    setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1);
    setupClusterConnection("cluster1", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0);
    setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 2, 1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.LOCAL, 0);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.LOCAL, 2);
    if (!isSharedStore()) {
        ((ReplicatedPolicyConfiguration) servers[0].getConfiguration().getHAPolicyConfiguration()).setGroupName("group1");
        ((ReplicatedPolicyConfiguration) servers[1].getConfiguration().getHAPolicyConfiguration()).setGroupName("group2");
        ((ReplicaPolicyConfiguration) servers[2].getConfiguration().getHAPolicyConfiguration()).setGroupName("group1");
    }
    startServers(0, 1, 2);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());
    createQueue(0, "queues.testaddress", "queue0", null, true);
    waitForBindings(0, "queues.testaddress", 1, 0, true);
    createQueue(1, "queues.testaddress", "queue0", null, true);
    waitForBindings(1, "queues.testaddress", 1, 0, true);
    addConsumer(0, 0, "queue0", null);
    addConsumer(1, 1, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 1, false);
    waitForBindings(1, "queues.testaddress", 1, 1, false);
    waitForBindings(0, "queues.testaddress", 1, 1, true);
    waitForBindings(1, "queues.testaddress", 1, 1, true);
    waitForTopology(servers[1], 2);
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id1"));
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id2"));
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id3"));
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id4"));
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id5"));
    sendWithProperty(0, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id6"));
    verifyReceiveAllWithGroupIDRoundRobin(0, 30, 0, 1);
    if (!isSharedStore()) {
        SharedNothingBackupActivation backupActivation = (SharedNothingBackupActivation) servers[2].getActivation();
        assertTrue(backupActivation.waitForBackupSync(10, TimeUnit.SECONDS));
    }
    closeSessionFactory(0);
    servers[0].fail(true);
    waitForServerRestart(2);
    setupSessionFactory(2, isNetty());
    addConsumer(2, 2, "queue0", null);
    waitForBindings(2, "queues.testaddress", 1, 1, true);
    waitForBindings(2, "queues.testaddress", 1, 1, false);
    waitForBindings(1, "queues.testaddress", 1, 1, true);
    waitForBindings(1, "queues.testaddress", 1, 1, false);
    sendWithProperty(2, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id1"));
    sendWithProperty(2, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id2"));
    sendWithProperty(2, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id3"));
    sendWithProperty(2, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id4"));
    sendWithProperty(2, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id5"));
    sendWithProperty(2, "queues.testaddress", 10, false, Message.HDR_GROUP_ID, new SimpleString("id6"));
    verifyReceiveAllWithGroupIDRoundRobin(2, 30, 1, 2);
}
Also used : ReplicatedPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ReplicaPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation) Test(org.junit.Test)

Example 5 with SharedNothingBackupActivation

use of org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation in project activemq-artemis by apache.

the class ActiveMQTestBase method waitForRemoteBackup.

/**
 * @param sessionFactoryP
 * @param seconds
 * @param waitForSync
 * @param backup
 */
public static final void waitForRemoteBackup(ClientSessionFactory sessionFactoryP, int seconds, boolean waitForSync, final ActiveMQServer backup) {
    ClientSessionFactoryInternal sessionFactory = (ClientSessionFactoryInternal) sessionFactoryP;
    final ActiveMQServerImpl actualServer = (ActiveMQServerImpl) backup;
    final long toWait = seconds * 1000;
    final long time = System.currentTimeMillis();
    int loop = 0;
    while (true) {
        Activation activation = actualServer.getActivation();
        boolean isReplicated = !backup.getHAPolicy().isSharedStore();
        boolean isRemoteUpToDate = true;
        if (isReplicated) {
            if (activation instanceof SharedNothingBackupActivation) {
                isRemoteUpToDate = backup.isReplicaSync();
            } else {
                // we may have already failed over and changed the Activation
                if (actualServer.isStarted()) {
                    // let it fail a few time to have time to start stopping in the case of waiting to failback
                    isRemoteUpToDate = loop++ > 10;
                } else {
                    // we could be waiting to failback or restart if the server is stopping
                    isRemoteUpToDate = false;
                }
            }
        }
        if ((sessionFactory == null || sessionFactory.getBackupConnector() != null) && (isRemoteUpToDate || !waitForSync) && (!waitForSync || actualServer.getBackupManager() != null && actualServer.getBackupManager().isBackupAnnounced())) {
            break;
        }
        if (System.currentTimeMillis() > (time + toWait)) {
            fail("backup started? (" + actualServer.isStarted() + "). Finished synchronizing (" + (activation) + "). SessionFactory!=null ? " + (sessionFactory != null) + " || sessionFactory.getBackupConnector()==" + (sessionFactory != null ? sessionFactory.getBackupConnector() : "not-applicable"));
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            fail(e.getMessage());
        }
    }
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) Activation(org.apache.activemq.artemis.core.server.impl.Activation) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation)

Aggregations

SharedNothingBackupActivation (org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation)7 Activation (org.apache.activemq.artemis.core.server.impl.Activation)4 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)4 Test (org.junit.Test)4 Configuration (org.apache.activemq.artemis.core.config.Configuration)3 HAPolicyConfiguration (org.apache.activemq.artemis.core.config.HAPolicyConfiguration)3 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)3 HAPolicy (org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy)3 ReplicaPolicy (org.apache.activemq.artemis.core.server.cluster.ha.ReplicaPolicy)3 ScaleDownPolicy (org.apache.activemq.artemis.core.server.cluster.ha.ScaleDownPolicy)3 ColocatedActivation (org.apache.activemq.artemis.core.server.impl.ColocatedActivation)3 LiveOnlyActivation (org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation)3 SharedNothingLiveActivation (org.apache.activemq.artemis.core.server.impl.SharedNothingLiveActivation)3 SharedStoreBackupActivation (org.apache.activemq.artemis.core.server.impl.SharedStoreBackupActivation)3 SharedStoreLiveActivation (org.apache.activemq.artemis.core.server.impl.SharedStoreLiveActivation)3 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)1 ReplicaPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration)1 ReplicatedPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration)1