jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1440395 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: CacheStore.java SegmentStore.java
Date Wed, 30 Jan 2013 13:17:53 GMT
Author: jukka
Date: Wed Jan 30 13:17:53 2013
New Revision: 1440395

URL: http://svn.apache.org/viewvc?rev=1440395&view=rev
Log:
OAK-593: Segment-based MK

Adjust SegmentStore into a lower-level interface that SegmentWriter and -Reader could use.
Add a basic segment cache.

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/CacheStore.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/CacheStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/CacheStore.java?rev=1440395&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/CacheStore.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/CacheStore.java
Wed Jan 30 13:17:53 2013
@@ -0,0 +1,65 @@
+package org.apache.jackrabbit.oak.plugins.segment;
+
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.cache.Weigher;
+
+public class CacheStore implements SegmentStore {
+
+    private final SegmentStore store;
+
+    private final LoadingCache<UUID, byte[]> cache;
+
+    public CacheStore(final SegmentStore store, long cacheSize) {
+        this.store = store;
+        this.cache = CacheBuilder.newBuilder()
+                .maximumWeight(cacheSize)
+                .weigher(new Weigher<UUID, byte[]>() {
+                    @Override
+                    public int weigh(UUID key, byte[] value) {
+                        return value.length;
+                    }
+                }).build(new CacheLoader<UUID, byte[]>() {
+                    @Override
+                    public byte[] load(UUID key) throws Exception {
+                        return store.readSegment(key);
+                    }
+                });
+    }
+
+    @Override
+    public RecordId getHead(String journal) {
+        return store.getHead(journal);
+    }
+
+    @Override
+    public boolean updateHead(String journal, RecordId base, RecordId head) {
+        return store.updateHead(journal, base, head);
+    }
+
+    @Override
+    public byte[] readSegment(UUID segmentId) {
+        try {
+            return cache.get(segmentId);
+        } catch (ExecutionException e) {
+            throw new IllegalStateException(
+                    "Failed to read segment " + segmentId, e);
+        }
+    }
+
+    @Override
+    public void createSegment(
+            UUID segmentId, byte[] data, int offset, int length) {
+        store.createSegment(segmentId, data, offset, length);
+    }
+
+    @Override
+    public void deleteSegment(UUID segmentId) {
+        store.deleteSegment(segmentId);
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java?rev=1440395&r1=1440394&r2=1440395&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStore.java
Wed Jan 30 13:17:53 2013
@@ -16,12 +16,18 @@
  */
 package org.apache.jackrabbit.oak.plugins.segment;
 
+import java.util.UUID;
+
 public interface SegmentStore {
 
-    Journal getJournal(String name);
+    RecordId getHead(String journal);
+
+    boolean updateHead(String journal, RecordId base, RecordId head);
+
+    byte[] readSegment(UUID segmentId);
 
-    SegmentReader getReader();
+    void createSegment(UUID segmentId, byte[] data, int offset, int length);
 
-    SegmentWriter getWriter();
+    void deleteSegment(UUID segmentId);
 
 }



Mime
View raw message