jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1526205 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: cache/ plugins/segment/ plugins/segment/file/ plugins/segment/mongo/
Date Wed, 25 Sep 2013 15:23:16 GMT
Author: thomasm
Date: Wed Sep 25 15:23:15 2013
New Revision: 1526205

URL: http://svn.apache.org/r1526205
Log:
OAK-1042 Segment node store caching (LIRS cache for segments; disabled)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/CacheLIRS.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/CacheStats.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentCache.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/CacheLIRS.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/CacheLIRS.java?rev=1526205&r1=1526204&r2=1526205&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/CacheLIRS.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/CacheLIRS.java
Wed Sep 25 15:23:15 2013
@@ -1093,6 +1093,7 @@ public class CacheLIRS<K, V> implements 
         
         private Weigher<?, ?> weigher;
         private long maxWeight;
+        private int averageWeight = 100;
 
         public Builder recordStats() {
             return this;
@@ -1108,10 +1109,16 @@ public class CacheLIRS<K, V> implements 
             return this;
         }
 
-        public <K, V> Cache<K, V> build() {
+        public <K, V> CacheLIRS<K, V> build() {
             @SuppressWarnings("unchecked")
             Weigher<K, V> w = (Weigher<K, V>) weigher;
-            return new CacheLIRS<K, V>(w, maxWeight, 100, 16, 16);
+            return new CacheLIRS<K, V>(w, maxWeight, averageWeight, 16, 16);
+        }
+
+        public Builder maximumSize(int maxSize) {
+            this.maxWeight = maxSize;
+            this.averageWeight = 1;
+            return this;
         }
         
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/CacheStats.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/CacheStats.java?rev=1526205&r1=1526204&r2=1526205&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/CacheStats.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/CacheStats.java
Wed Sep 25 15:23:15 2013
@@ -18,8 +18,6 @@
  */
 package org.apache.jackrabbit.oak.cache;
 
-import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
@@ -168,14 +166,13 @@ public class CacheStats implements Cache
         return cache.stats().minus(lastSnapshot);
     }
 
-    private static String timeInWords(long nanos){
+    private static String timeInWords(long nanos) {
         long millis = TimeUnit.NANOSECONDS.toMillis(nanos);
         return String.format("%d min, %d sec",
                 TimeUnit.MILLISECONDS.toMinutes(millis),
                 TimeUnit.MILLISECONDS.toSeconds(millis) -
                         TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))
         );
-        //return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(millis));
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentCache.java?rev=1526205&r1=1526204&r2=1526205&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentCache.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentCache.java
Wed Sep 25 15:23:15 2013
@@ -25,6 +25,9 @@ import java.util.Map.Entry;
 import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+
+import org.apache.jackrabbit.oak.cache.CacheLIRS;
 
 /**
  * Memory cache for segments.
@@ -33,9 +36,9 @@ public class SegmentCache {
 
     private static final int DEFAULT_MEMORY_CACHE_SIZE = 1 << 28; // 256MB
 
-    private final int maximumSize;
-
-    private int currentSize = 0;
+    protected final int maximumSize;
+    
+    protected int currentSize;
 
     private final Map<UUID, Segment> segments =
         new LinkedHashMap<UUID, Segment>(1000, 0.75f, true) {
@@ -52,12 +55,19 @@ public class SegmentCache {
 
     private final Set<UUID> currentlyLoading = new HashSet<UUID>();
 
-    public SegmentCache(int maximumSize) {
+    protected SegmentCache(int maximumSize) {
         this.maximumSize = maximumSize;
     }
 
-    public SegmentCache() {
-        this(DEFAULT_MEMORY_CACHE_SIZE);
+    public static SegmentCache create() {
+        return create(DEFAULT_MEMORY_CACHE_SIZE);
+    }
+
+    public static SegmentCache create(int maximumSize) {
+        if (Boolean.parseBoolean(System.getProperty("oak.segmentCacheLIRS", "false"))) {
+            return new SegmentCacheLIRS(maximumSize);
+        }
+        return new SegmentCache(maximumSize);
     }
 
     public Segment getSegment(UUID segmentId, Callable<Segment> loader)
@@ -112,5 +122,39 @@ public class SegmentCache {
         segments.clear();
         currentSize = 0;
     }
+    
+    /**
+     * A segment cache that internally uses the LIRS cache.
+     */
+    static class SegmentCacheLIRS extends SegmentCache {
+        
+        private CacheLIRS<UUID, Segment> cache;
+        
+        public SegmentCacheLIRS(int maximumSize) {
+            super(maximumSize);
+            cache = CacheLIRS.newBuilder().maximumWeight(maximumSize).build();
+        }
+
+        @Override
+        public Segment getSegment(UUID segmentId, Callable<Segment> loader) throws
ExecutionException {
+            return cache.get(segmentId, loader);
+        }
+
+        @Override
+        public void addSegment(Segment segment) {
+            cache.put(segment.getSegmentId(), segment);
+        }
+        
+        @Override
+        public void removeSegment(UUID segmentId) {
+            cache.invalidate(segmentId);
+        }
+        
+        @Override
+        public synchronized void clear() {
+            cache.invalidateAll();
+        }
+        
+    }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java?rev=1526205&r1=1526204&r2=1526205&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
Wed Sep 25 15:23:15 2013
@@ -119,7 +119,7 @@ public class SegmentNodeStoreService imp
             int cache = Integer.parseInt(String.valueOf(properties.get(CACHE)));
 
             mongo = new Mongo(host, port);
-            SegmentCache sc = new SegmentCache(cache * MB);
+            SegmentCache sc = SegmentCache.create(cache * MB);
             store = new MongoStore(mongo.getDB(db), sc);
         }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java?rev=1526205&r1=1526204&r2=1526205&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java
Wed Sep 25 15:23:15 2013
@@ -63,7 +63,7 @@ public class FileStore implements Segmen
 
     private final Map<String, Journal> journals = newHashMap();
 
-    private final SegmentCache cache = new SegmentCache();
+    private final SegmentCache cache = SegmentCache.create();
 
     public FileStore(File directory, int maxFileSize, boolean memoryMapping)
             throws IOException {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoStore.java?rev=1526205&r1=1526204&r2=1526205&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/mongo/MongoStore.java
Wed Sep 25 15:23:15 2013
@@ -71,7 +71,7 @@ public class MongoStore implements Segme
     }
 
     public MongoStore(DB db, int cacheSize) {
-        this(db, new SegmentCache(cacheSize));
+        this(db, SegmentCache.create(cacheSize));
     }
 
 



Mime
View raw message