Author: clebert.suconic(a)jboss.com
Date: 2009-12-06 11:30:57 -0500 (Sun, 06 Dec 2009)
New Revision: 8595
Modified:
trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java
trunk/tests/src/org/hornetq/tests/integration/journal/ValidateTransactionHealthTest.java
Log:
HORNETQ-237 - Fix for tmp files on the journal
Modified: trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2009-12-06 14:16:57 UTC
(rev 8594)
+++ trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2009-12-06 16:30:57 UTC
(rev 8595)
@@ -2904,16 +2904,11 @@
trace("Creating file " + fileName);
}
- SequentialFile sequentialFile = fileFactory.createSequentialFile(fileName,
maxAIO);
+ String tmpFileName = fileName + ".tmp";
+
+ SequentialFile sequentialFile = fileFactory.createSequentialFile(tmpFileName,
maxAIO);
- if (multiAIO)
- {
- sequentialFile.open();
- }
- else
- {
- sequentialFile.open(1, false);
- }
+ sequentialFile.open(1, false);
if (fill)
{
@@ -2928,14 +2923,25 @@
sequentialFile.writeDirect(bb, true);
}
- JournalFile info = new JournalFileImpl(sequentialFile, fileID);
- if (!keepOpened)
+ sequentialFile.close();
+
+ sequentialFile.renameTo(fileName);
+
+ if (keepOpened)
{
- sequentialFile.close();
+
+ if (multiAIO)
+ {
+ sequentialFile.open();
+ }
+ else
+ {
+ sequentialFile.open(1, false);
+ }
}
- return info;
+ return new JournalFileImpl(sequentialFile, fileID);
}
private void openFile(final JournalFile file, final boolean multiAIO) throws
Exception
@@ -3233,8 +3239,20 @@
controlFile.delete();
}
- List<String> leftFiles = fileFactory.listFiles(getFileExtension() +
".cmp");
+ cleanupTmpFiles(".cmp");
+ cleanupTmpFiles(".tmp");
+
+ return;
+ }
+
+ /**
+ * @throws Exception
+ */
+ private void cleanupTmpFiles(final String extension) throws Exception
+ {
+ List<String> leftFiles = fileFactory.listFiles(getFileExtension() +
extension);
+
if (leftFiles.size() > 0)
{
log.warn("Compacted files were left unnatended on journal directory,
deleting invalid files now");
@@ -3246,8 +3264,6 @@
file.delete();
}
}
-
- return;
}
private static boolean isInvalidSize(final int fileSize, final int bufferPos, final
int size)
Modified:
trunk/tests/src/org/hornetq/tests/integration/journal/ValidateTransactionHealthTest.java
===================================================================
---
trunk/tests/src/org/hornetq/tests/integration/journal/ValidateTransactionHealthTest.java 2009-12-06
14:16:57 UTC (rev 8594)
+++
trunk/tests/src/org/hornetq/tests/integration/journal/ValidateTransactionHealthTest.java 2009-12-06
16:30:57 UTC (rev 8595)
@@ -301,9 +301,6 @@
try
{
Journal journal = appendData(journalType, journalDir, numberOfElements,
transactionSize, numberOfThreads);
-
- journal.stop();
-
}
catch (Exception e)
{
@@ -313,7 +310,7 @@
System.exit(OK);
}
-
+
public static JournalImpl appendData(String journalType,
String journalDir,
long numberOfElements,
Show replies by date