jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1556610 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: AbstractStore.java Segment.java file/FileStore.java
Date Wed, 08 Jan 2014 19:20:20 GMT
Author: jukka
Date: Wed Jan  8 19:20:19 2014
New Revision: 1556610

URL: http://svn.apache.org/r1556610
Log:
OAK-593: Segment-based MK

Automatically dispose cached strings and templates that aren't being used

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java?rev=1556610&r1=1556609&r2=1556610&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/AbstractStore.java
Wed Jan  8 19:20:19 2014
@@ -32,7 +32,7 @@ public abstract class AbstractStore impl
 
     protected static final int MB = 1024 * 1024;
 
-    private final Cache<UUID, Segment> segments;
+    protected final Cache<UUID, Segment> segments;
 
     /**
      * Identifiers of the segments that are currently being loaded.

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java?rev=1556610&r1=1556609&r2=1556610&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
Wed Jan  8 19:20:19 2014
@@ -125,6 +125,8 @@ public class Segment {
      */
     private final ConcurrentMap<Integer, Template> templates = newConcurrentMap();
 
+    private final byte[] recentCacheHits;
+
     public Segment(SegmentStore store, UUID uuid, ByteBuffer data) {
         this.store = checkNotNull(store);
         this.uuid = checkNotNull(uuid);
@@ -141,7 +143,9 @@ public class Segment {
                         data.getLong(refpos + i * 16),
                         data.getLong(refpos + i * 16 + 8));
             }
+            recentCacheHits = new byte[(data.remaining() + 16 * 8 - 1) / (16 * 8)];
         } else {
+            recentCacheHits = null;
             refids = NO_REFS;
         }
 
@@ -153,9 +157,27 @@ public class Segment {
         this.uuid = checkNotNull(uuid);
         this.refids = checkNotNull(refids);
         this.data = checkNotNull(data);
+        this.recentCacheHits = new byte[(data.remaining() + 16 * 8 - 1) / (16 * 8)];
         this.current = true;
     }
 
+    public void dropOldCacheEntries() {
+        checkState(recentCacheHits != null);
+        for (Integer key : strings.keySet().toArray(new Integer[0])) {
+            int bitpos = (pos(key, 1) - data.position()) / 16;
+            if ((recentCacheHits[bitpos / 8] & (0x80 >>> (bitpos % 8))) == 0)
{
+                strings.remove(key);
+            }
+        }
+        for (Integer key : templates.keySet().toArray(new Integer[0])) {
+            int bitpos = (pos(key, 1) - data.position()) / 16;
+            if ((recentCacheHits[bitpos / 8] & (0x80 >>> (bitpos % 8))) == 0)
{
+                templates.remove(key);
+            }
+        }
+        Arrays.fill(recentCacheHits, (byte) 0);
+    }
+
     /**
      * Maps the given record offset to the respective position within the
      * internal {@link #data} array. The validity of a record with the given
@@ -278,6 +300,8 @@ public class Segment {
             string = loadString(offset);
             strings.putIfAbsent(offset, string); // only keep the first copy
         }
+        int bitpos = (pos(offset, 1) - data.position()) / 16;
+        recentCacheHits[bitpos / 8] |= 0x80 >>> (bitpos % 8);
         return string;
     }
 
@@ -326,6 +350,8 @@ public class Segment {
             template = loadTemplate(offset);
             templates.putIfAbsent(offset, template); // only keep the first copy
         }
+        int bitpos = (pos(offset, 1) - data.position()) / 16;
+        recentCacheHits[bitpos / 8] |= 0x80 >>> (bitpos % 8);
         return template;
     }
 

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=1556610&r1=1556609&r2=1556610&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 Jan  8 19:20:19 2014
@@ -201,6 +201,10 @@ public class FileStore extends AbstractS
                 }
             }
         }
+
+        for (Segment segment : segments.asMap().values().toArray(new Segment[0])) {
+            segment.dropOldCacheEntries();
+        }
     }
 
     public Iterable<UUID> getSegmentIds() {



Mime
View raw message