Permalink
Browse files

A few tweaks on persistence

  • Loading branch information...
1 parent ebfc512 commit a8aaee4ac6aecff0c30aab502ee9813bd37a6715 @clebertsuconic clebertsuconic committed Dec 5, 2009
View
4 src/main/org/hornetq/core/journal/SequentialFile.java
@@ -36,13 +36,13 @@
boolean isOpen();
boolean exists();
-
+
/**
* The maximum number of simultaneous writes accepted
* @param maxIO
* @throws Exception
*/
- void open(int maxIO) throws Exception;
+ void open(int maxIO, boolean useExecutor) throws Exception;
boolean fits(int size);
View
6 src/main/org/hornetq/core/journal/impl/AIOSequentialFile.java
@@ -178,14 +178,14 @@ else if (size % (10 * 1024) == 0)
public void open() throws Exception
{
- open(maxIO);
+ open(maxIO, true);
}
- public synchronized void open(final int maxIO) throws Exception
+ public synchronized void open(final int maxIO, final boolean useExecutor) throws Exception
{
opened = true;
- aioFile = new AsynchronousFileImpl(writerExecutor, pollerExecutor);
+ aioFile = new AsynchronousFileImpl(useExecutor ? writerExecutor : null, pollerExecutor);
aioFile.open(getFile().getAbsolutePath(), maxIO);
View
4 src/main/org/hornetq/core/journal/impl/AbstractJournalUpdateTask.java
@@ -98,7 +98,7 @@ public static SequentialFile writeControlFile(final SequentialFileFactory fileFa
try
{
- controlFile.open(1);
+ controlFile.open(1, false);
HornetQBuffer renameBuffer = HornetQBuffers.dynamicBuffer(1);
@@ -219,7 +219,7 @@ protected void openFile() throws Exception
currentFile = journal.getFile(false, false, false, true);
sequentialFile = currentFile.getFile();
- sequentialFile.open(1);
+ sequentialFile.open(1, false);
fileID = nextOrderingID++;
currentFile = new JournalFileImpl(sequentialFile, fileID);
View
10 src/main/org/hornetq/core/journal/impl/JournalImpl.java
@@ -369,7 +369,7 @@ public static int readJournalFile(final SequentialFileFactory fileFactory,
final JournalFile file,
final JournalReaderCallback reader) throws Exception
{
- file.getFile().open(1);
+ file.getFile().open(1, false);
ByteBuffer wholeFileBuffer = null;
try
{
@@ -2616,7 +2616,7 @@ private JournalFile reinitializeFile(final JournalFile file) throws Exception
SequentialFile sf = file.getFile();
- sf.open(1);
+ sf.open(1, false);
sf.position(0);
@@ -2725,7 +2725,7 @@ private static int getRecordSize(final byte recordType)
{
SequentialFile file = fileFactory.createSequentialFile(fileName, maxAIO);
- file.open(1);
+ file.open(1, false);
ByteBuffer bb = fileFactory.newBuffer(SIZE_HEADER);
@@ -2912,7 +2912,7 @@ private JournalFile createFile(final boolean keepOpened,
}
else
{
- sequentialFile.open(1);
+ sequentialFile.open(1, false);
}
if (fill)
@@ -2946,7 +2946,7 @@ private void openFile(final JournalFile file, final boolean multiAIO) throws Exc
}
else
{
- file.getFile().open(1);
+ file.getFile().open(1, false);
}
file.getFile().position(file.getFile().calculateBlockStart(SIZE_HEADER));
View
8 src/main/org/hornetq/core/journal/impl/NIOSequentialFile.java
@@ -89,18 +89,18 @@ public synchronized boolean isOpen()
* Some operations while initializing files on the journal may require a different maxIO */
public synchronized void open() throws Exception
{
- open(defaultMaxIO);
+ open(defaultMaxIO, true);
}
- public void open(final int maxIO) throws Exception
+ public void open(final int maxIO, final boolean useExecutor) throws Exception
{
rfile = new RandomAccessFile(getFile(), "rw");
channel = rfile.getChannel();
fileSize = channel.size();
- if (writerExecutor != null)
+ if (writerExecutor != null && useExecutor)
{
maxIOSemaphore = new Semaphore(maxIO);
this.maxIO = maxIO;
@@ -286,7 +286,7 @@ private void internalWrite(final ByteBuffer bytes, final boolean sync, final IOA
return;
}
- if (writerExecutor == null)
+ if (maxIOSemaphore == null)
{
doInternalWrite(bytes, sync, callback);
}
View
63 tests/src/org/hornetq/tests/integration/journal/NIOBufferedJournalCompactTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.tests.integration.journal;
+
+import java.io.File;
+
+import org.hornetq.core.config.impl.ConfigurationImpl;
+import org.hornetq.core.journal.SequentialFileFactory;
+import org.hornetq.core.journal.impl.AIOSequentialFileFactory;
+import org.hornetq.core.journal.impl.NIOSequentialFileFactory;
+
+/**
+ * A NIOBufferedJournalCompactTest
+ *
+ * @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public class NIOBufferedJournalCompactTest extends NIOJournalCompactTest
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+ @Override
+ protected SequentialFileFactory getFileFactory() throws Exception
+ {
+ File file = new File(getTestDir());
+
+ deleteDirectory(file);
+
+ file.mkdir();
+
+ return new NIOSequentialFileFactory(getTestDir(), true);
+ }
+
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
View
4 tests/src/org/hornetq/tests/integration/journal/NIOJournalCompactTest.java
@@ -507,7 +507,7 @@ public void run()
public void testSimpleCompacting() throws Exception
{
- setup(2, 60 * 1024, true);
+ setup(2, 60 * 1024, false);
createJournal();
startJournal();
@@ -756,7 +756,7 @@ public void testLiveSizeTransactional() throws Exception
protected void setUp() throws Exception
{
super.setUp();
-
+
File file = new File(getTestDir());
deleteDirectory(file);
View
4 tests/src/org/hornetq/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
@@ -363,10 +363,10 @@ public String getFileName()
public void open() throws Exception
{
- open(0);
+ open(1, true);
}
- public synchronized void open(final int currentMaxIO) throws Exception
+ public synchronized void open(final int currentMaxIO, final boolean useExecutor) throws Exception
{
open = true;
checkAndResize(0);

0 comments on commit a8aaee4

Please sign in to comment.