[jboss-cvs] JBoss Messaging SVN: r7529 - in trunk: tests/src/org/jboss/messaging/tests/integration/client and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 7 01:00:09 EDT 2009


Author: clebert.suconic at jboss.com
Date: 2009-07-07 01:00:09 -0400 (Tue, 07 Jul 2009)
New Revision: 7529

Modified:
   trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
   trunk/tests/src/org/jboss/messaging/tests/integration/client/CompactingTest.java
Log:
Fixing race condition on shut down during compacting and fixing test

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java	2009-07-06 23:33:05 UTC (rev 7528)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java	2009-07-07 05:00:09 UTC (rev 7529)
@@ -1378,8 +1378,9 @@
     * 
     *  Note: This method can't be called from the main executor, as it will invoke other methods depending on it.
     */
-   public void compact() throws Exception
+   public synchronized void compact() throws Exception
    {
+
       if (compactor != null)
       {
          throw new IllegalStateException("There is pending compacting operation");
@@ -1397,6 +1398,11 @@
          compactingLock.writeLock().lock();
          try
          {
+            if (state != STATE_LOADED)
+            {
+               return;
+            }
+
             autoReclaim = false;
 
             // We need to move to the next file, as we need a clear start for negatives and positives counts
@@ -2264,11 +2270,6 @@
 
       try
       {
-         while (!compactorWait.waitCompletion(60000))
-         {
-            log.warn("Waiting the compactor to finish its operations");
-         }
-
          filesExecutor.shutdown();
 
          if (!filesExecutor.awaitTermination(60, TimeUnit.SECONDS))
@@ -2352,7 +2353,7 @@
     * @param file
     * @throws Exception
     */
-   private void addFreeFile(JournalFile file) throws Exception
+   private void addFreeFile(final JournalFile file) throws Exception
    {
       // FIXME - size() involves a scan!!!
       if (freeFiles.size() + dataFiles.size() + 1 + openedFiles.size() < minFiles)
@@ -2365,8 +2366,6 @@
       }
       else
       {
-         file.getFile().open(1);
-
          file.getFile().delete();
       }
    }
@@ -2699,7 +2698,7 @@
    }
 
    // You need to guarantee lock.acquire() before calling this method
-   private void moveNextFile(boolean synchronous) throws InterruptedException
+   private void moveNextFile(final boolean synchronous) throws InterruptedException
    {
       closeFile(currentFile, synchronous);
 
@@ -2707,7 +2706,7 @@
 
       if (trace)
       {
-         trace("moveNextFile: " + currentFile.getFile().getFileName());
+         trace("moveNextFile: " + currentFile.getFile().getFileName() + " sync: " + synchronous);
       }
 
       fileFactory.activate(currentFile.getFile());
@@ -2718,7 +2717,7 @@
     * <p>In case there are no cached opened files, this method will block until the file was opened,
     * what would happen only if the system is under heavy load by another system (like a backup system, or a DB sharing the same box as JBM).</p> 
     * */
-   private JournalFile enqueueOpenFile(boolean synchronous) throws InterruptedException
+   private JournalFile enqueueOpenFile(final boolean synchronous) throws InterruptedException
    {
       if (trace)
       {
@@ -2835,7 +2834,7 @@
       return nextOpenedFile;
    }
 
-   private void closeFile(final JournalFile file, boolean synchronous)
+   private void closeFile(final JournalFile file, final boolean synchronous)
    {
       fileFactory.deactivate(file.getFile());
       pendingCloseFiles.add(file);

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/CompactingTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/CompactingTest.java	2009-07-06 23:33:05 UTC (rev 7528)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/CompactingTest.java	2009-07-07 05:00:09 UTC (rev 7529)
@@ -22,6 +22,7 @@
 
 package org.jboss.messaging.tests.integration.client;
 
+import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -34,6 +35,8 @@
 import org.jboss.messaging.core.config.Configuration;
 import org.jboss.messaging.core.config.impl.ConfigurationImpl;
 import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.journal.SequentialFile;
+import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
 import org.jboss.messaging.core.server.JournalType;
 import org.jboss.messaging.core.server.MessagingServer;
 import org.jboss.messaging.tests.util.ServiceTestBase;
@@ -70,14 +73,14 @@
 
    // Public --------------------------------------------------------
 
-   public void testMultiProducerAndCompactNIO() throws Throwable
+   public void testMultiProducerAndCompactAIO() throws Throwable
    {
-      internalTestMultiProducer(JournalType.NIO);
+      internalTestMultiProducer(JournalType.ASYNCIO);
    }
 
-   public void testMultiProducerAndCompactAIO() throws Throwable
+   public void testMultiProducerAndCompactNIO() throws Throwable
    {
-      internalTestMultiProducer(JournalType.ASYNCIO);
+      internalTestMultiProducer(JournalType.NIO);
    }
 
    public void internalTestMultiProducer(JournalType journalType) throws Throwable
@@ -227,6 +230,22 @@
 
       server.stop();
 
+      // NIOSequentialFileFactory factory = new NIOSequentialFileFactory(getJournalDir());
+      //      
+      // List<String> files = factory.listFiles("jbm");
+      //      
+      // for (String str: files)
+      // {
+      // System.out.println("Files " + str);
+      // SequentialFile file = factory.createSequentialFile(str, 1);
+      // for (int i = 0 ; i < 10 && file.size() == 0; i ++)
+      // {
+      // System.out.println("File size is ZERO = " + file.size());
+      // Thread.sleep(1000);
+      // }
+      // assertTrue(file.getFileName() + " size = " + file.size(), file.size() > 0);
+      // }
+
       setupServer(journalType);
 
       ClientSession sess = sf.createSession(true, true);
@@ -273,8 +292,8 @@
 
       config.setJournalType(journalType);
 
-      config.setJournalCompactMinFiles(ConfigurationImpl.DEFAULT_JOURNAL_COMPACT_MIN_FILES);
-      config.setJournalCompactPercentage(ConfigurationImpl.DEFAULT_JOURNAL_COMPACT_PERCENTAGE);
+      config.setJournalCompactMinFiles(3);
+      config.setJournalCompactPercentage(50);
 
       server = createServer(true, config);
 




More information about the jboss-cvs-commits mailing list