[jboss-cvs] JBoss Messaging SVN: r4733 - in trunk: tests/src/org/jboss/messaging/tests/unit/core/journal/impl and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 25 16:34:05 EDT 2008


Author: clebert.suconic at jboss.com
Date: 2008-07-25 16:34:05 -0400 (Fri, 25 Jul 2008)
New Revision: 4733

Modified:
   trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java
Log:
JournalWork: Dealing with loading files from a different alignment (NIOFiles<->AIOFiles)

Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java	2008-07-25 18:02:08 UTC (rev 4732)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java	2008-07-25 20:34:05 UTC (rev 4733)
@@ -210,6 +210,10 @@
       {
          throw new IllegalArgumentException("File size cannot be less than " + MIN_FILE_SIZE + " bytes");
       }
+      if (fileSize % fileFactory.getAlignment() != 0)
+      {
+         throw new IllegalArgumentException("Invalid journal-file-size " + fileSize + ", It should be multiple of " + fileFactory.getAlignment());
+      }
       if (minFiles < 2)
       {
          throw new IllegalArgumentException("minFiles cannot be less than 2");
@@ -693,9 +697,9 @@
             throw new IllegalStateException("File is wrong size " + bytesRead +
                   " expected " + fileSize + " : " + file.getFile().getFileName());
          }
-         
+
          //First long is the ordering timestamp, we just jump its position
-         bb.position(file.getFile().calculateBlockStart(SIZE_HEADER));
+         bb.position(SIZE_HEADER);
          
          boolean hasData = false;
          
@@ -1029,12 +1033,7 @@
                throw new IllegalStateException("Internal error on loading file. Position doesn't match with checkSize");
             }
             
-            bb.position(file.getFile().calculateBlockStart(bb.position()));
-            
-            if (recordType != FILL_CHARACTER)
-            {
-               lastDataPos = bb.position();
-            }
+            lastDataPos = bb.position();
          }
          
          file.getFile().close();          
@@ -1084,7 +1083,7 @@
       {     
          currentFile.getFile().open();
          
-         currentFile.getFile().position(lastDataPos);
+         currentFile.getFile().position(currentFile.getFile().calculateBlockStart(lastDataPos));
          
          currentFile.setOffset(lastDataPos);
       }

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java	2008-07-25 18:02:08 UTC (rev 4732)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java	2008-07-25 20:34:05 UTC (rev 4733)
@@ -128,6 +128,24 @@
       }
    }
    
+   public void testInconsistentAlignment() throws Exception
+   {
+      factory = new FakeSequentialFileFactory(512, true);
+
+      try
+      {
+         journalImpl = new JournalImpl(2000, 2,
+            true, true,
+            factory, 
+            "tt", "tt", 1000);
+         fail ("Supposed to throw an exception");
+      }
+      catch (Exception ignored)
+      {
+      }
+
+   }
+      
    public void testSimpleAdd() throws Exception
    {
       final int JOURNAL_SIZE = 1060;
@@ -925,6 +943,8 @@
       
       journalImpl.checkAndReclaimFiles();
       
+      assertEquals(0, journalImpl.getDataFilesCount());
+      
       setupJournal(JOURNAL_SIZE, 1);
       
       assertEquals(0, journalImpl.getDataFilesCount());
@@ -933,7 +953,53 @@
       
    }
    
+   // It should be ok to write records on AIO, and later read then on NIO
+   public void testDecreaseAlignment() throws Exception
+   {
+      final int JOURNAL_SIZE = 512 * 4;
+      
+      setupJournal(JOURNAL_SIZE, 512);
+      
+      for (int i = 0; i < 10; i++)
+      {
+         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)0) );
+      }
+      
+      journalImpl.appendCommitRecord(1l);
+      
+      setupJournal(JOURNAL_SIZE, 100);
+      
+      assertEquals(10, records.size());
+      
+      setupJournal(JOURNAL_SIZE, 1);
+      
+      assertEquals(10, records.size());
+   }
    
+   // It should be ok to write records on NIO, and later read then on AIO
+   public void testIncreaseAlignment() throws Exception
+   {
+      final int JOURNAL_SIZE = 512 * 4;
+      
+      setupJournal(JOURNAL_SIZE, 1);
+      
+      for (int i = 0; i < 10; i++)
+      {
+         journalImpl.appendAddRecordTransactional(1l, i, (byte)0, new SimpleEncoding(1, (byte)0) );
+      }
+      
+      journalImpl.appendCommitRecord(1l);
+      
+      setupJournal(JOURNAL_SIZE, 100);
+      
+      assertEquals(10, records.size());
+      
+      setupJournal(JOURNAL_SIZE, 512);
+      
+      assertEquals(10, records.size());
+   }
+   
+   
    // Package protected ---------------------------------------------
    
    // Protected -----------------------------------------------------




More information about the jboss-cvs-commits mailing list