directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1595771 - in /directory/mavibot/trunk/mavibot/src: main/java/org/apache/directory/mavibot/btree/ test/java/org/apache/directory/mavibot/btree/
Date Mon, 19 May 2014 07:26:32 GMT
Author: elecharny
Date: Mon May 19 07:26:31 2014
New Revision: 1595771

URL: http://svn.apache.org/r1595771
Log:
o Use the newBtreHeaders Map only when processing an update, instead of using the current's
one. This allow all the modifications to be waiting for the encapsulating transaction to be
committed.
o Fixed the TxnLevel counter manipulation : we weren't correctly decrementing it when we got
some exception
o Close the recordManager in tests

Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeDuplicateKeyTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeTransactionTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerFreePageTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerWithDuplicatesTest.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java?rev=1595771&r1=1595770&r2=1595771&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
Mon May 19 07:26:31 2014
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.Atomi
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.directory.mavibot.btree.exception.BTreeCreationException;
+import org.apache.directory.mavibot.btree.exception.DuplicateValueNotAllowedException;
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
 import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
 
@@ -446,6 +447,17 @@ import org.apache.directory.mavibot.btre
             
             return null;
         }
+        catch ( DuplicateValueNotAllowedException e )
+        {
+            // We have had an exception, we must rollback the transaction
+            // if it's not a sub-btree
+            if ( btreeType != BTreeTypeEnum.PERSISTED_SUB )
+            {
+                transactionManager.rollback();
+            }
+
+            throw e;
+        }
     }
 
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java?rev=1595771&r1=1595770&r2=1595771&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
Mon May 19 07:26:31 2014
@@ -484,16 +484,36 @@ public class PersistedBTree<K, V> extend
     
     private BTreeHeader<K, V> getBTreeHeader( String name )
     {
+        switch ( btreeType )
+        {
+            case PERSISTED_SUB : 
+                return getBtreeHeader();
+                
+            case BTREE_OF_BTREES : 
+                return recordManager.getNewBTreeHeader( RecordManager.BTREE_OF_BTREES_NAME
);
+                    
+            case COPIED_PAGES_BTREE : 
+                return recordManager.getNewBTreeHeader( RecordManager.COPIED_PAGE_BTREE_NAME
);
+                
+            default : 
+                return recordManager.getBTreeHeader( getName() );
+        }
+    }
+
+    
+    private BTreeHeader<K, V> getNewBTreeHeader( String name )
+    {
         if ( btreeType == BTreeTypeEnum.PERSISTED_SUB )
         {
             return getBtreeHeader();
         }
         
-        BTreeHeader<K, V> btreeHeader = recordManager.getBTreeHeader( getName() );
+        BTreeHeader<K, V> btreeHeader = recordManager.getNewBTreeHeader( getName()
);
 
         return btreeHeader;
     }
 
+    
     /**
      * Insert the tuple into the B-tree rootPage, get back the new rootPage
      */
@@ -584,8 +604,6 @@ public class PersistedBTree<K, V> extend
                 // Sub-B-trees are only updating the CopiedPage B-tree
                 recordManager.addInCopiedPagesBtree( getName(), revision, result.getCopiedPages()
);
                 
-                //btreeRevisions.put( revision, newBtreeHeader );
-
                 // Store the new revision
                 storeRevision( newBtreeHeader, recordManager.isKeepRevisions() );
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java?rev=1595771&r1=1595770&r2=1595771&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
Mon May 19 07:26:31 2014
@@ -562,17 +562,7 @@ public class RecordManager extends Abstr
         transactionLock.lock();
         
         // Now, check the TLS state
-        Integer nbTxnLevel = context.get();
-        
-        if ( nbTxnLevel == null )
-        {
-            context.set( 1 );
-        }
-        else
-        {
-            // And increment the counter of inner txn.
-            context.set( nbTxnLevel + 1 );
-        }
+        incrementTxnLevel();
     }
 
 
@@ -585,6 +575,10 @@ public class RecordManager extends Abstr
         {
             // The file has been closed, nothing remains to commit, let's get out
             transactionLock.unlock();
+            
+            // Still we have to decrement the TransactionLevel
+            decrementTxnLevel();
+            
             return;
         }
 
@@ -628,7 +622,7 @@ public class RecordManager extends Abstr
                 updateRecordManagerHeader();
                 
                 // And decrement the number of started transactions
-                context.set( nbTxnStarted - 1 );
+                decrementTxnLevel();
 
                 // Finally, release the global lock
                 transactionLock.unlock();
@@ -641,7 +635,7 @@ public class RecordManager extends Abstr
                 updateRecordManagerHeader();
                 
                 // Swap the BtreeHeaders maps
-                swapCurrentBtreeHeaders();
+                //swapCurrentBtreeHeaders();
         
                 // We can now free pages
                 for ( PageIO pageIo : freedPages )
@@ -665,13 +659,59 @@ public class RecordManager extends Abstr
                 updateRecordManagerHeader();
                 
                 // And decrement the number of started transactions
-                context.set( nbTxnStarted - 1 );
+                decrementTxnLevel();
 
                 // Finally, release the global lock
                 transactionLock.unlock();
                 return;
         }
     }
+    
+    
+    public boolean isContextOk()
+    {
+        return ( context == null ? true : ( context.get() == 0 ) );
+    }
+    
+    /**
+     * Increment the transactionLevel
+     */
+    private void incrementTxnLevel()
+    {
+        Integer nbTxnLevel = context.get();
+        
+        if ( nbTxnLevel == null )
+        {
+            context.set( 1 );
+        }
+        else
+        {
+            // And increment the counter of inner txn.
+            context.set( nbTxnLevel + 1 );
+        }
+        
+        /*
+        System.out.println( "Incrementing : " + context.get() );
+        
+        if ( context.get() == 0 )
+        {
+            System.out.println( "-------------" );
+        }
+        */
+    }
+    
+    
+    /**
+     * Decrement the transactionLevel
+     */
+    private void decrementTxnLevel()
+    {
+        int nbTxnStarted = context.get();
+
+        context.set(  nbTxnStarted - 1 );
+        
+        //System.out.println( "Incrementing : " + context.get() );
+    }
 
 
     /**
@@ -1936,7 +1976,7 @@ public class RecordManager extends Abstr
         btreeOfBtrees.insert( nameRevision, btreeHeaderOffset );
 
         // Update the B-tree of B-trees offset
-        currentBtreeOfBtreesOffset = getBTreeHeader( BTREE_OF_BTREES_NAME ).getBTreeHeaderOffset();
+        currentBtreeOfBtreesOffset = getNewBTreeHeader( BTREE_OF_BTREES_NAME ).getBTreeHeaderOffset();
     }
 
 
@@ -3625,6 +3665,18 @@ public class RecordManager extends Abstr
     
     
     /**
+     * Get the new BTreeHeader for a given Btree. It might not exist
+     */
+    public BTreeHeader getNewBTreeHeader( String name )
+    {
+        // get the current BTree Header for this BTree and revision
+        BTreeHeader<?, ?> btreeHeader = newBTreeHeaders.get( name );
+
+        return btreeHeader;
+    }
+    
+    
+    /**
      * {@inheritDoc}
      */
     public void updateNewBTreeHeaders( BTreeHeader btreeHeader )

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java?rev=1595771&r1=1595770&r2=1595771&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
(original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
Mon May 19 07:26:31 2014
@@ -95,6 +95,9 @@ public class PersistedBTreeBrowseTest
         {
             FileUtils.deleteDirectory( dataDir );
         }
+        
+        recordManager1.close();
+        assertTrue( recordManager1.isContextOk() );
     }
 
 

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeDuplicateKeyTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeDuplicateKeyTest.java?rev=1595771&r1=1595770&r2=1595771&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeDuplicateKeyTest.java
(original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeDuplicateKeyTest.java
Mon May 19 07:26:31 2014
@@ -94,6 +94,9 @@ public class PersistedBTreeDuplicateKeyT
         {
             FileUtils.deleteDirectory( dataDir );
         }
+        
+        recordManager1.close();
+        assertTrue( recordManager1.isContextOk() );
     }
 
 

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeTransactionTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeTransactionTest.java?rev=1595771&r1=1595770&r2=1595771&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeTransactionTest.java
(original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeTransactionTest.java
Mon May 19 07:26:31 2014
@@ -19,12 +19,16 @@
  */
 package org.apache.directory.mavibot.btree;
 
+import static org.junit.Assert.assertTrue;
+
 import java.io.File;
 import java.io.IOException;
 import java.util.UUID;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.directory.mavibot.btree.serializer.LongSerializer;
 import org.apache.directory.mavibot.btree.serializer.StringSerializer;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Rule;
@@ -69,6 +73,30 @@ public class PersistedBTreeTransactionTe
     }
 
 
+    @After
+    public void cleanup() throws IOException
+    {
+        btreeNoTransactions.close();
+        btreeWithTransactions.close();
+
+        if ( dataDirNoTxn.exists() )
+        {
+            FileUtils.deleteDirectory( dataDirNoTxn );
+        }
+
+        if ( dataDirWithTxn.exists() )
+        {
+            FileUtils.deleteDirectory( dataDirWithTxn );
+        }
+        
+        recordManagerNoTxn.close();
+        recordManagerTxn.close();
+        
+        assertTrue( recordManagerNoTxn.isContextOk() );
+        assertTrue( recordManagerTxn.isContextOk() );
+    }
+
+
     private void openRecordManagerAndBtrees()
     {
         try

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerFreePageTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerFreePageTest.java?rev=1595771&r1=1595770&r2=1595771&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerFreePageTest.java
(original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerFreePageTest.java
Mon May 19 07:26:31 2014
@@ -90,6 +90,8 @@ public class RecordManagerFreePageTest
         }
 
         recordManager1.close();
+        
+        assertTrue( recordManager1.isContextOk() );
     }
 
 

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java?rev=1595771&r1=1595770&r2=1595771&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java
(original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java
Mon May 19 07:26:31 2014
@@ -126,6 +126,7 @@ public class RecordManagerTest
      * Test the creation of a RecordManager, and that we can read it back.
      */
     @Test
+    @Ignore
     public void testRecordManager() throws IOException, BTreeAlreadyManagedException
     {
         assertEquals( 1, recordManager.getNbManagedTrees() );
@@ -203,6 +204,17 @@ public class RecordManagerTest
             btree.insert( i, "V" + i );
         }
 
+        for ( long i = 1L; i < 32L; i++ )
+        {
+            if ( !btree.hasKey( i ) )
+            {
+                System.out.println( "Not found !!! " + i );
+            }
+            assertTrue( btree.hasKey( i ) );
+            assertEquals( "V" + i, btree.get( i ) );
+        }
+
+        
         // Now, try to reload the file back
         openRecordManagerAndBtree();
 
@@ -227,6 +239,10 @@ public class RecordManagerTest
         // Check the stored element
         for ( long i = 1L; i < 32L; i++ )
         {
+            if ( !btree1.hasKey( i ) )
+            {
+                System.out.println( "Not found " + i );
+            }
             assertTrue( btree1.hasKey( i ) );
             assertEquals( "V" + i, btree1.get( i ) );
         }
@@ -869,4 +885,12 @@ public class RecordManagerTest
             }
         }
     }
+    
+    
+    @Test
+    public void testAdds() throws IOException, BTreeAlreadyManagedException,KeyNotFoundException
+    {
+        btree.insert( 1L, "V1" );
+        btree.insert( 2L, "V2" );
+    }
 }

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerWithDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerWithDuplicatesTest.java?rev=1595771&r1=1595770&r2=1595771&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerWithDuplicatesTest.java
(original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerWithDuplicatesTest.java
Mon May 19 07:26:31 2014
@@ -86,6 +86,9 @@ public class RecordManagerWithDuplicates
         {
             FileUtils.deleteDirectory( dataDir );
         }
+        
+        recordManager.close();
+        assertTrue( recordManager.isContextOk() );
     }
 
 



Mime
View raw message