directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1546354 - in /directory/mavibot/trunk/mavibot/src: main/java/org/apache/directory/mavibot/btree/managed/ test/java/org/apache/directory/mavibot/btree/managed/
Date Thu, 28 Nov 2013 12:12:50 GMT
Author: elecharny
Date: Thu Nov 28 12:12:50 2013
New Revision: 1546354

URL: http://svn.apache.org/r1546354
Log:
o Added a dump(PageIO) method for debug purpose
o Fixed a bad comparison that made the conversion of an array to a subbtree too early, and
resulted in a deserialization of an array to a subbtree.

Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/managed/RecordManagerTest.java

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=1546354&r1=1546353&r2=1546354&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
Thu Nov 28 12:12:50 2013
@@ -1510,6 +1510,14 @@ public class RecordManager
      */
     private void flushPages( PageIO... pageIos ) throws IOException
     {
+        if ( LOG.isDebugEnabled() )
+        {
+            for ( PageIO pageIo : pageIos )
+            {
+                dump( pageIo );
+            }
+        }
+
         for ( PageIO pageIo : pageIos )
         {
             pageIo.getData().rewind();
@@ -1899,9 +1907,9 @@ public class RecordManager
     {
         // We first need to save the new page on disk
         PageIO[] pageIos = serializePage( btree, newRevision, newPage );
-
+        
         LOG.debug( "Write data for '{}' btree ", btree.getName() );
-
+        
         // Write the page on disk
         flushPages( pageIos );
 
@@ -2127,6 +2135,68 @@ public class RecordManager
         // And close the channel
         fileChannel.close();
     }
+    
+    
+    /** Hex chars */
+    private static final byte[] HEX_CHAR = new byte[]
+        { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
+
+    
+    public static String dump( byte octet )
+    {
+        return new String( new byte[]
+            { HEX_CHAR[( octet & 0x00F0 ) >> 4], HEX_CHAR[octet & 0x000F] }
);
+    }
+
+    /**
+     * Dump a pageIO
+     */
+    private void dump( PageIO pageIo )
+    {
+        ByteBuffer buffer = pageIo.getData();
+        buffer.mark();
+        byte[] longBuffer = new byte[LONG_SIZE];
+        byte[] intBuffer = new byte[INT_SIZE]; 
+        
+        // get the next page offset
+        buffer.get( longBuffer );
+        long nextOffset = LongSerializer.deserialize( longBuffer );
+        
+        // Get the data size 
+        buffer.get( intBuffer );
+        int size = IntSerializer.deserialize( intBuffer );
+        
+        buffer.reset();
+        
+        System.out.println( "PageIO[" + Long.toHexString( pageIo.getOffset() ) + "], size
= " + size + ", NEXT PageIO:" + Long.toHexString( nextOffset ) );
+        System.out.println( " 0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F " );
+        System.out.println( "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" );
+        
+        int position = buffer.position();
+        
+        for ( int i = 0; i < buffer.limit(); i+= 16 )
+        {
+            System.out.print( "|" );
+            
+            for ( int j = 0; j < 16; j++ )
+            {
+                System.out.print( dump( buffer.get() ) );
+                
+                if ( j == 15 )
+                {
+                    System.out.println( "|" );
+                }
+                else
+                {
+                    System.out.print( " " );
+                }
+            }
+        }
+        
+        System.out.println( "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" );
+
+        buffer.reset();
+    }
 
 
     /**

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java?rev=1546354&r1=1546353&r2=1546354&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java
Thu Nov 28 12:12:50 2013
@@ -82,7 +82,7 @@ public class ValueHolder<V> implements C
 
         // We create the array of values if they fit in an array. If they are stored in a

         // BTree, we do nothing atm.
-        if ( nbValues < BTree.valueThresholdUp )
+        if ( nbValues <= BTree.valueThresholdUp )
         {
             // The values are contained into an array
             valueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), nbValues );
@@ -669,7 +669,7 @@ public class ValueHolder<V> implements C
         checkAndDeserialize();
 
         // We have to check that we have reached the threshold or not
-        if ( valueArray.length + 1 > BTree.valueThresholdUp )
+        if ( valueArray.length >= BTree.valueThresholdUp )
         {
             // Ok, transform the array into a btree
             createSubTree();

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/managed/RecordManagerTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/managed/RecordManagerTest.java?rev=1546354&r1=1546353&r2=1546354&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/managed/RecordManagerTest.java
(original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/managed/RecordManagerTest.java
Thu Nov 28 12:12:50 2013
@@ -822,25 +822,25 @@ public class RecordManagerTest
      * Test with BTrees containing duplicate keys
      */
     @Test
-    @Ignore
     public void testBTreesDuplicateKeys() throws IOException, BTreeAlreadyManagedException,
         KeyNotFoundException
     {
         int pageSize = 16;
-        int numKeys = 2;
+        int numKeys = 1;
         String name = "duplicateTree";
+        String[] testValues = new String[]{ "00", "01", "02", "03", "04", "05", "06", "07",
"08", "09", "0A", "0B", "0C", "0D", "0E", "0F", "10" };
 
         BTree<Long, String> dupsTree = new BTree<Long, String>( name, null, new
LongSerializer(),
             new StringSerializer(), pageSize,
             true );
 
         recordManager1.manage( dupsTree );
-
+        
         for ( long i = 0; i < numKeys; i++ )
         {
             for ( int k = 0; k < pageSize + 1; k++ )
             {
-                dupsTree.insert( i, String.valueOf( k ) );
+                dupsTree.insert( i, testValues[ k ] );
             }
         }
 
@@ -855,7 +855,7 @@ public class RecordManagerTest
 
             for ( int k = 0; k < pageSize + 1; k++ )
             {
-                assertTrue( values.next().equals( String.valueOf( k ) ) );
+                assertTrue( values.next().equals( testValues[ k ] ) );
             }
         }
     }



Mime
View raw message