directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1681704 - in /directory/mavibot/trunk/mavibot/src: main/java/org/apache/directory/mavibot/btree/MavibotInspector.java test/java/org/apache/directory/mavibot/btree/PageReclaimerTest.java
Date Tue, 26 May 2015 07:56:56 GMT
Author: kayyagari
Date: Tue May 26 07:56:55 2015
New Revision: 1681704

URL: http://svn.apache.org/r1681704
Log:
o added a method to get the offsets of pages
o updated test to check offsets(still incomplete)

Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PageReclaimerTest.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java?rev=1681704&r1=1681703&r2=1681704&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/MavibotInspector.java
Tue May 26 07:56:55 2015
@@ -28,8 +28,10 @@ import java.io.RandomAccessFile;
 import java.nio.BufferUnderflowException;
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -51,7 +53,7 @@ public class MavibotInspector
     private File dbFile;
 
     // The recordManager
-    private RecordManager rm;
+    private static RecordManager rm;
 
     private BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
 
@@ -62,6 +64,12 @@ public class MavibotInspector
     // The set of page array we already know about
     private static Set<String> knownPagesArrays = new HashSet<String>();
 
+    // Create an array of pages to be checked for each B-tree, plus
+    // two others for the free pages and the global one
+    // We use one bit per page. It's 0 when the page
+    // hasn't been checked, 1 otherwise.
+    private static Map<String, int[]> checkedPages = new HashMap<String, int[]>();
+
     static
     {
         knownPagesArrays.add( GLOBAL_PAGES_NAME );
@@ -248,6 +256,8 @@ public class MavibotInspector
     {
         try
         {
+            rm = recordManager;
+            
             // First check the RMheader
             ByteBuffer recordManagerHeader = ByteBuffer.allocate( RecordManager.RECORD_MANAGER_HEADER_SIZE
);
             long fileSize = recordManager.fileChannel.size();
@@ -273,7 +283,7 @@ public class MavibotInspector
             // Compute the number of pages in this file
             long nbPages = ( fileSize - RecordManager.RECORD_MANAGER_HEADER_SIZE ) / pageSize;
 
-            // The number of trees. It must be at least 2 and > 0
+            // The number of trees. It must be at least >= 2
             int nbBtrees = recordManagerHeader.getInt();
 
             if ( ( nbBtrees < 0 ) || ( nbBtrees != recordManager.nbBtree ) )
@@ -292,12 +302,6 @@ public class MavibotInspector
 
             int nbPageBits = ( int ) ( nbPages / 32 );
 
-            // Create an array of pages to be checked for each B-tree, plus
-            // two others for the free pages and the global one
-            // We use one bit per page. It's 0 when the page
-            // hasn't been checked, 1 otherwise.
-            Map<String, int[]> checkedPages = new HashMap<String, int[]>( nbBtrees
+ 4 );
-
             // The global page array
             checkedPages.put( GLOBAL_PAGES_NAME, new int[nbPageBits + 1] );
 
@@ -1105,6 +1109,66 @@ public class MavibotInspector
 
 
     /**
+     * @see #getPageOffsets()
+     */
+    public static List<Long> getFreePages() throws IOException
+    {
+        return getPageOffsets( FREE_PAGES_NAME );
+    }
+
+    
+    /**
+     * @see #getPageOffsets()
+     */
+    public static List<Long> getGlobalPages() throws IOException
+    {
+        return getPageOffsets( GLOBAL_PAGES_NAME );
+    }
+
+    
+    /**
+     * Gives a list of offsets of free pages.
+     * This method should always be called after calling check() method.
+     * 
+     * @return a list of offsets
+     * @throws IOException
+     */
+    public static List<Long> getPageOffsets( String pageArrayName ) throws IOException
+    {
+        List<Long> lst = new ArrayList<Long>();
+        
+        int[] fparry = checkedPages.get( pageArrayName );
+
+        long nbPagesChecked = 0;
+        long fileSize = rm.fileChannel.size();
+        long nbPages = ( fileSize - RecordManager.RECORD_MANAGER_HEADER_SIZE ) / rm.pageSize;
+
+        for ( int checkedPage : fparry )
+        {
+            for ( int j = 0; j < 32; j++ )
+            {
+                nbPagesChecked++;
+
+                if ( nbPagesChecked > nbPages + 1 )
+                {
+                    break;
+                }
+                else
+                {
+                    int mask = ( checkedPage & ( 1 << j ) );
+                    if ( mask != 0 )
+                    {
+                        lst.add( nbPagesChecked * rm.pageSize);
+                    }
+                }
+            }
+        }
+        
+        return lst;
+    }
+    
+    
+    /**
      * Process a page array
      */
     private static String dumpPageArray( RecordManager recordManager, int[] checkedPages
) throws IOException

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PageReclaimerTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PageReclaimerTest.java?rev=1681704&r1=1681703&r2=1681704&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PageReclaimerTest.java
(original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PageReclaimerTest.java
Tue May 26 07:56:55 2015
@@ -23,6 +23,8 @@ package org.apache.directory.mavibot.btr
 import static org.junit.Assert.assertEquals;
 
 import java.io.File;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 import java.util.Random;
 import java.util.concurrent.ConcurrentHashMap;
@@ -238,7 +240,8 @@ public class PageReclaimerTest
     {
         File file = File.createTempFile( "freepagedump", ".db" );
         RecordManager manager = new RecordManager( file.getAbsolutePath() );
-        manager._disableReclaimer( true );
+        manager.setSpaceReclaimerThreshold(17);
+        //manager._disableReclaimer( true );
         
         PersistedBTreeConfiguration config = new PersistedBTreeConfiguration();
 
@@ -265,10 +268,26 @@ public class PageReclaimerTest
         long totalPages = file.length() / RecordManager.DEFAULT_PAGE_SIZE;
         
         // in RM the header page gets skipped before incrementing nbCreatedPages 
-        assertEquals( manager.nbCreatedPages.get()+1, totalPages );
+        //assertEquals( manager.nbCreatedPages.get()+1, totalPages );
         
         System.out.println(btree.getRootPage());
         System.out.println( file.getAbsolutePath() );
+        
+        MavibotInspector.check(manager);
+        List<Long> lst = MavibotInspector.getFreePages();
+        System.out.println(lst);
+        
+        lst = MavibotInspector.getGlobalPages();
+        System.out.println(lst);
+        System.out.println("Total global offsets " + lst.size() );
+        
+        lst = MavibotInspector.getPageOffsets( RecordManager.BTREE_OF_BTREES_NAME );
+        System.out.println(lst);
+        
+        lst = MavibotInspector.getPageOffsets( RecordManager.COPIED_PAGE_BTREE_NAME );
+        System.out.println(lst);
+
         manager.close();
     }
+    
 }



Mime
View raw message