directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1513417 - in /directory/mavibot/trunk/mavibot/src: main/java/org/apache/directory/mavibot/btree/ test/java/org/apache/directory/mavibot/btree/
Date Tue, 13 Aug 2013 10:09:14 GMT
Author: elecharny
Date: Tue Aug 13 10:09:14 2013
New Revision: 1513417

URL: http://svn.apache.org/r1513417
Log:
More generic improvements

Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Leaf.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Node.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTest.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java?rev=1513417&r1=1513416&r2=1513417&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
Tue Aug 13 10:09:14 2013
@@ -31,9 +31,7 @@ import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.util.Comparator;
 import java.util.LinkedList;
-import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
@@ -117,9 +115,6 @@ public class BTree<K, V>
     /** The thread responsible for the cleanup of timed out reads */
     private Thread readTransactionsThread;
 
-    /** The thread responsible for the journal updates */
-    private Thread journalManagerThread;
-
     /** Define a default delay for a read transaction. This is 10 seconds */
     public static final long DEFAULT_READ_TIMEOUT = 10 * 1000L;
 
@@ -130,6 +125,7 @@ public class BTree<K, V>
 
     private FileChannel journalChannel = null;
 
+
     /**
      * Create a thread that is responsible of cleaning the transactions when
      * they hit the timeout
@@ -461,7 +457,6 @@ public class BTree<K, V>
             journalChannel.close();
         }
 
-        
         rootPage = null;
     }
 
@@ -1108,22 +1103,22 @@ public class BTree<K, V>
 
                 // Store the offset on disk in the page
                 ( ( AbstractPage<K, V> ) splitResult.getLeftPage() )
-                    .setOffset( ( ( ReferenceHolder ) holderLeft ).getOffset() );
+                    .setOffset( ( ( ReferenceHolder<Page<K, V>, K, V> ) holderLeft
).getOffset() );
 
                 // Store the last offset on disk in the page
                 ( ( AbstractPage<K, V> ) splitResult.getLeftPage() )
-                    .setLastOffset( ( ( ReferenceHolder ) holderLeft ).getLastOffset() );
+                    .setLastOffset( ( ( ReferenceHolder<Page<K, V>, K, V> ) holderLeft
).getLastOffset() );
 
                 ElementHolder<Page<K, V>, K, V> holderRight = recordManager.writePage(
this,
                     rightPage, revision );
 
                 // Store the offset on disk in the page
                 ( ( AbstractPage<K, V> ) splitResult.getRightPage() )
-                    .setOffset( ( ( ReferenceHolder ) holderRight ).getOffset() );
+                    .setOffset( ( ( ReferenceHolder<Page<K, V>, K, V> ) holderRight
).getOffset() );
 
                 // Store the last offset on disk in the page
                 ( ( AbstractPage<K, V> ) splitResult.getRightPage() )
-                    .setLastOffset( ( ( ReferenceHolder ) holderRight ).getLastOffset() );
+                    .setLastOffset( ( ( ReferenceHolder<Page<K, V>, K, V> ) holderRight
).getLastOffset() );
 
                 // Create the new rootPage
                 newRootPage = new Node<K, V>( this, revision, pivot, holderLeft, holderRight
);
@@ -1142,10 +1137,12 @@ public class BTree<K, V>
                     .writePage( this, newRootPage, revision );
 
                 // Store the offset on disk in the page
-                ( ( AbstractPage<K, V> ) newRootPage ).setOffset( ( ( ReferenceHolder
) holder ).getOffset() );
+                ( ( AbstractPage<K, V> ) newRootPage ).setOffset( ( ( ReferenceHolder<Page<K,
V>, K, V> ) holder )
+                    .getOffset() );
 
                 // Store the last offset on disk in the page
-                ( ( AbstractPage<K, V> ) newRootPage ).setLastOffset( ( ( ReferenceHolder
) holder ).getLastOffset() );
+                ( ( AbstractPage<K, V> ) newRootPage ).setLastOffset( ( ( ReferenceHolder<Page<K,
V>, K, V> ) holder )
+                    .getLastOffset() );
             }
 
             rootPage = newRootPage;
@@ -1631,30 +1628,25 @@ public class BTree<K, V>
      * @param value The value to store
      * @return The value holder
      */
-    /* no qualifier */ElementHolder createHolder( Object value )
+    /* no qualifier */ElementHolder<V, K, V> createValueHolder( V value )
     {
         if ( type == BTreeTypeEnum.MANAGED )
         {
-            if ( value instanceof Page )
-            {
-                return new ReferenceHolder<Page<K, V>, K, V>( this, ( Page<K,
V> ) value,
-                    ( ( Page<K, V> ) value ).getOffset(), ( ( Page<K, V> ) value
).getLastOffset() );
-            }
-            else if ( isAllowDuplicates() )
+            if ( isAllowDuplicates() )
             {
-                return new DuplicateKeyMemoryHolder<K, V>( this, ( V ) value );
+                return new DuplicateKeyMemoryHolder<K, V>( this, value );
             }
             else
             {
                 // Atm, keep the values in memory
-                return new MemoryHolder<K, V>( this, ( V ) value );
+                return new MemoryHolder<K, V>( this, value );
             }
         }
         else
         {
-            if ( isAllowDuplicates() && !( value instanceof Page ) )
+            if ( isAllowDuplicates() )
             {
-                return new DuplicateKeyMemoryHolder<K, V>( this, ( V ) value );
+                return new DuplicateKeyMemoryHolder<K, V>( this, value );
             }
             else
             {
@@ -1665,6 +1657,26 @@ public class BTree<K, V>
 
 
     /**
+     * Create a ValueHolder depending on the kind of holder we want.
+     * 
+     * @param value The value to store
+     * @return The value holder
+     */
+    /* no qualifier */ElementHolder<Page<K, V>, K, V> createPageHolder( Page<K,
V> value )
+    {
+        if ( type == BTreeTypeEnum.MANAGED )
+        {
+            return new ReferenceHolder<Page<K, V>, K, V>( this, value,
+                value.getOffset(), value.getLastOffset() );
+        }
+        else
+        {
+            return new MemoryHolder( this, value );
+        }
+    }
+
+
+    /**
      * @return the keySerializer
      */
     public ElementSerializer<K> getKeySerializer()
@@ -1750,7 +1762,7 @@ public class BTree<K, V>
         btreeHeader.setAllowDuplicates( allowDuplicates );
     }
 
-    
+
     private void writeToJournal( Modification<K, V> modification )
         throws IOException
     {
@@ -1786,7 +1798,7 @@ public class BTree<K, V>
         journalChannel.force( true );
     }
 
-    
+
     /**
      * @see Object#toString()
      */

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java?rev=1513417&r1=1513416&r2=1513417&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java
Tue Aug 13 10:09:14 2013
@@ -61,6 +61,7 @@ public class BTreeBuilder<K, V>
     }
 
 
+    @SuppressWarnings("unchecked")
     public BTree<K, V> build( Iterator<Tuple<K, V>> sortedTupleItr ) throws
IOException
     {
         BTree<K, V> btree = new BTree<K, V>( name, keySerializer, valueSerializer
);
@@ -129,6 +130,7 @@ public class BTreeBuilder<K, V>
     }
 
 
+    @SuppressWarnings("unchecked")
     private Page<K, V> attachNodes( List<Page<K, V>> children, BTree<K,
V> btree ) throws IOException
     {
         if ( children.size() == 1 )
@@ -144,6 +146,7 @@ public class BTreeBuilder<K, V>
         lstNodes.add( node );
         int i = 0;
         int totalNodes = 0;
+
         for ( Page<K, V> p : children )
         {
             if ( i != 0 )
@@ -151,7 +154,7 @@ public class BTreeBuilder<K, V>
                 setKey( node, i - 1, p.getLeftMostKey() );
             }
 
-            node.children[i] = btree.createHolder( p );
+            node.children[i] = btree.createPageHolder( p );
 
             i++;
             totalNodes++;
@@ -166,6 +169,7 @@ public class BTreeBuilder<K, V>
 
         // remove null keys and values from the last node and resize
         AbstractPage<K, V> lastNode = ( AbstractPage<K, V> ) lstNodes.get( lstNodes.size()
- 1 );
+
         for ( int j = 0; j < lastNode.nbElems; j++ )
         {
             if ( lastNode.keys[j] == null )

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Leaf.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Leaf.java?rev=1513417&r1=1513416&r2=1513417&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Leaf.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Leaf.java
Tue Aug 13 10:09:14 2013
@@ -747,7 +747,7 @@ import org.apache.directory.mavibot.btre
         {
             // Now we can inject the value
             oldValue = newLeaf.values[pos].getValue( btree );
-            newLeaf.values[pos] = btree.createHolder( value );
+            newLeaf.values[pos] = btree.createValueHolder( value );
         }
 
         // Create the result
@@ -835,7 +835,7 @@ import org.apache.directory.mavibot.btre
         int middle = btree.getPageSize() >> 1;
         Leaf<K, V> leftLeaf = null;
         Leaf<K, V> rightLeaf = null;
-        ElementHolder<V, K, V> valueHolder = btree.createHolder( value );
+        ElementHolder<V, K, V> valueHolder = btree.createValueHolder( value );
 
         // Determinate where to store the new value
         if ( pos <= middle )

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Node.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Node.java?rev=1513417&r1=1513416&r2=1513417&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Node.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Node.java
Tue Aug 13 10:09:14 2013
@@ -91,8 +91,8 @@ import org.apache.directory.mavibot.btre
                 btree.getPageSize() + 1 );
         }
 
-        children[0] = btree.createHolder( leftPage );
-        children[1] = btree.createHolder( rightPage );
+        children[0] = btree.createPageHolder( leftPage );
+        children[1] = btree.createPageHolder( rightPage );
 
         // Create the keys array and store the pivot into it
         // We get the type of array to create from the btree
@@ -1037,7 +1037,7 @@ import org.apache.directory.mavibot.btre
         }
         else
         {
-            return btree.createHolder( page );
+            return btree.createPageHolder( page );
         }
     }
 

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTest.java?rev=1513417&r1=1513416&r2=1513417&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTest.java
(original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTest.java
Tue Aug 13 10:09:14 2013
@@ -1042,7 +1042,7 @@ public class InMemoryBTreeTest
         for ( Tuple<Integer, String> tuple : tuples )
         {
             leaf.keys[pos] = tuple.getKey();
-            leaf.values[pos] = btree.createHolder( tuple.getValue() );
+            leaf.values[pos] = btree.createValueHolder( tuple.getValue() );
             pos++;
         }
 
@@ -1060,7 +1060,7 @@ public class InMemoryBTreeTest
             node.keys[pos - 1] = leftmost.getKey();
         }
 
-        node.children[pos] = btree.createHolder( page );
+        node.children[pos] = btree.createPageHolder( page );
     }
 
 



Mime
View raw message