directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1572368 - in /directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree: BTreeHeader.java InMemoryBTree.java PersistedBTree.java
Date Thu, 27 Feb 2014 00:44:06 GMT
Author: elecharny
Date: Thu Feb 27 00:44:06 2014
New Revision: 1572368

URL: http://svn.apache.org/r1572368
Log:
o Injecting the rootPage in the BTreeHeader will compute the rootPageOffset if needed (no
need to inject it)
o Added the rollback() call in the insert method
o Written the rootPage on disk when we have a split

Modified:
    directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeHeader.java
    directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTree.java
    directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java

Modified: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeHeader.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeHeader.java?rev=1572368&r1=1572367&r2=1572368&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeHeader.java
(original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeHeader.java
Thu Feb 27 00:44:06 2014
@@ -225,6 +225,7 @@ import java.util.concurrent.atomic.Atomi
     /* no qualifier */ void setRootPage( Page<K, V> rootPage )
     {
         this.rootPage = rootPage;
+        this.rootPageOffset = ((AbstractPage<K, V>)rootPage).getOffset();
     }
 
 

Modified: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTree.java?rev=1572368&r1=1572367&r2=1572368&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTree.java
(original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTree.java
Thu Feb 27 00:44:06 2014
@@ -835,7 +835,6 @@ import org.slf4j.LoggerFactory;
         newBtreeHeader.setRevision( revision );
         newBtreeHeader.setNbElems( btreeHeader.getNbElems() );
         newBtreeHeader.setRootPage( btreeHeader.getRootPage() );
-        newBtreeHeader.setRootPageOffset( btreeHeader.getRootPageOffset() );
 
         return newBtreeHeader;
     }

Modified: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java?rev=1572368&r1=1572367&r2=1572368&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
(original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
Thu Feb 27 00:44:06 2014
@@ -403,20 +403,26 @@ public class PersistedBTree<K, V> extend
 
         recordManager.beginTransaction();
 
-        // Try to insert the new value in the tree at the right place,
-        // starting from the root page. Here, the root page may be either
-        // a Node or a Leaf
-        InsertResult<K, V> result = processInsert( key, value, revision );
-
-        // We can safely free the copied pages
-        //recordManager.freePages( this, revision, result.getCopiedPages() );
-
-        // If the B-tree is managed, we have to update the rootPage on disk
-        // Update the RecordManager header
-        commit();
+        try
+        {
+            // Try to insert the new value in the tree at the right place,
+            // starting from the root page. Here, the root page may be either
+            // a Node or a Leaf
+            InsertResult<K, V> result = processInsert( key, value, revision );
 
-        // Return the value we have found if it was modified
-        return result;
+            // Done ! we can commit now
+            commit();
+
+            // Return the value we have found if it was modified
+            return result;
+        }
+        catch ( IOException ioe )
+        {
+            // if we've got an error, we have to rollback
+            rollback();
+
+            throw ioe;
+        }
     }
 
 
@@ -425,13 +431,14 @@ public class PersistedBTree<K, V> extend
      */
     private InsertResult<K, V> processInsert( K key, V value, long revision ) throws
IOException
     {
+        // Get the current B-tree header, and insert the value into it
         BTreeHeader<K, V> btreeHeader = getBtreeHeader();
         InsertResult<K, V> result = btreeHeader.getRootPage().insert( key, value, revision
);
 
         // Create a new BTreeHeader
         BTreeHeader<K, V> newBtreeHeader = btreeHeader.copy();
 
-        // Inject the old btreeHeader into the pages to be freed
+        // Inject the old B-tree header into the pages to be freed
         // if we are inserting an element in a management BTree
         if ( btreeType == BTreeTypeEnum.PERSISTED_MANAGEMENT )
         {
@@ -451,9 +458,6 @@ public class PersistedBTree<K, V> extend
 
             newRootPage = modifyResult.getModifiedPage();
 
-            // Write the new root page on disk
-            PageHolder<K, V> newRootPageHolder = writePage( newRootPage, revision );
-
             // Increment the counter if we have inserted a new value
             if ( modifyResult.getModifiedValue() == null )
             {
@@ -483,10 +487,11 @@ public class PersistedBTree<K, V> extend
             newBtreeHeader.incrementNbElems();
         }
 
+        // Write the new root page on disk
+        writePage( newRootPage, revision );
+
         // Update the new B-tree header
-        long newRootPageOffset = ((AbstractPage<K, V>)newRootPage).getOffset();
         newBtreeHeader.setRootPage( newRootPage );
-        newBtreeHeader.setRootPageOffset( newRootPageOffset );
         newBtreeHeader.setRevision( revision );
 
         // Write down the data on disk



Mime
View raw message