directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1551946 - in /directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree: PersistedBTree.java PersistedBTreeBuilder.java PersistedNode.java RecordManager.java
Date Wed, 18 Dec 2013 13:59:15 GMT
Author: elecharny
Date: Wed Dec 18 13:59:14 2013
New Revision: 1551946

URL: http://svn.apache.org/r1551946
Log:
o Used PageHolder instead of PersistedPageHolder when we can
o Added some Javadoc

Modified:
    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/PersistedBTreeBuilder.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedNode.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java

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=1551946&r1=1551945&r2=1551946&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
Wed Dec 18 13:59:14 2013
@@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
 
 /**
  * The B+Tree MVCC data structure.
- * 
+ *
  * @param <K> The type for the keys
  * @param <V> The type for the stored values
  *
@@ -76,7 +76,7 @@ public class PersistedBTree<K, V> extend
 
 
     /**
-     * Creates a new BTree, with no initialization. 
+     * Creates a new BTree, with no initialization.
      */
     /* no qualifier */PersistedBTree()
     {
@@ -86,9 +86,9 @@ public class PersistedBTree<K, V> extend
 
 
     /**
-     * Creates a new persisted BTree using the BTreeConfiguration to initialize the 
+     * Creates a new persisted BTree using the BTreeConfiguration to initialize the
      * BTree
-     * 
+     *
      * @param configuration The configuration to use
      */
     /* no qualifier */PersistedBTree( PersistedBTreeConfiguration<K, V> configuration
)
@@ -142,7 +142,7 @@ public class PersistedBTree<K, V> extend
 
     /**
      * Initialize the BTree.
-     * 
+     *
      * @throws IOException If we get some exception while initializing the BTree
      */
     public void init()
@@ -279,7 +279,7 @@ public class PersistedBTree<K, V> extend
 
     /**
      * Gets the RecordManager for a managed BTree
-     * 
+     *
      * @return The recordManager if the BTree is managed
      */
     /* No qualifier */RecordManager getRecordManager()
@@ -290,7 +290,7 @@ public class PersistedBTree<K, V> extend
 
     /**
      * Inject a RecordManager for a managed BTree
-     * 
+     *
      * @param recordManager The injected RecordManager
      */
     /* No qualifier */void setRecordManager( RecordManager recordManager )
@@ -300,12 +300,12 @@ public class PersistedBTree<K, V> extend
 
 
     /**
-     * 
+     *
      * Deletes the given <key,value> pair if both key and value match. If the given
value is null
      * and there is no null value associated with the given key then the entry with the given
key
      * will be removed.
      *
-     * @param key The key to be removed 
+     * @param key The key to be removed
      * @param value The value to be removed (can be null, and when no null value exists the
key will be removed irrespective of the value)
      * @param revision The revision to be associated with this operation
      * @return
@@ -344,8 +344,7 @@ public class PersistedBTree<K, V> extend
                 // Write the modified page on disk
                 // Note that we don't use the holder, the new root page will
                 // remain in memory.
-                PersistedPageHolder<K, V> holder = recordManager.writePage( this, modifiedPage,
-                    revision );
+                PageHolder<K, V> holder = recordManager.writePage( this, modifiedPage,
revision );
 
                 // Store the offset on disk in the page in memory
                 ( ( AbstractPage<K, V> ) modifiedPage ).setOffset( ( ( PersistedPageHolder<K,
V> ) holder )
@@ -428,8 +427,7 @@ public class PersistedBTree<K, V> extend
             // Write the modified page on disk
             // Note that we don't use the holder, the new root page will
             // remain in memory.
-            PersistedPageHolder<K, V> holder = recordManager.writePage( this, modifiedPage,
-                revision );
+            PageHolder<K, V> holder = recordManager.writePage( this, modifiedPage,
revision );
 
             // The root has just been modified, we haven't split it
             // Get it and make it the current root page
@@ -450,18 +448,16 @@ public class PersistedBTree<K, V> extend
 
             // If the BTree is managed, we have to write the two pages that were created
             // and to keep a track of the two offsets for the upper node
-            PersistedPageHolder<K, V> holderLeft = recordManager.writePage( this,
-                leftPage, revision );
+            PageHolder<K, V> holderLeft = recordManager.writePage( this, leftPage,
revision );
 
-            PersistedPageHolder<K, V> holderRight = recordManager.writePage( this,
-                rightPage, revision );
+            PageHolder<K, V> holderRight = recordManager.writePage( this, rightPage,
revision );
 
             // Create the new rootPage
             newRootPage = new PersistedNode<K, V>( this, revision, pivot, holderLeft,
holderRight );
 
             // If the BTree is managed, we now have to write the page on disk
             // and to add this page to the list of modified pages
-            PersistedPageHolder<K, V> holder = recordManager
+            PageHolder<K, V> holder = recordManager
                 .writePage( this, newRootPage, revision );
 
             rootPage = newRootPage;
@@ -494,7 +490,7 @@ public class PersistedBTree<K, V> extend
 
     /**
      * Write the data in the ByteBuffer, and eventually on disk if needed.
-     * 
+     *
      * @param channel The channel we want to write to
      * @param bb The ByteBuffer we want to feed
      * @param buffer The data to inject
@@ -535,7 +531,7 @@ public class PersistedBTree<K, V> extend
 
     /**
      * Get the rootPzge associated to a give revision.
-     * 
+     *
      * @param revision The revision we are looking for
      * @return The rootPage associated to this revision
      * @throws IOException If we had an issue while accessing the underlying file

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTreeBuilder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTreeBuilder.java?rev=1551946&r1=1551945&r2=1551946&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTreeBuilder.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTreeBuilder.java
Wed Dec 18 13:59:14 2013
@@ -92,7 +92,7 @@ public class PersistedBTreeBuilder<K, V>
             {
                 leafIndex = 0;
 
-                PersistedPageHolder<K, V> pageHolder = rm.writePage( btree, leaf1,
1 );
+                PageHolder<K, V> pageHolder = rm.writePage( btree, leaf1, 1 );
 
                 leaf1 = ( PersistedLeaf<K, V> ) BTreeFactory.createLeaf( btree, 0,
numKeysInNode );
                 lstLeaves.add( leaf1 );
@@ -123,7 +123,7 @@ public class PersistedBTreeBuilder<K, V>
                 lastLeaf.values = ( PersistedValueHolder<V>[] ) Array.newInstance(
PersistedValueHolder.class, n );
                 System.arraycopy( values, 0, lastLeaf.values, 0, n );
 
-                PersistedPageHolder<K, V> pageHolder = rm.writePage( btree, lastLeaf,
1 );
+                PageHolder<K, V> pageHolder = rm.writePage( btree, lastLeaf, 1 );
 
                 break;
             }
@@ -179,7 +179,7 @@ public class PersistedBTreeBuilder<K, V>
             {
                 i = 0;
 
-                PersistedPageHolder<K, V> pageHolder = rm.writePage( btree, node, 1
);
+                PageHolder<K, V> pageHolder = rm.writePage( btree, node, 1 );
 
                 node = ( PersistedNode<K, V> ) BTreeFactory.createNode( btree, 0, numKeysInNode
);
                 lstNodes.add( node );
@@ -200,7 +200,7 @@ public class PersistedBTreeBuilder<K, V>
                 lastNode.setKeys( ( KeyHolder[] ) Array.newInstance( KeyHolder.class, n )
);
                 System.arraycopy( keys, 0, lastNode.getKeys(), 0, n );
 
-                PersistedPageHolder<K, V> pageHolder = rm.writePage( btree, lastNode,
1 );
+                PageHolder<K, V> pageHolder = rm.writePage( btree, lastNode, 1 );
 
                 break;
             }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedNode.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedNode.java?rev=1551946&r1=1551945&r2=1551946&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedNode.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedNode.java
Wed Dec 18 13:59:14 2013
@@ -28,7 +28,7 @@ import java.util.List;
 /**
  * A MVCC Node. It stores the keys and references to its children page. It does not
  * contain any value.
- * 
+ *
  * @param <K> The type for the Key
  * @param <V> The type for the stored value
  *
@@ -40,7 +40,7 @@ import java.util.List;
      * Creates a new Node which will contain only one key, with references to
      * a left and right page. This is a specific constructor used by the btree
      * when the root was full when we added a new value.
-     * 
+     *
      * @param btree the parent BTree
      * @param revision the Node revision
      * @param nbElems The number of elements in this Node
@@ -59,7 +59,7 @@ import java.util.List;
      * Creates a new Node which will contain only one key, with references to
      * a left and right page. This is a specific constructor used by the btree
      * when the root was full when we added a new value.
-     * 
+     *
      * @param btree the parent BTree
      * @param revision the Node revision
      * @param key The new key
@@ -91,7 +91,7 @@ import java.util.List;
      * Creates a new Node which will contain only one key, with references to
      * a left and right page. This is a specific constructor used by the btree
      * when the root was full when we added a new value.
-     * 
+     *
      * @param btree the parent BTree
      * @param revision the Node revision
      * @param key The new key
@@ -99,8 +99,7 @@ import java.util.List;
      * @param rightPage The right page
      */
     @SuppressWarnings("unchecked")
-    PersistedNode( BTree<K, V> btree, long revision, K key, PersistedPageHolder<K,
V> leftPage,
-        PersistedPageHolder<K, V> rightPage )
+    PersistedNode( BTree<K, V> btree, long revision, K key, PageHolder<K, V>
leftPage, PageHolder<K, V> rightPage )
     {
         super( btree, revision, 1 );
 
@@ -177,7 +176,7 @@ import java.util.List;
     /**
      * Modifies the current node after a remove has been done in one of its children.
      * The node won't be merged with another node.
-     * 
+     *
      * @param removeResult The result of a remove operation
      * @param index the position of the key, not transformed
      * @param pos The position of the key, as a positive value
@@ -220,7 +219,7 @@ import java.util.List;
     /**
      * Handles the removal of an element from the root page, when two of its children
      * have been merged.
-     * 
+     *
      * @param mergedResult The merge result
      * @param pos The position in the current root
      * @param found Tells if the removed key is present in the root page
@@ -255,7 +254,7 @@ import java.util.List;
      * Borrows an element from the right sibling, creating a new sibling with one
      * less element and creating a new page where the element to remove has been
      * deleted and the borrowed element added on the right.
-     * 
+     *
      * @param revision The new revision for all the pages
      * @param sibling The right sibling
      * @param pos The position of the element to remove
@@ -342,7 +341,7 @@ import java.util.List;
      * Borrows an element from the left sibling, creating a new sibling with one
      * less element and creating a new page where the element to remove has been
      * deleted and the borrowed element added on the left.
-     * 
+     *
      * @param revision The new revision for all the pages
      * @param sibling The left sibling
      * @param pos The position of the element to remove
@@ -430,7 +429,7 @@ import java.util.List;
     /**
      * We have to merge the node with its sibling, both have N/2 elements before the element
      * removal.
-     * 
+     *
      * @param revision The revision
      * @param mergedResult The result of the merge
      * @param sibling The Page we will merge the current page with
@@ -649,7 +648,7 @@ import java.util.List;
                 // We will remove one element from a page that will have less than N/2 elements,
                 // which will lead to some reorganization : either we can borrow an element
from
                 // a sibling, or we will have to merge two pages
-                int siblingPos = selectSibling( ( PersistedNode<K, V> ) parent, parentPos
);
+                int siblingPos = selectSibling( parent, parentPos );
 
                 PersistedNode<K, V> sibling = ( PersistedNode<K, V> ) ( ( ( PersistedNode<K,
V> ) parent ).children[siblingPos]
                     .getValue() );
@@ -769,7 +768,7 @@ import java.util.List;
 
     /**
      * Remove the key at a given position.
-     * 
+     *
      * @param mergedResult The page we will remove a key from
      * @param revision The revision of the modified page
      * @param pos The position into the page of the element to remove
@@ -849,7 +848,7 @@ import java.util.List;
 
     /**
      * Set the value at a give position
-     * 
+     *
      * @param pos The position in the values array
      * @param value the value to inject
      */
@@ -863,7 +862,7 @@ import java.util.List;
      * This method is used when we have to replace a child in a page when we have
      * found the key in the tree (the value will be changed, so we have made
      * copies of the existing pages).
-     * 
+     *
      * @param revision The current revision
      * @param result The modified page
      * @param pos The position of the found key
@@ -892,15 +891,15 @@ import java.util.List;
 
 
     /**
-     * Creates a new holder contaning a reference to a Page
-     * 
+     * Creates a new holder containing a reference to a Page
+     *
      * @param page The page we will refer to
-     * @return A holder contaning a reference to the child page
+     * @return A holder containing a reference to the child page
      * @throws IOException If we have an error while trying to access the page
      */
-    private PersistedPageHolder<K, V> createHolder( Page<K, V> page ) throws
IOException
+    private PageHolder<K, V> createHolder( Page<K, V> page ) throws IOException
     {
-        PersistedPageHolder<K, V> holder = ( ( PersistedBTree<K, V> ) btree ).getRecordManager().writePage(
btree,
+        PageHolder<K, V> holder = ( ( PersistedBTree<K, V> ) btree ).getRecordManager().writePage(
btree,
             page,
             revision );
 
@@ -911,7 +910,7 @@ import java.util.List;
     /**
      * Adds a new key into a copy of the current page at a given position. We return the
      * modified page. The new page will have one more key than the current page.
-     * 
+     *
      * @param copiedPages the list of copied pages
      * @param revision The revision of the modified page
      * @param key The key to insert
@@ -966,7 +965,7 @@ import java.util.List;
      * If the newly added element is in the middle, we will use it
      * as a pivot. Otherwise, we will use either the last element in the left page if the
element is added
      * on the left, or the first element in the right page if it's added on the right.
-     * 
+     *
      * @param copiedPages the list of copied pages
      * @param revision The new revision for all the created pages
      * @param pivot The key that will be move up after the split
@@ -1079,7 +1078,7 @@ import java.util.List;
 
     /**
      * Copies the current page and all its keys, with a new revision.
-     * 
+     *
      * @param revision The new revision
      * @return The copied page
      */

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=1551946&r1=1551945&r2=1551946&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
Wed Dec 18 13:59:14 2013
@@ -1914,16 +1914,14 @@ public class RecordManager
      * Stores a new page on disk. We will add the modified page into the tree of copied pages.
      * The new page is serialized and saved on disk.
      *
-     * @param oldPage
-     * @param oldRevision
-     * @param newPage
-     * @param newRevision
-     * @return The offset of the new page
-     * @throws IOException
+     * @param btree The persistedBTree we will create a new PageHolder for
+     * @param newPage The page to write on disk
+     * @param newRevision The page's revision
+     * @return A PageHolder containing the copied page
+     * @throws IOException If the page can't be written on disk
      */
-    /* No qualifier*/<K, V> PersistedPageHolder<K, V> writePage( BTree<K,
V> btree, Page<K, V> newPage,
-        long newRevision )
-        throws IOException
+    /* No qualifier*/<K, V> PageHolder<K, V> writePage( BTree<K, V> btree,
Page<K, V> newPage,
+        long newRevision ) throws IOException
     {
         // We first need to save the new page on disk
         PageIO[] pageIos = serializePage( btree, newRevision, newPage );
@@ -1936,7 +1934,7 @@ public class RecordManager
         // Build the resulting reference
         long offset = pageIos[0].getOffset();
         long lastOffset = pageIos[pageIos.length - 1].getOffset();
-        PersistedPageHolder<K, V> valueHolder = new PersistedPageHolder<K, V>(
btree, newPage, offset,
+        PersistedPageHolder<K, V> pageHolder = new PersistedPageHolder<K, V>(
btree, newPage, offset,
             lastOffset );
 
         if ( LOG_CHECK.isDebugEnabled() )
@@ -1944,7 +1942,7 @@ public class RecordManager
             check();
         }
 
-        return valueHolder;
+        return pageHolder;
     }
 
 



Mime
View raw message