directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1592304 - in /directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree: MavibotInspector.java RecordManager.java
Date Sun, 04 May 2014 00:55:42 GMT
Author: elecharny
Date: Sun May  4 00:55:42 2014
New Revision: 1592304

URL: http://svn.apache.org/r1592304
Log:
o Added some more methods to check the btrees. We now have a dedicated method for the BOB
and CPB checks (not yet finished).
o Added a helper method to update the checkedPges
o the checkBtrees is not called, as it's buggy.

More to come...

Modified:
    directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
    directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java

Modified: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java?rev=1592304&r1=1592303&r2=1592304&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
(original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
Sun May  4 00:55:42 2014
@@ -227,7 +227,7 @@ public class MavibotInspector
 
             checkOffset( recordManager, firstFreePage, pageSize );
 
-            int nbPageBits = ( int ) ( nbPages / RecordManager.INT_SIZE );
+            int nbPageBits = ( int ) ( nbPages / 32 );
 
             // Create an array of pages to be checked
             // We use one bit per page. It's 0 when the page
@@ -263,8 +263,17 @@ public class MavibotInspector
             // Check that the current CPB offset is valid
             checkOffset( recordManager, currentCopiedPagesBtreeOffset, pageSize );
 
+            // Now, check the BTree of Btrees
+            BTree<NameRevision, Long> btreeOfBtrees = BTreeFactory.<NameRevision,
Long> createInMemoryBTree();
+            checkBtreeOfBtrees( recordManager, checkedPages, pageSize, btreeOfBtrees );
+
+            // And the Copied Pages BTree
+            checkCopiedPagesBtree( recordManager, checkedPages, pageSize );
+
             // The B-trees
-            checkBtrees( recordManager, checkedPages, pageSize, nbBtrees );
+            //checkBtrees( recordManager, checkedPages, pageSize, nbBtrees );
+            
+            dumpCheckedPages( recordManager, checkedPages );
         }
         catch ( Exception e )
         {
@@ -275,6 +284,82 @@ public class MavibotInspector
         }
     }
 
+    
+    /**
+     * Check the Btree of Btrees
+     *
+     * @param checkedPages
+     * @param pageSize
+     * @throws IOException
+     * @throws EndOfFileExceededException
+     * @throws NoSuchFieldException
+     * @throws SecurityException
+     * @throws IllegalArgumentException
+     * @throws InstantiationException
+     * @throws IllegalAccessException
+     * @throws ClassNotFoundException
+     */
+    private static <K, V> void checkBtreeOfBtrees( RecordManager recordManager, int[]
checkedPages, int pageSize, BTree<K, V> btree ) throws EndOfFileExceededException, IOException,
ClassNotFoundException, IllegalAccessException, InstantiationException, IllegalArgumentException,
SecurityException, NoSuchFieldException
+    {
+        // Read the BOB header
+        PageIO[] bobHeaderPageIos = recordManager.readPageIOs( recordManager.currentBtreeOfBtreesOffset,
Long.MAX_VALUE );
+
+        // update the checkedPages
+        updateCheckedPages( checkedPages, pageSize, bobHeaderPageIos );
+
+        //checkBtree( checkedPages, pageSize, bobHeaderPageIos, btree );
+    }
+
+    
+    /**
+     * Check the Copied pages Btree
+     *
+     * @param checkedPages
+     * @param pageSize
+     * @throws IOException 
+     * @throws EndOfFileExceededException 
+     */
+    private static void checkCopiedPagesBtree( RecordManager recordManager, int[] checkedPages,
int pageSize ) throws EndOfFileExceededException, IOException
+    {
+        // Read the CPB header
+        PageIO[] cpbHeaderPageIos = recordManager.readPageIOs( recordManager.currentCopiedPagesBtreeOffset,
Long.MAX_VALUE );
+
+        // update the checkedPages
+        updateCheckedPages( checkedPages, pageSize, cpbHeaderPageIos );
+
+        //checkBtree( checkedPages, pageSize, bobHeaderPageIos, btree );
+    }
+
+
+    /**
+     * Update the array of seen pages.
+     */
+    private static void updateCheckedPages( int[] checkedPages, int pageSize, PageIO... pageIos
)
+    {
+        for ( PageIO pageIO : pageIos )
+        {
+            long offset = pageIO.getOffset();
+
+            if ( ( offset % pageSize ) != 0 )
+            {
+                throw new InvalidBTreeException( "Offset invalid : " + offset );
+            }
+
+            int pageNumber = (int)(offset / pageSize);
+            int nbBitsPage = ( RecordManager.INT_SIZE << 3 );
+            int pageMask = checkedPages[ pageNumber / nbBitsPage ];
+            int mask = 1 << pageNumber % nbBitsPage;
+
+            if ( ( pageMask & mask ) != 0 )
+            {
+                throw new InvalidBTreeException( "The page " + offset + " has already been
referenced" );
+            }
+
+            pageMask |= mask;
+            checkedPages[ pageNumber / nbBitsPage ] = pageMask;
+        }
+    }
+
 
     /**
      * Check the offset to be sure it's a valid one :

Modified: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java?rev=1592304&r1=1592303&r2=1592304&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
(original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
Sun May  4 00:55:42 2014
@@ -172,13 +172,13 @@ public class RecordManager extends Abstr
     private static final String COPIED_PAGE_BTREE_NAME = "_copiedPageBtree_";
 
     /** The current B-tree of B-trees header offset */
-    private long currentBtreeOfBtreesOffset;
+    /* no qualifier */ long currentBtreeOfBtreesOffset;
 
     /** The previous B-tree of B-trees header offset */
     private long previousBtreeOfBtreesOffset = NO_PAGE;
 
     /** The offset on the current copied pages B-tree */
-    private long currentCopiedPagesBtreeOffset = NO_PAGE;
+    /* no qualifier */ long currentCopiedPagesBtreeOffset = NO_PAGE;
 
     /** The offset on the previous copied pages B-tree */
     private long previousCopiedPagesBtreeOffset = NO_PAGE;



Mime
View raw message