You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2015/05/12 08:20:00 UTC
svn commit: r1678872 - in /directory/mavibot/trunk/mavibot/src:
main/java/org/apache/directory/mavibot/btree/SpaceReclaimer.java
test/java/org/apache/directory/mavibot/btree/SpaceReclaimerTest.java
Author: kayyagari
Date: Tue May 12 06:20:00 2015
New Revision: 1678872
URL: http://svn.apache.org/r1678872
Log:
o run reclaimer in a transaction
o added a test which demonstrates a failed page reclaiming operation when not run inside a transaction
o removed useless imports
o added a flag to skip running reclaimer when a reclaiming operation is in progress
Modified:
directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/SpaceReclaimer.java
directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/SpaceReclaimerTest.java
Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/SpaceReclaimer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/SpaceReclaimer.java?rev=1678872&r1=1678871&r2=1678872&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/SpaceReclaimer.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/SpaceReclaimer.java Tue May 12 06:20:00 2015
@@ -20,21 +20,11 @@
package org.apache.directory.mavibot.btree;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
-import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,11 +40,12 @@ public class SpaceReclaimer
/** the record manager */
private RecordManager rm;
- private static String COPIED_PAGE_MAP_DATA_FILE = "cpm.db";
-
/** The LoggerFactory used by this class */
protected static final Logger LOG = LoggerFactory.getLogger( SpaceReclaimer.class );
+ /** a flag to detect the running state */
+ private boolean running = false;
+
/**
* Creates a new instance of SpaceReclaimer.
*
@@ -74,6 +65,15 @@ public class SpaceReclaimer
//System.out.println( "reclaiming pages" );
try
{
+ if ( running )
+ {
+ return;
+ }
+
+ running = true;
+
+ rm.beginTransaction();
+
Set<String> managed = rm.getManagedTrees();
for ( String name : managed )
@@ -81,7 +81,7 @@ public class SpaceReclaimer
PersistedBTree tree = ( PersistedBTree ) rm.getManagedTree( name );
Set<Long> inUseRevisions = new TreeSet<Long>();
-
+
// the tree might have been removed
if ( tree != null )
{
@@ -110,12 +110,18 @@ public class SpaceReclaimer
rm.free( offsets );
RevisionName key = new RevisionName( rv, name );
+
rm.copiedPageBtree.delete( key );
}
}
+
+ running = false;
+ rm.commit();
}
catch ( Exception e )
{
+ running = false;
+ rm.rollback();
LOG.warn( "Errors while reclaiming", e );
throw new RuntimeException( e );
}
@@ -146,6 +152,8 @@ public class SpaceReclaimer
}
}
+ cursor.close();
+
return lst;
}
}
Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/SpaceReclaimerTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/SpaceReclaimerTest.java?rev=1678872&r1=1678871&r2=1678872&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/SpaceReclaimerTest.java (original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/SpaceReclaimerTest.java Tue May 12 06:20:00 2015
@@ -110,4 +110,41 @@ public class SpaceReclaimerTest
assertEquals( count, total );
}
+
+
+ /**
+ * with the reclaimer threshold 10 and total entries of 1120
+ * there was a condition that resulted in OOM while reopening the RM
+ *
+ * This issue was fixed after SpaceReclaimer was updated to run in
+ * a transaction.
+ *
+ * This test is present to verify the fix
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testReclaimerWithMagicNum() throws Exception
+ {
+ rm.setSpaceReclaimerThreshold( 10 );
+
+ int total = 1120;
+ for ( int i=0; i < total; i++ )
+ {
+ uidTree.insert( i, String.valueOf( i ) );
+ }
+
+ closeAndReopenRM();
+
+ int count = 0;
+ TupleCursor<Integer, String> cursor = uidTree.browse();
+ while ( cursor.hasNext() )
+ {
+ Tuple<Integer, String> t = cursor.next();
+ assertEquals( t.key, Integer.valueOf( count ) );
+ count++;
+ }
+
+ assertEquals( count, total );
+ }
}