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();
}
}
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();
}
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();
}
Aggregations