You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2014/03/29 10:29:55 UTC

svn commit: r1582969 - in /directory/mavibot/branches/with-txns/mavibot/src: main/java/org/apache/directory/mavibot/btree/ test/java/org/apache/directory/mavibot/btree/

Author: elecharny
Date: Sat Mar 29 09:29:54 2014
New Revision: 1582969

URL: http://svn.apache.org/r1582969
Log:
o Fixed a bug in dups value handling : we weren't storing the new btreeHeader of sub-b-trees when we add a new value
o Fixed a bug in the nextKey() method
o Added a test (ignored atm)

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/TupleCursor.java
    directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.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=1582969&r1=1582968&r2=1582969&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 Sat Mar 29 09:29:54 2014
@@ -594,6 +594,19 @@ public class PersistedBTree<K, V> extend
 
                 break;
 
+            case PERSISTED_SUB :
+                // Sub-B-trees are only updating the CopiedPage B-tree
+                recordManager.addInCopiedPagesBtree( getName(), revision, result.getCopiedPages() );
+                
+                //btreeRevisions.clear();
+                
+                btreeRevisions.put( revision, newBtreeHeader );
+
+                currentRevision.set( revision );
+
+
+                break;
+
             case BTREE_OF_BTREES :
                 // The B-tree of B-trees or the copiedPages B-tree has been updated, update the RMheader parameters
                 recordManager.updateRecordManagerHeader( newBtreeHeaderOffset, -1L );

Modified: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/TupleCursor.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/TupleCursor.java?rev=1582969&r1=1582968&r2=1582969&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/TupleCursor.java (original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/TupleCursor.java Sat Mar 29 09:29:54 2014
@@ -701,15 +701,20 @@ public class TupleCursor<K, V>
             return false;
         }
 
-        if ( parentPos.pos == 0 )
+        switch ( parentPos.pos )
         {
-            // Beginning of the leaf. We have to go back into the stack up to the
-            // parent, and down to the leaf
-            return hasPrevParentPos();
-        }
-        else
-        {
-            return true;
+            case 0 :
+                // Beginning of the leaf. We have to go back into the stack up to the
+                // parent, and down to the leaf
+                return hasPrevParentPos();
+                
+            case -1 :
+                // no previous key
+                return false;
+                
+            default :
+                // we have a previous key
+                return true;
         }
     }
 

Modified: directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java?rev=1582969&r1=1582968&r2=1582969&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java (original)
+++ directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java Sat Mar 29 09:29:54 2014
@@ -38,6 +38,7 @@ import org.apache.directory.mavibot.btre
 import org.apache.directory.mavibot.btree.serializer.StringSerializer;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -801,7 +802,7 @@ public class PersistedBTreeBrowseTest
             // Expected
         }
 
-        assertEquals( -1L, cursor.getRevision() );
+        assertEquals( 0L, cursor.getRevision() );
     }
 
 
@@ -979,6 +980,56 @@ public class PersistedBTreeBrowseTest
         }
     }
 
+    
+    /**
+     * Test the TupleCursor.nextKey method on a btree containing nodes
+     * with duplicate values.
+     */
+   @Test
+   @Ignore
+   public void testNextKeyDups() throws IOException, BTreeAlreadyManagedException
+   {
+       // Inject some data
+       //for ( long i = 1; i < 3; i++ )
+       {
+           for ( long j = 1; j < 9; j++ )
+           {
+               btree.insert( 1L, Long.toString( j ) );
+           }
+       }
+
+       btree.insert( 1L, "10" );
+
+       // Create the cursor
+       TupleCursor<Long, String> cursor = btree.browse();
+
+       // Move forward
+       cursor.beforeFirst();
+
+       assertFalse( cursor.hasPrevKey() );
+       assertTrue( cursor.hasNextKey() );
+
+       Tuple<Long, String> tuple = cursor.nextKey();
+
+       checkTuple( tuple, 1L, "1" );
+       
+       cursor.beforeFirst();
+       long val = 1L;
+       
+       while ( cursor.hasNext() )
+       {
+           tuple = cursor.next();
+           
+           assertEquals( Long.valueOf( 1L ), tuple.getKey() );
+           assertEquals( Long.toString( val ), tuple.getValue() );
+           
+           val++;
+       }
+       
+       assertFalse( cursor.hasNextKey() );
+       assertFalse( cursor.hasPrevKey() );
+   }
+
 
     /**
      * Test the TupleCursor.moveToPrevNonDuplicateKey method on a btree containing nodes