directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1540822 - in /directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed: BTree.java RecordManager.java
Date Mon, 11 Nov 2013 19:53:36 GMT
Author: elecharny
Date: Mon Nov 11 19:53:35 2013
New Revision: 1540822

URL: http://svn.apache.org/r1540822
Log:
o Fixed a bug in the way we were serializing keys in pages
o Added a way to inject a different cache size

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

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTree.java?rev=1540822&r1=1540821&r2=1540822&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTree.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTree.java
Mon Nov 11 19:53:35 2013
@@ -278,6 +278,14 @@ public class BTree<K, V> implements Clos
     }
 
 
+    public BTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V>
valueSerializer,
+        boolean allowDuplicates, int cacheSize )
+        throws IOException
+    {
+        this( name, null, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE, allowDuplicates,
cacheSize );
+    }
+
+
     /**
      * Creates a new in-memory BTree with a default page size and key/value serializers.
      * 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java?rev=1540822&r1=1540821&r2=1540822&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java
Mon Nov 11 19:53:35 2013
@@ -710,7 +710,17 @@ public class RecordManager
             PageHolder<K, V> valueHolder = new PageHolder<K, V>( btree, null,
offset, lastOffset );
             node.setValue( i, valueHolder );
 
+            // Read the key length
+            int keyLength = byteBuffer.getInt();
+            
+            int currentPosition = byteBuffer.position();
+            
+            // and the key value
             K key = btree.getKeySerializer().deserialize( byteBuffer );
+            
+            // Set the new position now
+            byteBuffer.position( currentPosition + keyLength );
+            
             BTreeFactory.setKey( node, i, key );
         }
 
@@ -1162,7 +1172,7 @@ public class RecordManager
         else
         {
             // Prepare a list of byte[] that will contain the serialized page
-            int nbBuffers = 1 + 1 + 1 + nbElems * 2;
+            int nbBuffers = 1 + 1 + 1 + nbElems * 3;
             int dataSize = 0;
             int serializedSize = 0;
 
@@ -1247,9 +1257,15 @@ public class RecordManager
     {
         KeyHolder<K> holder = node.getKeyHolder( pos );
         byte[] buffer = holder.getBuffer();
+        
+        // We have to store the serialized key length
+        byte[] length = IntSerializer.serialize( buffer.length );
+        serializedData.add( length );
+
+        // And store the serialized key now
         serializedData.add( buffer );
 
-        return buffer.length;
+        return buffer.length + 4;
     }
 
 
@@ -1287,16 +1303,13 @@ public class RecordManager
 
         if ( keyData != null )
         {
-            byte[] data = new byte[keyData.length];
+            // We have to store the serialized key length
+            byte[] length = IntSerializer.serialize( keyData.length );
+            serializedData.add( length );
 
-            // The key length
-            byte[] buffer = IntSerializer.serialize( data.length );
-            serializedData.add( buffer );
-            dataSize += buffer.length;
-
-            // The key data
+            // And the key data
             serializedData.add( keyData );
-            dataSize += data.length;
+            dataSize += keyData.length + 4;
         }
         else
         {



Mime
View raw message