Skip to content

Commit

Permalink
[HORNETQ-1479] JournalImpl.load() fails if there are truncated files
Browse files Browse the repository at this point in the history
BZ-1229434

(cherry picked from commit c95eea5)

Squashed with:

HORNETQ-1479 / BZ-1229434 - JournalImpl.load() fails if there are truncated files

- truncated files are deleted to avoid potential problems

(cherry picked from commit 87b8a4c)
  • Loading branch information
TomasHofman authored and clebertsuconic committed Jun 11, 2015
1 parent cc25524 commit 1cc1511
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
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();
HornetQJournalLogger.LOGGER.deletingTooShortFile(fileName);
file.delete();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,8 @@ public interface HornetQJournalLogger 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 = "Deleting journal file {0}: file is shorter then minimum header size.", format = Message.Format.MESSAGE_FORMAT)
void deletingTooShortFile(String fileName);

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

package org.hornetq.tests.unit.core.journal.impl;

import java.io.File;
import java.nio.ByteBuffer;
import java.util.List;

Expand Down Expand Up @@ -3225,6 +3226,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();

}

0 comments on commit 1cc1511

Please sign in to comment.