You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2013/06/20 16:39:00 UTC
svn commit: r1495025 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk:
EmpericalWeigher.java MongoMK.java
Author: mreutegg
Date: Thu Jun 20 14:39:00 2013
New Revision: 1495025
URL: http://svn.apache.org/r1495025
Log:
OAK-619 Lock-free MongoMK implementation
- Use weight for diff cache
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/EmpericalWeigher.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/EmpericalWeigher.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/EmpericalWeigher.java?rev=1495025&r1=1495024&r2=1495025&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/EmpericalWeigher.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/EmpericalWeigher.java Thu Jun 20 14:39:00 2013
@@ -38,6 +38,8 @@ public class EmpericalWeigher implements
size += ((Node.Children) value).getMemory();
} else if (value instanceof MongoDocumentStore.CachedDocument) {
size += Utils.estimateMemoryUsage(((MongoDocumentStore.CachedDocument) value).value);
+ } else if (value instanceof String) {
+ size += ((String) value).length() * 2;
} else if (value != null) {
throw new IllegalArgumentException("Cannot determine weight for object of type " + value.getClass());
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java?rev=1495025&r1=1495024&r2=1495025&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java Thu Jun 20 14:39:00 2013
@@ -29,7 +29,9 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
+import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -67,12 +69,6 @@ public class MongoMK implements MicroKer
private static final Logger LOG = LoggerFactory.getLogger(MongoMK.class);
/**
- * The number of diffs to cache.
- */
- private static final int CACHE_DIFF =
- Integer.getInteger("oak.mongoMK.cacheNodes", 16);
-
- /**
* When trying to access revisions that are older than this many
* milliseconds, a warning is logged. The default is one minute.
*/
@@ -236,7 +232,8 @@ public class MongoMK implements MicroKer
.build();
diffCache = CacheBuilder.newBuilder()
- .maximumSize(CACHE_DIFF)
+ .weigher(builder.getWeigher())
+ .maximumWeight(builder.getDiffCacheSize())
.build();
init();
@@ -764,18 +761,28 @@ public class MongoMK implements MicroKer
}
@Override
- public synchronized String diff(String fromRevisionId, String toRevisionId, String path,
- int depth) throws MicroKernelException {
+ public String diff(final String fromRevisionId,
+ final String toRevisionId,
+ final String path,
+ final int depth) throws MicroKernelException {
String key = fromRevisionId + "-" + toRevisionId + "-" + path + "-" + depth;
- String d = diffCache.getIfPresent(key);
- if (d == null) {
- d = diffImpl(fromRevisionId, toRevisionId, path, depth);
- diffCache.put(key, d);
+ try {
+ return diffCache.get(key, new Callable<String>() {
+ @Override
+ public String call() throws Exception {
+ return diffImpl(fromRevisionId, toRevisionId, path, depth);
+ }
+ });
+ } catch (ExecutionException e) {
+ if (e.getCause() instanceof MicroKernelException) {
+ throw (MicroKernelException) e.getCause();
+ } else {
+ throw new MicroKernelException(e.getCause());
+ }
}
- return d;
}
- private String diffImpl(String fromRevisionId, String toRevisionId, String path,
+ private synchronized String diffImpl(String fromRevisionId, String toRevisionId, String path,
int depth) throws MicroKernelException {
if (fromRevisionId.equals(toRevisionId)) {
return "";
@@ -1561,6 +1568,7 @@ public class MongoMK implements MicroKer
private Weigher<String, Object> weigher = new EmpericalWeigher();
private long nodeCacheSize;
private long childrenCacheSize;
+ private long diffCacheSize;
private long documentCacheSize;
public Builder() {
@@ -1676,7 +1684,8 @@ public class MongoMK implements MicroKer
public Builder memoryCacheSize(long memoryCacheSize) {
this.nodeCacheSize = memoryCacheSize * 20 / 100;
this.childrenCacheSize = memoryCacheSize * 10 / 100;
- this.documentCacheSize = memoryCacheSize - nodeCacheSize - childrenCacheSize;
+ this.diffCacheSize = memoryCacheSize * 2 / 100;
+ this.documentCacheSize = memoryCacheSize - nodeCacheSize - childrenCacheSize - diffCacheSize;
return this;
}
@@ -1692,6 +1701,10 @@ public class MongoMK implements MicroKer
return documentCacheSize;
}
+ public long getDiffCacheSize() {
+ return diffCacheSize;
+ }
+
/**
* Open the MongoMK instance using the configured options.
*