Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARTEMIS-135 - Fix on journal load #23

Merged
merged 1 commit into from
Jun 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -375,18 +375,25 @@ public List<JournalFile> orderFiles() throws Exception
{
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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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;
Expand Down Expand Up @@ -3222,6 +3223,26 @@ public void testAddTexThenUpdate() throws Exception

}

@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();

}