Author: tomekr
Date: Fri Sep 8 09:00:45 2017
New Revision: 1807691
URL: http://svn.apache.org/viewvc?rev=1807691&view=rev
Log:
OAK-6636: Create a path cache for the CompositeNodeState
Added:
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/StringCache.java
jackrabbit/oak/trunk/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/StringCacheTest.java
Modified:
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeState.java
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositionContext.java
Modified:
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeState.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeState.java?rev=1807691&r1=1807690&r2=1807691&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeState.java
(original)
+++
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeState.java
Fri Sep 8 09:00:45 2017
@@ -59,7 +59,7 @@ class CompositeNodeState extends Abstrac
private final String path;
CompositeNodeState(String path, NodeMap<NodeState> nodeStates,
CompositionContext ctx) {
- this.path = path;
+ this.path = ctx.getPathCache().get(path);
this.ctx = ctx;
this.nodeStates = nodeStates;
this.owningStore = ctx.getOwningStore(getPath());
Modified:
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositionContext.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositionContext.java?rev=1807691&r1=1807690&r2=1807691&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositionContext.java
(original)
+++
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositionContext.java
Fri Sep 8 09:00:45 2017
@@ -50,7 +50,10 @@ class CompositionContext {
private final Set<MountedNodeStore> allStores;
+ private final StringCache pathCache;
+
CompositionContext(MountInfoProvider mip, NodeStore globalStore,
List<MountedNodeStore> nonDefaultStores) {
+ this.pathCache = new StringCache();
this.mip = mip;
this.globalStore = new MountedNodeStore(mip.getDefaultMount(),
globalStore);
this.nonDefaultStores = nonDefaultStores;
@@ -175,4 +178,8 @@ class CompositionContext {
return new CompositeNodeState("/", NodeMap.create(rootStates), this);
}
+ StringCache getPathCache() {
+ return pathCache;
+ }
+
}
Added:
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/StringCache.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/StringCache.java?rev=1807691&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/StringCache.java
(added)
+++
jackrabbit/oak/trunk/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/StringCache.java
Fri Sep 8 09:00:45 2017
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.composite;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * This class caches the path strings used in the CompositeNodeState to avoid
+ * keeping too many strings in the memory.
+ */
+public class StringCache {
+
+ private static final int CACHE_SIZE = 1000;
+
+ private static final Logger LOG =
LoggerFactory.getLogger(StringCache.class);
+
+ private final ConcurrentMap<String, String> cache = new
ConcurrentHashMap<>(CACHE_SIZE);
+
+ public String get(String path) {
+ if (cache.size() >= CACHE_SIZE && !cache.containsKey(path)) {
+ LOG.debug("Cache size too big. Revise your mount setup.");
+ return path;
+ }
+ return cache.computeIfAbsent(path, (k) -> path);
+ }
+}
Added:
jackrabbit/oak/trunk/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/StringCacheTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/StringCacheTest.java?rev=1807691&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/StringCacheTest.java
(added)
+++
jackrabbit/oak/trunk/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/StringCacheTest.java
Fri Sep 8 09:00:45 2017
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.composite;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class StringCacheTest {
+
+ @Test
+ public void testCache() {
+ StringCache cache = new StringCache();
+
+ StringBuilder b = new StringBuilder("abc").append("xyz");
+
+ String s1 = b.toString();
+ String s2 = b.toString();
+ String s3 = b.toString();
+
+ Assert.assertNotSame(s1, s2);
+ Assert.assertNotSame(s2, s3);
+ Assert.assertNotSame(s1, s3);
+
+ String c1 = cache.get(s1);
+ String c2 = cache.get(s2);
+ String c3 = cache.get(s3);
+
+ Assert.assertSame(c1, c2);
+ Assert.assertSame(c2, c3);
+ Assert.assertSame(c1, c3);
+ }
+
+}