Repository: activemq-artemis Updated Branches: refs/heads/master 6738e81f4 -> 0e8eff7ef
ARTEMIS-135 - Fix on journal load https://issues.apache.org/jira/browse/ARTEMIS-135 This is importing a recent fix from the journal on the old version. If a crash happened between the create file and the fill of the file the file wouldn't be loaded and the server wouldn't start until you removed the offending file Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/72354ee3 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/72354ee3 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/72354ee3 Branch: refs/heads/master Commit: 72354ee38fab9073ab4750ccd2281ba75bd2ffba Parents: 6738e81 Author: Tomas Hofman <[email protected]> Authored: Wed Jun 10 20:27:55 2015 -0400 Committer: Clebert Suconic <[email protected]> Committed: Wed Jun 10 20:29:45 2015 -0400 ---------------------------------------------------------------------- .../artemis/core/journal/impl/JournalImpl.java | 21 +++++++++++++------- .../artemis/journal/ActiveMQJournalLogger.java | 4 ++++ .../core/journal/impl/JournalImplTestUnit.java | 21 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/72354ee3/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java ---------------------------------------------------------------------- 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 8f74327..f394202 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 @@ -375,18 +375,25 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal { SequentialFile file = fileFactory.createSequentialFile(fileName, filesRepository.getMaxAIO()); - file.open(1, false); - - try + if (file.size() >= SIZE_HEADER) { + file.open(1, false); - JournalFileImpl jrnFile = readFileHeader(file); + try + { + JournalFileImpl jrnFile = readFileHeader(file); - orderedFiles.add(jrnFile); + orderedFiles.add(jrnFile); + } + finally + { + file.close(); + } } - finally + else { - file.close(); + ActiveMQJournalLogger.LOGGER.ignoringShortFile(fileName); + file.delete(); } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/72354ee3/artemis-journal/src/main/java/org/apache/activemq/artemis/journal/ActiveMQJournalLogger.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/journal/ActiveMQJournalLogger.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/journal/ActiveMQJournalLogger.java index 73f8e85..4d2429d 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/journal/ActiveMQJournalLogger.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/journal/ActiveMQJournalLogger.java @@ -269,4 +269,8 @@ public interface ActiveMQJournalLogger extends BasicLogger @Message(id = 144006, value = "IOError code {0}, {1}", format = Message.Format.MESSAGE_FORMAT) void ioError(final int errorCode, final String errorMessage); + @LogMessage(level = Logger.Level.WARN) + @Message(id = 144007, value = "Ignoring journal file {0}: file is shorter then minimum header size. This file is being removed.", format = Message.Format.MESSAGE_FORMAT) + void ignoringShortFile(String fileName); + } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/72354ee3/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java ---------------------------------------------------------------------- diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java index 6ed956d..ab86abc 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java @@ -18,6 +18,7 @@ package org.apache.activemq.artemis.tests.unit.core.journal.impl; import java.nio.ByteBuffer; import java.util.List; +import java.io.File; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.ActiveMQIOErrorException; @@ -3222,6 +3223,26 @@ public abstract class JournalImplTestUnit extends JournalImplTestBase } + @Test + public void testLoadTruncatedFile() throws Exception + { + setup(2, 2 * 1024, true); + createJournal(); + startJournal(); + + String testDir = getTestDir(); + new File(testDir + File.separator + filePrefix + "-1." + fileExtension).createNewFile(); + + try + { + load(); + } + catch (Exception e) + { + Assert.fail("Unexpected exception: " + e.toString()); + } + } + protected abstract int getAlignment(); }
