Search in sources :

Example 1 with FileMoveManager

use of org.apache.activemq.artemis.core.server.files.FileMoveManager in project activemq-artemis by apache.

the class ActiveMQServerImpl method moveServerData.

/**
 * Move data away before starting data synchronization for fail-back.
 * <p>
 * Use case is a server, upon restarting, finding a former backup running in its place. It will
 * move any older data away and log a warning about it.
 */
void moveServerData(int maxSavedReplicated) throws IOException {
    File[] dataDirs = new File[] { configuration.getBindingsLocation(), configuration.getJournalLocation(), configuration.getPagingLocation(), configuration.getLargeMessagesLocation() };
    for (File data : dataDirs) {
        FileMoveManager moveManager = new FileMoveManager(data, maxSavedReplicated);
        moveManager.doMove();
    }
}
Also used : FileMoveManager(org.apache.activemq.artemis.core.server.files.FileMoveManager) SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) File(java.io.File)

Example 2 with FileMoveManager

use of org.apache.activemq.artemis.core.server.files.FileMoveManager in project activemq-artemis by apache.

the class FailoverTest method simpleFailover.

/**
 * @param doFailBack
 * @throws Exception
 */
private void simpleFailover(boolean isReplicated, boolean doFailBack) throws Exception {
    locator.setFailoverOnInitialConnection(true);
    createSessionFactory();
    ClientSession session = createSessionAndQueue();
    ClientProducer producer = addClientProducer(session.createProducer(FailoverTestBase.ADDRESS));
    sendMessages(session, producer, NUM_MESSAGES);
    producer.close();
    session.commit();
    SimpleString liveId = liveServer.getServer().getNodeID();
    crash(session);
    session.start();
    ClientConsumer consumer = addClientConsumer(session.createConsumer(FailoverTestBase.ADDRESS));
    receiveMessages(consumer);
    assertNoMoreMessages(consumer);
    consumer.close();
    producer = addClientProducer(session.createProducer(FailoverTestBase.ADDRESS));
    sendMessages(session, producer, NUM_MESSAGES);
    producer.close();
    session.commit();
    Assert.assertEquals("backup must be running with the same nodeID", liveId, backupServer.getServer().getNodeID());
    if (doFailBack) {
        Assert.assertFalse("must NOT be a backup", liveServer.getServer().getHAPolicy().isBackup());
        adaptLiveConfigForReplicatedFailBack(liveServer);
        beforeRestart(liveServer);
        liveServer.start();
        Assert.assertTrue("live initialized...", liveServer.getServer().waitForActivation(40, TimeUnit.SECONDS));
        int i = 0;
        while (!backupServer.isStarted() && i++ < 100) {
            Thread.sleep(100);
        }
        liveServer.getServer().waitForActivation(5, TimeUnit.SECONDS);
        Assert.assertTrue(backupServer.isStarted());
        if (isReplicated) {
            FileMoveManager moveManager = new FileMoveManager(backupServer.getServer().getConfiguration().getJournalLocation(), 0);
            Assert.assertEquals(1, moveManager.getNumberOfFolders());
        }
    } else {
        backupServer.stop();
        beforeRestart(backupServer);
        backupServer.start();
        Assert.assertTrue(backupServer.getServer().waitForActivation(10, TimeUnit.SECONDS));
    }
    ClientSession session2 = createSession(sf, false, false);
    session2.start();
    ClientConsumer consumer2 = session2.createConsumer(FailoverTestBase.ADDRESS);
    receiveMessages(consumer2, 0, NUM_MESSAGES, true);
    assertNoMoreMessages(consumer2);
    session2.commit();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) FileMoveManager(org.apache.activemq.artemis.core.server.files.FileMoveManager) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 3 with FileMoveManager

use of org.apache.activemq.artemis.core.server.files.FileMoveManager in project activemq-artemis by apache.

the class BackupSyncJournalTest method testFailBack.

/**
 * Basic fail-back test.
 *
 * @throws Exception
 */
@Test
public void testFailBack() throws Exception {
    createProducerSendSomeMessages();
    startBackupCrashLive();
    receiveMsgsInRange(0, n_msgs);
    assertNoMoreMessages();
    sendMessages(session, producer, n_msgs);
    receiveMsgsInRange(0, n_msgs);
    assertNoMoreMessages();
    sendMessages(session, producer, 2 * n_msgs);
    assertFalse("must NOT be a backup", liveServer.getServer().getHAPolicy().isBackup());
    adaptLiveConfigForReplicatedFailBack(liveServer);
    FileMoveManager liveMoveManager = new FileMoveManager(liveServer.getServer().getConfiguration().getJournalLocation(), -1);
    liveServer.getServer().lockActivation();
    try {
        liveServer.start();
        assertTrue("must have become a backup", liveServer.getServer().getHAPolicy().isBackup());
        Assert.assertEquals(0, liveMoveManager.getNumberOfFolders());
    } finally {
        liveServer.getServer().unlockActivation();
    }
    waitForServerToStart(liveServer.getServer());
    liveServer.getServer().waitForActivation(10, TimeUnit.SECONDS);
    Assert.assertEquals(1, liveMoveManager.getNumberOfFolders());
    assertTrue("must be active now", !liveServer.getServer().getHAPolicy().isBackup());
    assertTrue("Fail-back must initialize live!", liveServer.getServer().waitForActivation(15, TimeUnit.SECONDS));
    assertFalse("must be LIVE!", liveServer.getServer().getHAPolicy().isBackup());
    int i = 0;
    while (!backupServer.isStarted() && i++ < 100) {
        Thread.sleep(100);
    }
    assertTrue(backupServer.getServer().isStarted());
    assertTrue(liveServer.getServer().isStarted());
    receiveMsgsInRange(0, 2 * n_msgs);
    assertNoMoreMessages();
}
Also used : FileMoveManager(org.apache.activemq.artemis.core.server.files.FileMoveManager) Test(org.junit.Test)

Aggregations

FileMoveManager (org.apache.activemq.artemis.core.server.files.FileMoveManager)3 File (java.io.File)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)1 Test (org.junit.Test)1