directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1541176 - /directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Leaf.java
Date Tue, 12 Nov 2013 17:39:06 GMT
Author: elecharny
Date: Tue Nov 12 17:39:06 2013
New Revision: 1541176

URL: http://svn.apache.org/r1541176
Log:
Fixed a bug in delete : when we remove a value in a ValueHodler having more than 1 value,
we have to copy the ValueHolder and delete the value in this copy. This was not what we were
doing, leading to some modified ValueHolder in the previous revision.

Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Leaf.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Leaf.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Leaf.java?rev=1541176&r1=1541175&r2=1541176&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Leaf.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/Leaf.java
Tue Nov 12 17:39:06 2013
@@ -168,7 +168,7 @@ import org.apache.directory.mavibot.btre
                 else
                 {
                     removedElement = new Tuple<K, V>( keys[index].getKey(), value );
// only one value was removed
-                    valueHolder.remove( value );
+                    //valueHolder.remove( value );
                 }
             }
             else
@@ -181,10 +181,12 @@ import org.apache.directory.mavibot.btre
 
         if ( keyRemoved )
         {
+            // No value, we can remove the key
             newLeaf = new Leaf<K, V>( btree, revision, nbElems - 1 );
         }
         else
         {
+            // Copy the page as we will delete a value from a ValueHolder
             newLeaf = new Leaf<K, V>( btree, revision, nbElems );
         }
 
@@ -194,8 +196,8 @@ import org.apache.directory.mavibot.btre
         // If the parent is null, then this page is the root page.
         if ( parent == null )
         {
-            // Just remove the entry if it's present
-            copyAfterRemovingElement( keyRemoved, newLeaf, index );
+            // Just remove the entry if it's present, or replace it if we have more than
one value in the ValueHolder
+            copyAfterRemovingElement( keyRemoved, value, newLeaf, index );
 
             // The current page is added in the copied page list
             defaultResult.addCopiedPage( this );
@@ -249,7 +251,7 @@ import org.apache.directory.mavibot.btre
                 // We simply remove the element from the page, and if it was the leftmost,
                 // we return the new pivot (it will replace any instance of the removed
                 // key in its parents)
-                copyAfterRemovingElement( keyRemoved, newLeaf, index );
+                copyAfterRemovingElement( true, value, newLeaf, index );
 
                 // The current page is added in the copied page list
                 defaultResult.addCopiedPage( this );
@@ -263,6 +265,20 @@ import org.apache.directory.mavibot.btre
             // Copy the keys and the values
             System.arraycopy( keys, 0, newLeaf.keys, 0, nbElems );
             System.arraycopy( values, 0, newLeaf.values, 0, nbElems );
+            
+            // Replace the ValueHolder now
+            try
+            {
+                ValueHolder<V> newValueHolder = (ValueHolder<V>)valueHolder.clone();
+                newValueHolder.remove( value );
+                
+                newLeaf.values[pos] = newValueHolder;
+            }
+            catch ( CloneNotSupportedException e )
+            {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
 
             // The current page is added in the copied page list
             defaultResult.addCopiedPage( this );
@@ -438,7 +454,7 @@ import org.apache.directory.mavibot.btre
      * @param pos The position into the page of the element to remove
      * @throws IOException If we have an error while trying to access the page
      */
-    private void copyAfterRemovingElement( boolean keyRemoved, Leaf<K, V> newLeaf,
int pos ) throws IOException
+    private void copyAfterRemovingElement( boolean keyRemoved, V removedValue, Leaf<K,
V> newLeaf, int pos ) throws IOException
     {
         if ( keyRemoved )
         {
@@ -462,6 +478,23 @@ import org.apache.directory.mavibot.btre
         {
             System.arraycopy( keys, 0, newLeaf.keys, 0, nbElems );
             System.arraycopy( values, 0, newLeaf.values, 0, nbElems );
+            
+            // We still have to clone the modified value holder
+            ValueHolder<V> valueHolder = newLeaf.values[pos];
+            
+            try
+            {
+                ValueHolder<V> newValueHolder = (ValueHolder<V>)valueHolder.clone();
+                
+                newValueHolder.remove( removedValue );
+                
+                newLeaf.values[pos] = newValueHolder;
+            }
+            catch ( CloneNotSupportedException e )
+            {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
         }
     }
 



Mime
View raw message