directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1603909 - in /directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree: PersistedBTree.java PersistedPageHolder.java
Date Thu, 19 Jun 2014 14:59:23 GMT
Author: kayyagari
Date: Thu Jun 19 14:59:23 2014
New Revision: 1603909

URL: http://svn.apache.org/r1603909
Log:
o replaced ehcache's Cache with LRUMap
o updated PersistedPageHolder constructor to NOT to hold a reference to the Page (this will
be reloaded or will be fetched from cache
  this fix helps in avoiding OOM issues during bulkload)

Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedPageHolder.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java?rev=1603909&r1=1603908&r2=1603909&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
Thu Jun 19 14:59:23 2014
@@ -30,6 +30,7 @@ import net.sf.ehcache.Cache;
 import net.sf.ehcache.Status;
 import net.sf.ehcache.config.CacheConfiguration;
 
+import org.apache.commons.collections.map.LRUMap;
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,7 +52,7 @@ public class PersistedBTree<K, V> extend
     protected static final Logger LOG_PAGES = LoggerFactory.getLogger( "org.apache.directory.mavibot.LOG_PAGES"
);
 
     /** The cache associated with this B-tree */
-    protected Cache cache;
+    protected LRUMap cache;
 
     /** The default number of pages to keep in memory */
     public static final int DEFAULT_CACHE_SIZE = 1000;
@@ -173,8 +174,12 @@ public class PersistedBTree<K, V> extend
             cacheConfiguration.setMaxElementsInMemory( cacheSize );
             cacheConfiguration.setMemoryStoreEvictionPolicy( "LRU" );
 
-            cache = new Cache( cacheConfiguration );
-            cache.initialise();
+            if ( cacheSize < 1 )
+            {
+                cacheSize = 1;
+            }
+            
+            cache = new LRUMap( cacheSize );
         }
         else
         {
@@ -191,7 +196,7 @@ public class PersistedBTree<K, V> extend
     /**
      * Return the cache we use in this BTree
      */
-    /* No qualifier */Cache getCache()
+    /* No qualifier */LRUMap getCache()
     {
         return cache;
     }
@@ -216,12 +221,7 @@ public class PersistedBTree<K, V> extend
         // readTransactions.clear();
 
         // Clean the cache
-        if ( cache.getStatus() == Status.STATUS_ALIVE )
-        {
-            cache.removeAll();
-        }
-
-        cache.dispose();
+        cache.clear();
     }
 
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedPageHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedPageHolder.java?rev=1603909&r1=1603908&r2=1603909&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedPageHolder.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedPageHolder.java
Thu Jun 19 14:59:23 2014
@@ -22,9 +22,9 @@ package org.apache.directory.mavibot.btr
 
 import java.io.IOException;
 
-import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
 
+import org.apache.commons.collections.map.LRUMap;
 import org.apache.directory.mavibot.btree.exception.BTreeOperationException;
 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
 
@@ -46,7 +46,7 @@ import org.apache.directory.mavibot.btre
     private RecordManager recordManager;
 
     /** The cache */
-    private Cache cache;
+    private LRUMap cache;
 
     /** The offset of the first {@link PageIO} storing the page on disk */
     private long offset;
@@ -62,7 +62,8 @@ import org.apache.directory.mavibot.btre
      */
     public PersistedPageHolder( BTree<K, V> btree, Page<K, V> page )
     {
-        super( btree, page );
+        // DO NOT keep the reference to Page, it will be fetched from cache when needed 
+        super( btree, null );
         cache = ( ( PersistedBTree<K, V> ) btree ).getCache();
         recordManager = ( ( PersistedBTree<K, V> ) btree ).getRecordManager();
         offset = ( ( AbstractPage<K, V> ) page ).getOffset();
@@ -71,7 +72,7 @@ import org.apache.directory.mavibot.btre
         ( ( AbstractPage<K, V> ) page ).setOffset( offset );
         ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset );
 
-        cache.put( new Element( offset, page ) );
+        cache.put( offset, page );
     }
 
 
@@ -82,7 +83,8 @@ import org.apache.directory.mavibot.btre
      */
     public PersistedPageHolder( BTree<K, V> btree, Page<K, V> page, long offset,
long lastOffset )
     {
-        super( btree, page );
+        // DO NOT keep the reference to Page, it will be fetched from cache when needed
+        super( btree, null );
         cache = ( ( PersistedBTree<K, V> ) btree ).getCache();
         recordManager = ( ( PersistedBTree<K, V> ) btree ).getRecordManager();
         this.offset = offset;
@@ -94,7 +96,7 @@ import org.apache.directory.mavibot.btre
             ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset );
         }
 
-        cache.put( new Element( offset, page ) );
+        cache.put( offset, page );
     }
 
 
@@ -105,20 +107,7 @@ import org.apache.directory.mavibot.btre
      */
     public Page<K, V> getValue()
     {
-        Element element = cache.get( offset );
-
-        if ( element == null )
-        {
-            // We haven't found the element in the cache, reload it
-            // We have to fetch the element from disk, using the offset now
-            Page<K, V> page = fetchElement();
-
-            cache.put( new Element( offset, page ) );
-
-            return page;
-        }
-
-        Page<K, V> page = ( Page<K, V> ) element.getObjectValue();
+        Page<K, V> page = ( Page<K, V> ) cache.get( offset );
 
         if ( page == null )
         {
@@ -128,7 +117,7 @@ import org.apache.directory.mavibot.btre
             ( ( AbstractPage<K, V> ) page ).setOffset( offset );
             ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset );
 
-            cache.put( new Element( offset, page ) );
+            cache.put( offset, page );
         }
 
         return page;



Mime
View raw message