This closes #23 Fix for truncated files during crashes
This commit is contained in:
commit
0e8eff7ef8
|
@ -375,11 +375,12 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
|
|||
{
|
||||
SequentialFile file = fileFactory.createSequentialFile(fileName, filesRepository.getMaxAIO());
|
||||
|
||||
if (file.size() >= SIZE_HEADER)
|
||||
{
|
||||
file.open(1, false);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
JournalFileImpl jrnFile = readFileHeader(file);
|
||||
|
||||
orderedFiles.add(jrnFile);
|
||||
|
@ -389,6 +390,12 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
|
|||
file.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ActiveMQJournalLogger.LOGGER.ignoringShortFile(fileName);
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
// Now order them by ordering id - we can't use the file name for ordering
|
||||
// since we can re-use dataFiles
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue