This closes #425

This commit is contained in:
Clebert Suconic 2016-04-04 12:23:36 -04:00
commit b16b864f07
4 changed files with 47 additions and 4 deletions

View File

@ -50,6 +50,8 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor
private final AtomicBoolean running = new AtomicBoolean(false);
private static final String AIO_TEST_FILE = ".aio-test";
// This method exists just to make debug easier.
// I could replace log.trace by log.info temporarily while I was debugging
// Journal
@ -114,6 +116,36 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor
return LibaioContext.isLoaded();
}
public static boolean isSupported(File journalPath) {
if (!isSupported()) {
return false;
}
File aioTestFile = new File(journalPath, AIO_TEST_FILE);
try {
int fd = LibaioContext.open(aioTestFile.getAbsolutePath(), true);
LibaioContext.close(fd);
aioTestFile.delete();
}
catch (Exception e) {
// try to handle the file using plain Java
// return false if and only if we can create/remove the file using
// plain Java but not using AIO
try {
if (!aioTestFile.exists()) {
if (!aioTestFile.createNewFile()) return true;
}
if (!aioTestFile.delete()) return true;
}
catch (Exception ie) {
// we can not even create the test file using plain java
return true;
}
return false;
}
return true;
}
@Override
public ByteBuffer allocateDirectBuffer(final int size) {

View File

@ -390,7 +390,7 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
*/
public static native int open(String path, boolean direct);
static native void close(int fd);
public static native void close(int fd);
/**
*/

View File

@ -1479,4 +1479,9 @@ public interface ActiveMQServerLogger extends BasicLogger {
@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 224070, value = "Received Interrupt Exception whilst waiting for component to shutdown: {0}", format = Message.Format.MESSAGE_FORMAT)
void interruptWhilstStoppingComponent(String componentClassName);
@LogMessage(level = Logger.Level.INFO)
@Message(id = 224072, value = "libaio was found but the filesystem does not support AIO. Switching the configuration into NIO. Journal path: {0}", format = Message.Format.MESSAGE_FORMAT)
void switchingNIOonPath(String journalPath);
}

View File

@ -1682,9 +1682,15 @@ public class ActiveMQServerImpl implements ActiveMQServer {
// Create the pools - we have two pools - one for non scheduled - and another for scheduled
initializeExecutorServices();
if (configuration.getJournalType() == JournalType.ASYNCIO && !AIOSequentialFileFactory.isSupported()) {
ActiveMQServerLogger.LOGGER.switchingNIO();
configuration.setJournalType(JournalType.NIO);
if (configuration.getJournalType() == JournalType.ASYNCIO) {
if (!AIOSequentialFileFactory.isSupported()) {
ActiveMQServerLogger.LOGGER.switchingNIO();
configuration.setJournalType(JournalType.NIO);
}
else if (!AIOSequentialFileFactory.isSupported(configuration.getJournalLocation())) {
ActiveMQServerLogger.LOGGER.switchingNIOonPath(configuration.getJournalLocation().getAbsolutePath());
configuration.setJournalType(JournalType.NIO);
}
}
managementService = new ManagementServiceImpl(mbeanServer, configuration);