directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1584243 - in /directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree: PersistedBTree.java PersistedValueHolder.java RecordManager.java
Date Thu, 03 Apr 2014 01:19:09 GMT
Author: elecharny
Date: Thu Apr  3 01:19:09 2014
New Revision: 1584243

URL: http://svn.apache.org/r1584243
Log:
o Modified the PersistedBTree initialization to use the parent cache and readTransactions
set when it's a sub-btree
o The PersistedBTree.getBtreeOffset() method now correctly return the BtreeHeader offset,
instead of the BtreeInfo offset
o The RecordMaager.loadBtree() method takes the parentBtree as a parameter if required
o Removed some commented code

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

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=1584243&r1=1584242&r2=1584243&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 Apr  3 01:19:09 2014
@@ -127,16 +127,17 @@ public class PersistedBTree<K, V> extend
 
         if ( btreeType == BTreeTypeEnum.PERSISTED_SUB )
         {
-            // The subBTree inherit its cache from its parent BTree
-            this.cache = ( ( PersistedBTree<K, V> ) configuration.getParentBTree()
).getCache();
-            readTransactions = new ConcurrentLinkedQueue<ReadTransaction<K, V>>();
+            // The subBTree inherits its cache and readTransactions from its parent BTree
+            init( ( PersistedBTree<K, V> ) configuration.getParentBTree() );
+        }
+        else
+        {
+            // We will create a new cache and a new readTransactions map 
+            init( null );
         }
 
         // Add the B-tree header into the revisions
         btreeRevisions.put( 0L, btreeHeader );
-
-        // Now, initialize the BTree
-        init();
     }
 
 
@@ -145,9 +146,9 @@ public class PersistedBTree<K, V> extend
      *
      * @throws IOException If we get some exception while initializing the BTree
      */
-    public void init()
+    public void init( BTree<K, V> parentBTree )
     {
-        if ( btreeType != BTreeTypeEnum.PERSISTED_SUB )
+        if ( parentBTree == null )
         {
             // This is not a subBtree, we have to initialize the cache
 
@@ -166,6 +167,11 @@ public class PersistedBTree<K, V> extend
             cache = new Cache( cacheConfiguration );
             cache.initialise();
         }
+        else
+        {
+            this.cache = ((PersistedBTree<K, V>)parentBTree).getCache();
+            this.readTransactions = ((PersistedBTree<K, V>)parentBTree).getReadTransactions();
+        }
 
         // Initialize the txnManager thread
         //FIXME we should NOT create a new transaction manager thread for each BTree
@@ -215,7 +221,7 @@ public class PersistedBTree<K, V> extend
      */
     /* No qualifier*/long getBtreeOffset()
     {
-        return getBtreeHeader().getBTreeInfoOffset();
+        return getBtreeHeader().getBTreeHeaderOffset();
     }
 
 
@@ -302,32 +308,6 @@ public class PersistedBTree<K, V> extend
             AbstractDeleteResult<K, V> deleteResult = ( AbstractDeleteResult<K,
V> ) result;
 
             Tuple<K, V> tuple = deleteResult.getRemovedElement();
-//
-//            // Update the B-tree header, creating a new BtreeHeader page now
-//            long newBtreeHeaderOffset = recordManager.updateBtreeHeader( this, ( ( AbstractPage<K,
V> ) getRootPage() ).getOffset() );
-//
-//            // Update the B-tree of B-trees with this new offset, if we are not already
doing so
-//            switch ( btreeType )
-//            {
-//                case PERSISTED :
-//                    // We have a new B-tree header to inject into the B-tree of btrees
-//                    recordManager.addInBtreeOfBtrees( getName(), revision, newBtreeHeaderOffset
);
-//                    break;
-//
-//                case BTREE_OF_BTREES :
-//                case COPIED_PAGES_BTREE :
-//                    // The B-tree of B-trees or the copiedPages B-tree has been updated,
update the RMheader parameters
-//                    getBtreeHeader().setBTreeHeaderOffset( newBtreeHeaderOffset );
-//
-//                    break;
-//
-//                default:
-//                    // Nothing to do for sub-btrees
-//                    break;
-//            }
-//
-//            // 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
@@ -390,15 +370,6 @@ public class PersistedBTree<K, V> extend
         // remain in memory.
         PageHolder<K, V> holder = writePage( newRootPage, revision );
 
-        // Store the offset on disk in the page in memory
-//        ( ( AbstractPage<K, V> ) modifiedPage ).setOffset( ( ( PersistedPageHolder<K,
V> ) holder )
-//            .getOffset() );
-//
-//        // Store the last offset on disk in the page in memory
-//        ( ( AbstractPage<K, V> ) modifiedPage )
-//            .setLastOffset( ( ( PersistedPageHolder<K, V> ) holder )
-//                .getLastOffset() );
-
         // Decrease the number of elements in the current tree
         newBtreeHeader.decrementNbElems();
         newBtreeHeader.setRootPage( newRootPage );

Modified: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedValueHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedValueHolder.java?rev=1584243&r1=1584242&r2=1584243&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedValueHolder.java
(original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedValueHolder.java
Thu Apr  3 01:19:09 2014
@@ -655,7 +655,7 @@ import org.apache.directory.mavibot.btre
         long offset = LongSerializer.deserialize( raw );
 
         // and reload the sub btree
-        valueBtree = parentBtree.getRecordManager().loadDupsBtree( offset );
+        valueBtree = parentBtree.getRecordManager().loadDupsBtree( offset, parentBtree );
     }
 
 

Modified: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java?rev=1584243&r1=1584242&r2=1584243&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
(original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
Thu Apr  3 01:19:09 2014
@@ -32,10 +32,13 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.UUID;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import net.sf.ehcache.Cache;
+
 import org.apache.directory.mavibot.btree.exception.BTreeAlreadyManagedException;
 import org.apache.directory.mavibot.btree.exception.BTreeCreationException;
 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
@@ -706,6 +709,26 @@ public class RecordManager
     private <K, V> void loadBtree( PageIO[] pageIos, BTree<K, V> btree ) throws
EndOfFileExceededException,
         IOException, ClassNotFoundException, IllegalAccessException, InstantiationException,
IllegalArgumentException, SecurityException, NoSuchFieldException
     {
+        loadBtree( pageIos, btree, null );
+    }
+
+
+    /**
+     * Read a B-tree from the disk. The meta-data are at the given position in the list of
pages.
+     * We load a B-tree in two steps : first, we load the B-tree header, then the common
informations
+     *
+     * @param pageIos The list of pages containing the meta-data
+     * @param btree The B-tree we have to initialize
+     * @throws InstantiationException
+     * @throws IllegalAccessException
+     * @throws ClassNotFoundException
+     * @throws NoSuchFieldException
+     * @throws SecurityException
+     * @throws IllegalArgumentException
+     */
+    private <K, V> void loadBtree( PageIO[] pageIos, BTree btree, BTree<K, V>
parentBTree ) throws EndOfFileExceededException,
+        IOException, ClassNotFoundException, IllegalAccessException, InstantiationException,
IllegalArgumentException, SecurityException, NoSuchFieldException
+    {
         long dataPos = 0L;
 
         // Process the B-tree header
@@ -785,7 +808,7 @@ public class RecordManager
 
         // Now, init the B-tree
         ( ( PersistedBTree<K, V> ) btree ).setRecordManager( this );
-        ( ( PersistedBTree<K, V> ) btree ).init();
+        ( ( PersistedBTree<K, V> ) btree ).init( parentBTree );
 
         // Read the rootPage pages on disk
         PageIO[] rootPageIos = readPageIOs( rootPageOffset, Long.MAX_VALUE );
@@ -3928,16 +3951,15 @@ public class RecordManager
      * @param offset the offset of the B-tree header
      * @return the deserialized B-tree
      */
-    /* No qualifier */<K, V> BTree<K, V> loadDupsBtree( long btreeHeaderOffset
)
+    /* No qualifier */<K, V> BTree<V, V> loadDupsBtree( long btreeHeaderOffset,
BTree<K, V> parentBtree )
     {
         try
         {
             PageIO[] pageIos = readPageIOs( btreeHeaderOffset, Long.MAX_VALUE );
 
-            BTree<K, V> subBtree = BTreeFactory.createPersistedBTree();
-            ( ( PersistedBTree<K, V> ) subBtree ).setBtreeHeaderOffset( btreeHeaderOffset
);
-
-            loadBtree( pageIos, subBtree );
+            BTree<V, V> subBtree = BTreeFactory.<V, V> createPersistedBTree(
BTreeTypeEnum.PERSISTED_SUB );
+            loadBtree( pageIos, subBtree, parentBtree );
+            
 
             return subBtree;
         }



Mime
View raw message