directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1574073 - in /directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree: BTreeFactory.java RecordManager.java
Date Tue, 04 Mar 2014 12:56:47 GMT
Author: elecharny
Date: Tue Mar  4 12:56:47 2014
New Revision: 1574073

URL: http://svn.apache.org/r1574073
Log:
o Implemented the load method for persisted btrees

Modified:
    directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.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/BTreeFactory.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java?rev=1574073&r1=1574072&r2=1574073&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java
(original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java
Tue Mar  4 12:56:47 2014
@@ -41,7 +41,6 @@ public class BTreeFactory<K, V>
     //--------------------------------------------------------------------------------------------
     // Create persisted btrees
     //--------------------------------------------------------------------------------------------
-
     /**
      * Creates a new persisted B-tree, with no initialization.
      *
@@ -56,6 +55,31 @@ public class BTreeFactory<K, V>
 
 
     /**
+     * Creates a new persisted B-tree, with no initialization.
+     *
+     * @return a new B-tree instance
+     */
+    public static <K, V> BTree<K, V> createPersistedBTree( BTreeTypeEnum type
)
+    {
+        BTree<K, V> btree = new PersistedBTree<K, V>();
+        ((AbstractBTree<K, V>)btree).setType( type );
+
+        return btree;
+    }
+
+
+    /**
+     * Sets the btreeHeader offset for a Persisted BTree
+     *
+     * @param btree The btree to update
+     * @param btreeHeaderOffset The offset
+     */
+    public static <K, V> void setBtreeHeaderOffset( PersistedBTree<K, V> btree,
long btreeHeaderOffset )
+    {
+        btree.setBtreeHeaderOffset( btreeHeaderOffset );
+    }
+
+    /**
      * Creates a new persisted B-tree using the BTreeConfiguration to initialize the
      * B-tree
      *
@@ -467,7 +491,7 @@ public class BTreeFactory<K, V>
      */
     /* no qualifier*/static <K, V> Page<K, V> createLeaf( BTree<K, V> btree,
long revision, int nbElems )
     {
-        if ( btree.getType() == BTreeTypeEnum.PERSISTED )
+        if ( btree.getType() != BTreeTypeEnum.IN_MEMORY )
         {
             return new PersistedLeaf<K, V>( btree, revision, nbElems );
         }
@@ -488,7 +512,7 @@ public class BTreeFactory<K, V>
      */
     /* no qualifier*/static <K, V> Page<K, V> createNode( BTree<K, V> btree,
long revision, int nbElems )
     {
-        if ( btree.getType() == BTreeTypeEnum.PERSISTED )
+        if ( btree.getType() != BTreeTypeEnum.IN_MEMORY )
         {
             return new PersistedNode<K, V>( btree, revision, nbElems );
         }
@@ -514,7 +538,7 @@ public class BTreeFactory<K, V>
     {
         KeyHolder<K> keyHolder;
 
-        if ( btree.getType() == BTreeTypeEnum.PERSISTED )
+        if ( btree.getType() != BTreeTypeEnum.IN_MEMORY )
         {
             keyHolder = new PersistedKeyHolder<K>( btree.getKeySerializer(), key );
         }
@@ -537,7 +561,7 @@ public class BTreeFactory<K, V>
      */
     /* no qualifier*/static <K, V> void setValue( BTree<K, V> btree, Page<K,
V> page, int pos, ValueHolder<V> value )
     {
-        if ( btree.getType() == BTreeTypeEnum.PERSISTED )
+        if ( btree.getType() != BTreeTypeEnum.IN_MEMORY )
         {
             ( ( PersistedLeaf<K, V> ) page ).setValue( pos, value );
         }
@@ -558,7 +582,7 @@ public class BTreeFactory<K, V>
      */
     /* no qualifier*/static <K, V> void setPage( BTree<K, V> btree, Page<K,
V> page, int pos, Page<K, V> child )
     {
-        if ( btree.getType() == BTreeTypeEnum.PERSISTED )
+        if ( btree.getType() != BTreeTypeEnum.IN_MEMORY )
         {
             ( ( PersistedNode<K, V> ) page ).setValue( pos, new PersistedPageHolder<K,
V>( btree, child ) );
         }

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=1574073&r1=1574072&r2=1574073&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
Tue Mar  4 12:56:47 2014
@@ -455,17 +455,19 @@ public class RecordManager
             previousCopiedPagesBtreeOffset = recordManagerHeader.getLong();
 
             // read the B-tree of B-trees
-            PageIO[] bobPageIos = readPageIOs( currentBtreeOfBtreesOffset, Long.MAX_VALUE
);
+            PageIO[] bobHeaderPageIos = readPageIOs( currentBtreeOfBtreesOffset, Long.MAX_VALUE
);
 
-            btreeOfBtrees = BTreeFactory.<NameRevision, Long> createPersistedBTree();
-            ( ( PersistedBTree<NameRevision, Long> ) btreeOfBtrees ).setBtreeHeaderOffset(
currentBtreeOfBtreesOffset );
-            loadBtree( bobPageIos, btreeOfBtrees );
+            btreeOfBtrees = BTreeFactory.<NameRevision, Long> createPersistedBTree(
BTreeTypeEnum.BTREE_OF_BTREES );
+            //BTreeFactory.<NameRevision, Long> setBtreeHeaderOffset( ( PersistedBTree<NameRevision,
Long> )btreeOfBtrees, currentBtreeOfBtreesOffset );
+
+            loadBtree( bobHeaderPageIos, btreeOfBtrees );
 
             // read the copied page B-tree
             PageIO[] copiedPagesPageIos = readPageIOs( currentCopiedPagesBtreeOffset, Long.MAX_VALUE
);
 
-            copiedPageBtree = BTreeFactory.<RevisionName, long[]> createPersistedBTree();
-            ( ( PersistedBTree<RevisionName, long[]> ) copiedPageBtree ).setBtreeHeaderOffset(
currentCopiedPagesBtreeOffset );
+            copiedPageBtree = BTreeFactory.<RevisionName, long[]> createPersistedBTree(
BTreeTypeEnum.COPIED_PAGES_BTREE );
+            //( ( PersistedBTree<RevisionName, long[]> ) copiedPageBtree ).setBtreeHeaderOffset(
currentCopiedPagesBtreeOffset );
+
             loadBtree( copiedPagesPageIos, copiedPageBtree );
 
             // Now, read all the B-trees from the btree of btrees
@@ -482,7 +484,7 @@ public class RecordManager
                 long btreeOffset = btreeTuple.getValue();
                 long revision = nameRevision.getValue();
 
-                // Check if we already have prcoessed this B-tree
+                // Check if we already have processed this B-tree
                 Long loadedBtreeRevision = loadedBtrees.get( nameRevision.getName() );
 
                 if ( loadedBtreeRevision != null )
@@ -514,7 +516,7 @@ public class RecordManager
                 PageIO[] btreePageIos = readPageIOs( btreeOffset, Long.MAX_VALUE );
 
                 BTree<?, ?> btree = BTreeFactory.<NameRevision, Long> createPersistedBTree();
-                ( ( PersistedBTree<NameRevision, Long> ) btree ).setBtreeHeaderOffset(
btreeOffset );
+                //( ( PersistedBTree<NameRevision, Long> ) btree ).setBtreeHeaderOffset(
btreeOffset );
                 loadBtree( btreePageIos, btree );
 
                 // Add the btree into the map of managed B-trees
@@ -545,6 +547,13 @@ public class RecordManager
     {
         lockHeldCounter--;
 
+        if ( !fileChannel.isOpen() )
+        {
+            // The file has been closed, nothing remains to commit, let's get out
+            transactionLock.unlock();
+            return;
+        }
+
         if ( lockHeldCounter == 0 )
         {
             // We are done with the transaction
@@ -699,20 +708,26 @@ public class RecordManager
     {
         long dataPos = 0L;
 
-        // Process teh B-tree header
+        // Process the B-tree header
+        BTreeHeader<K, V> btreeHeader = new BTreeHeader<K, V>();
+        btreeHeader.setBtree( btree );
+
+        // The BtreeHeader offset
+        btreeHeader.setBTreeHeaderOffset( pageIos[0].getOffset() );
+
         // The B-tree current revision
         long revision = readLong( pageIos, dataPos );
-        BTreeFactory.setRevision( btree, revision );
+        btreeHeader.setRevision( revision );
         dataPos += LONG_SIZE;
 
         // The nb elems in the tree
         long nbElems = readLong( pageIos, dataPos );
-        BTreeFactory.setNbElems( btree, nbElems );
+        btreeHeader.setNbElems( nbElems );
         dataPos += LONG_SIZE;
 
         // The B-tree rootPage offset
         long rootPageOffset = readLong( pageIos, dataPos );
-        BTreeFactory.setRootPageOffset( btree, rootPageOffset );
+        btreeHeader.setRootPageOffset( rootPageOffset );
         dataPos += LONG_SIZE;
 
         // The B-tree information offset
@@ -720,6 +735,7 @@ public class RecordManager
 
         // Now, process the common informations
         PageIO[] infoPageIos = readPageIOs( btreeInfoOffset, Long.MAX_VALUE );
+        ((PersistedBTree<K, V>)btree).setBtreeInfoOffset( infoPageIos[0].getOffset()
);
         dataPos = 0L;
 
         // The B-tree page size
@@ -764,10 +780,12 @@ public class RecordManager
         ( ( PersistedBTree<K, V> ) btree ).setAllowDuplicates( allowDuplicates != 0
);
         dataPos += INT_SIZE;
 
-        // Now, init the B-tree
-        //btree.init();
+        // Set the current revision to the one stored in the B-tree header
+        ((PersistedBTree<K, V>)btree).storeRevision( btreeHeader );
 
+        // Now, init the B-tree
         ( ( PersistedBTree<K, V> ) btree ).setRecordManager( this );
+        ( ( PersistedBTree<K, V> ) btree ).init();
 
         // Read the rootPage pages on disk
         PageIO[] rootPageIos = readPageIOs( rootPageOffset, Long.MAX_VALUE );



Mime
View raw message