o added a flag(for internal testing use only) to disable free page reclaimer
authorKiran Ayyagari <kayyagari@apache.org>
Thu, 14 May 2015 10:06:37 +0000 (10:06 +0000)
committerKiran Ayyagari <kayyagari@apache.org>
Thu, 14 May 2015 10:06:37 +0000 (10:06 +0000)
o added a test for verifying the internal state of the RM (work in progress)

mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
mavibot/src/test/java/org/apache/directory/mavibot/btree/SpaceReclaimerTest.java

index 598d9eb..8640488 100644 (file)
@@ -219,6 +219,9 @@ public class RecordManager extends AbstractTransactionManager
     // FIXME the below value is derived after seeing that anything higher than that
     // is resulting in a "This thread does not hold the transactionLock" error
     private int spaceReclaimerThreshold = 70;
+    
+    /* a flag used to disable the free page reclaimer (used for internal testing only) */
+    private boolean disableReclaimer = false;
 
     public Map<Long, Integer> writeCounter = new HashMap<Long, Integer>();
 
@@ -307,6 +310,12 @@ public class RecordManager extends AbstractTransactionManager
      */
     private void runReclaimer()
     {
+        if ( disableReclaimer )
+        {
+            LOG.warn( "Free page reclaimer is disabled, this should not be disabled on production systems." );
+            return; 
+        }
+        
         try
         {
             commitCount = 0;
@@ -4072,11 +4081,15 @@ public class RecordManager extends AbstractTransactionManager
      * 
      * @param spaceReclaimerThreshold the number of commits before the reclaimer runs
      */
-    public void setSpaceReclaimerThreshold( int spaceReclaimerThreshold )
+    /* no qualifier */ void setSpaceReclaimerThreshold( int spaceReclaimerThreshold )
     {
         this.spaceReclaimerThreshold = spaceReclaimerThreshold;
     }
 
+    /* no qualifier */ void _disableReclaimer( boolean toggle )
+    {
+        this.disableReclaimer = toggle;
+    }
 
     /**
      * @see Object#toString()
index c812924..d07ad3c 100644 (file)
@@ -232,5 +232,33 @@ public class SpaceReclaimerTest
         \r
         assertEquals( count, total );\r
     }\r
-    \r
+\r
+    @Test\r
+    public void testInspectTreeState() throws Exception\r
+    {\r
+        File file = File.createTempFile( "freepagedump", ".db" );\r
+        RecordManager manager = new RecordManager( file.getAbsolutePath() );\r
+        manager._disableReclaimer( true );\r
+        \r
+        PersistedBTreeConfiguration config = new PersistedBTreeConfiguration();\r
+\r
+        config.setName( "dump-tree" );\r
+        config.setKeySerializer( IntSerializer.INSTANCE );\r
+        config.setValueSerializer( StringSerializer.INSTANCE );\r
+        config.setAllowDuplicates( false );\r
+        config.setPageSize( 4 );\r
+\r
+        BTree btree = new PersistedBTree( config );\r
+        manager.manage( btree );\r
+        \r
+        // insert 5 so that we get 1 root and 2 child nodes\r
+        for( int i=0; i<5; i++ )\r
+        {\r
+            btree.insert( i, String.valueOf( i ) );\r
+        }\r
+        \r
+        System.out.println(btree.getRootPage());\r
+        System.out.println( file.getAbsolutePath() );\r
+        manager.close();\r
+    }\r
 }\r