ARTEMIS-2014 Treat inability to create directory for paging as critial

This commit is contained in:
Justin Bertram 2018-08-07 10:51:56 -05:00
parent 2eb1a526f0
commit 0ae7d32532
2 changed files with 62 additions and 2 deletions

View File

@ -224,8 +224,10 @@ public abstract class AbstractSequentialFileFactory implements SequentialFileFac
@Override @Override
public void createDirs() throws Exception { public void createDirs() throws Exception {
boolean ok = journalDir.mkdirs(); boolean ok = journalDir.mkdirs();
if (!ok) { if (!ok && !journalDir.exists()) {
throw new IOException("Failed to create directory " + journalDir); IOException e = new IOException("Unable to create directory: " + journalDir);
onIOError(e, e.getMessage(), null);
throw e;
} }
} }

View File

@ -35,6 +35,7 @@ import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -96,6 +97,7 @@ import org.apache.activemq.artemis.utils.actors.ArtemisExecutor;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -1400,6 +1402,62 @@ public class PagingTest extends ActiveMQTestBase {
} }
@Test
public void testInabilityToCreateDirectoryDuringPaging() throws Exception {
// this test only applies to file-based stores
Assume.assumeTrue(storeType == StoreConfiguration.StoreType.FILE);
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false).setPagingDirectory(UUID.randomUUID().toString());
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
final int numberOfMessages = 100;
locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
session.createQueue(PagingTest.ADDRESS, RoutingType.MULTICAST, PagingTest.ADDRESS, null, true);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message = null;
byte[] body = new byte[MESSAGE_SIZE];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= MESSAGE_SIZE; j++) {
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++) {
message = session.createMessage(true);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
try {
producer.send(message);
} catch (Exception e) {
// ignore
}
}
assertTrue(Wait.waitFor(() -> server.getState() == ActiveMQServer.SERVER_STATE.STOPPED, 5000, 200));
session.close();
sf.close();
locator.close();
}
/** /**
* This test will remove all the page directories during a restart, simulating a crash scenario. The server should still start after this * This test will remove all the page directories during a restart, simulating a crash scenario. The server should still start after this
*/ */