From fbe27682a14ef5a30ec5ee5f925fca0f3842471e Mon Sep 17 00:00:00 2001 From: Andy Taylor Date: Mon, 19 Jun 2017 12:04:21 +0100 Subject: [PATCH] ARTEMIS-1237 - Hard coded timeout on Journal file open Make timeout configurable https://issues.apache.org/jira/browse/ARTEMIS-1237 --- .../config/ActiveMQDefaultConfiguration.java | 7 ++++ .../journal/impl/JournalFilesRepository.java | 10 ++++-- .../core/journal/impl/JournalImpl.java | 33 +++++++++++++++++-- .../artemis/core/config/Configuration.java | 10 ++++++ .../core/config/impl/ConfigurationImpl.java | 13 ++++++++ .../impl/FileConfigurationParser.java | 2 ++ .../impl/journal/JournalStorageManager.java | 2 +- .../schema/artemis-configuration.xsd | 14 ++++++-- .../config/impl/FileConfigurationTest.java | 1 + .../ConfigurationTest-full-config.xml | 1 + 10 files changed, 84 insertions(+), 9 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/config/ActiveMQDefaultConfiguration.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/config/ActiveMQDefaultConfiguration.java index 7ace35c944..2ff6a0a4e6 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/config/ActiveMQDefaultConfiguration.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/config/ActiveMQDefaultConfiguration.java @@ -261,6 +261,9 @@ public final class ActiveMQDefaultConfiguration { // The percentage of live data on which we consider compacting the journal private static int DEFAULT_JOURNAL_COMPACT_PERCENTAGE = 30; + // The time to wait when opening a new journal file before failing + private static int DEFAULT_JOURNAL_FILE_OPEN_TIMEOUT = 5; + // The minimal number of data files before we can start compacting private static int DEFAULT_JOURNAL_COMPACT_MIN_FILES = 10; @@ -796,6 +799,10 @@ public final class ActiveMQDefaultConfiguration { return DEFAULT_JOURNAL_COMPACT_PERCENTAGE; } + public static int getDefaultJournalFileOpenTimeout() { + return DEFAULT_JOURNAL_FILE_OPEN_TIMEOUT; + } + /** * The minimal number of data files before we can start compacting */ diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java index c0a278dbb1..488aa1f91d 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java @@ -81,6 +81,8 @@ public class JournalFilesRepository { private final AtomicInteger freeFilesCount = new AtomicInteger(0); + private final int journalFileOpenTimeout; + private Executor openFilesExecutor; private final Runnable pushOpenRunnable = new Runnable() { @@ -103,7 +105,8 @@ public class JournalFilesRepository { final int maxAIO, final int fileSize, final int minFiles, - final int poolSize) { + final int poolSize, + final int journalFileOpenTimeout) { if (filePrefix == null) { throw new IllegalArgumentException("filePrefix cannot be null"); } @@ -122,6 +125,7 @@ public class JournalFilesRepository { this.poolSize = poolSize; this.userVersion = userVersion; this.journal = journal; + this.journalFileOpenTimeout = journalFileOpenTimeout; } // Public -------------------------------------------------------- @@ -421,7 +425,7 @@ public class JournalFilesRepository { pushOpen(); - nextFile = openedFiles.poll(5, TimeUnit.SECONDS); + nextFile = openedFiles.poll(journalFileOpenTimeout, TimeUnit.SECONDS); } if (openedFiles.isEmpty()) { @@ -431,7 +435,7 @@ public class JournalFilesRepository { if (nextFile == null) { - logger.debug("Could not get a file in 5 seconds, it will retry directly, without an executor"); + logger.debug("Could not get a file in " + journalFileOpenTimeout + " seconds, it will retry directly, without an executor"); try { nextFile = takeFile(true, true, true, false); } catch (Exception e) { diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java index 7e8320c71b..513ed030f8 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java @@ -234,7 +234,21 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal final String fileExtension, final int maxAIO, final int userVersion) { - this(null, fileSize, minFiles, poolSize, compactMinFiles, compactPercentage, fileFactory, filePrefix, fileExtension, maxAIO, userVersion); + this(null, fileSize, minFiles, poolSize, compactMinFiles, compactPercentage, 5, fileFactory, filePrefix, fileExtension, maxAIO, userVersion); + } + + public JournalImpl(final int fileSize, + final int minFiles, + final int poolSize, + final int compactMinFiles, + final int compactPercentage, + final int journalFileOpenTimeout, + final SequentialFileFactory fileFactory, + final String filePrefix, + final String fileExtension, + final int maxAIO, + final int userVersion) { + this(null, fileSize, minFiles, poolSize, compactMinFiles, compactPercentage, journalFileOpenTimeout, fileFactory, filePrefix, fileExtension, maxAIO, userVersion); } public JournalImpl(final ExecutorFactory ioExecutors, @@ -248,6 +262,21 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal final String fileExtension, final int maxAIO, final int userVersion) { + this(ioExecutors, fileSize, minFiles, poolSize, compactMinFiles, compactPercentage, 5, fileFactory, filePrefix, fileExtension, maxAIO, userVersion); + } + + public JournalImpl(final ExecutorFactory ioExecutors, + final int fileSize, + final int minFiles, + final int poolSize, + final int compactMinFiles, + final int compactPercentage, + final int journalFileOpenTimeout, + final SequentialFileFactory fileFactory, + final String filePrefix, + final String fileExtension, + final int maxAIO, + final int userVersion) { super(fileFactory.isSupportsCallbacks(), fileSize); @@ -275,7 +304,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal this.fileFactory = fileFactory; - filesRepository = new JournalFilesRepository(fileFactory, this, filePrefix, fileExtension, userVersion, maxAIO, fileSize, minFiles, poolSize); + filesRepository = new JournalFilesRepository(fileFactory, this, filePrefix, fileExtension, userVersion, maxAIO, fileSize, minFiles, poolSize, journalFileOpenTimeout); this.userVersion = userVersion; } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java index 9d5d4a8d4a..699744317d 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java @@ -645,6 +645,16 @@ public interface Configuration { */ int getJournalCompactPercentage(); + /** + * @return How long to wait when opening a new Journal file before failing + */ + int getJournalFileOpenTimeout(); + + /** + * Sets the journal file open timeout + */ + Configuration setJournalFileOpenTimeout(int journalFileOpenTimeout); + /** * Sets the percentage of live data before compacting the journal. */ diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java index fb678b6546..f0a6067aff 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java @@ -173,6 +173,8 @@ public class ConfigurationImpl implements Configuration, Serializable { protected int journalCompactPercentage = ActiveMQDefaultConfiguration.getDefaultJournalCompactPercentage(); + protected int journalFileOpenTimeout = ActiveMQDefaultConfiguration.getDefaultJournalFileOpenTimeout(); + protected int journalFileSize = ActiveMQDefaultConfiguration.getDefaultJournalFileSize(); protected int journalPoolFiles = ActiveMQDefaultConfiguration.getDefaultJournalPoolFiles(); @@ -1145,6 +1147,17 @@ public class ConfigurationImpl implements Configuration, Serializable { return this; } + @Override + public int getJournalFileOpenTimeout() { + return journalFileOpenTimeout; + } + + @Override + public Configuration setJournalFileOpenTimeout(int journalFileOpenTimeout) { + this.journalFileOpenTimeout = journalFileOpenTimeout; + return this; + } + @Override public ConfigurationImpl setJournalCompactPercentage(final int percentage) { journalCompactPercentage = percentage; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java index a3d59f6fc0..e06397da3c 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java @@ -561,6 +561,8 @@ public final class FileConfigurationParser extends XMLConfigurationUtil { config.setJournalMaxIO_NIO(journalMaxIO); } + config.setJournalFileOpenTimeout(getInteger(e, "journal-file-open-timeout", ActiveMQDefaultConfiguration.getDefaultJournalFileOpenTimeout(), Validators.GT_ZERO)); + config.setJournalMinFiles(getInteger(e, "journal-min-files", config.getJournalMinFiles(), Validators.GT_ZERO)); config.setJournalPoolFiles(getInteger(e, "journal-pool-files", config.getJournalPoolFiles(), Validators.MINUS_ONE_OR_GT_ZERO)); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java index 27fdc6f503..803c441405 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java @@ -120,7 +120,7 @@ public class JournalStorageManager extends AbstractJournalStorageManager { bindingsFF = new NIOSequentialFileFactory(config.getBindingsLocation(), criticalErrorListener, config.getJournalMaxIO_NIO()); bindingsFF.setDatasync(config.isJournalDatasync()); - Journal localBindings = new JournalImpl(ioExecutors, 1024 * 1024, 2, config.getJournalCompactMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactPercentage(), bindingsFF, "activemq-bindings", "bindings", 1, 0); + Journal localBindings = new JournalImpl(ioExecutors, 1024 * 1024, 2, config.getJournalCompactMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactPercentage(), config.getJournalFileOpenTimeout(), bindingsFF, "activemq-bindings", "bindings", 1, 0); bindingsJournal = localBindings; originalBindingsJournal = localBindings; diff --git a/artemis-server/src/main/resources/schema/artemis-configuration.xsd b/artemis-server/src/main/resources/schema/artemis-configuration.xsd index 6af18bd233..9021b70d38 100644 --- a/artemis-server/src/main/resources/schema/artemis-configuration.xsd +++ b/artemis-server/src/main/resources/schema/artemis-configuration.xsd @@ -692,6 +692,14 @@ + + + + the length of time to wait when opening a new Journal file before timing out and failing + + + + @@ -764,7 +772,7 @@ a list of security settings - + @@ -862,7 +870,7 @@ - + @@ -886,7 +894,7 @@ - + diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java index 28ad83e556..1d1f53b1f2 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java @@ -101,6 +101,7 @@ public class FileConfigurationTest extends ConfigurationImplTest { Assert.assertEquals(10000, conf.getJournalBufferSize_NIO()); Assert.assertEquals(1000, conf.getJournalBufferTimeout_NIO()); Assert.assertEquals(56546, conf.getJournalMaxIO_NIO()); + Assert.assertEquals(9876, conf.getJournalFileOpenTimeout()); Assert.assertEquals(false, conf.isJournalSyncTransactional()); Assert.assertEquals(true, conf.isJournalSyncNonTransactional()); diff --git a/artemis-server/src/test/resources/ConfigurationTest-full-config.xml b/artemis-server/src/test/resources/ConfigurationTest-full-config.xml index ca10eb99c8..65264547c5 100644 --- a/artemis-server/src/test/resources/ConfigurationTest-full-config.xml +++ b/artemis-server/src/test/resources/ConfigurationTest-full-config.xml @@ -232,6 +232,7 @@ 33 123 56546 + 9876 5000 95 54321