Author: mreutegg
Date: Thu Nov 24 09:33:24 2016
New Revision: 1771098
URL: http://svn.apache.org/viewvc?rev=1771098&view=rev
Log:
OAK-5132: Limit diff cache entries in size
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheTest.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCache.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCache.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCache.java?rev=1771098&r1=1771097&r2=1771098&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCache.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCache.java
Thu Nov 24 09:33:24 2016
@@ -40,6 +40,14 @@ import static org.apache.jackrabbit.oak.
* An in-memory diff cache implementation.
*/
public class MemoryDiffCache extends DiffCache {
+
+ /**
+ * Cache entry Strings with a length more than this limit are not put into
+ * the cache.
+ */
+ static final int CACHE_VALUE_LIMIT = Integer.getInteger(
+ "oak.memoryDiffCache.limit", 8 * 1024 * 1024);
+
private static final Logger LOG =
LoggerFactory.getLogger(MemoryDiffCache.class);
/**
@@ -117,8 +125,13 @@ public class MemoryDiffCache extends Dif
@Override
public void append(@Nonnull String path, @Nonnull String changes) {
PathRev key = diffCacheKey(path, from, to);
- LOG.debug("Adding cache entry for {} from {} to {}", path, from,
to);
- diffCache.put(key, new StringValue(changes));
+ if (changes.length() > CACHE_VALUE_LIMIT) {
+ LOG.warn("Not caching entry for {} from {} to {}. Length of
changes is {}.",
+ path, from, to, changes.length());
+ } else {
+ LOG.debug("Adding cache entry for {} from {} to {}", path,
from, to);
+ diffCache.put(key, new StringValue(changes));
+ }
}
@Override
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheTest.java?rev=1771098&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheTest.java
Thu Nov 24 09:33:24 2016
@@ -0,0 +1,54 @@
+/*
+ * 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.plugins.document;
+
+import java.util.UUID;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class MemoryDiffCacheTest {
+
+ @Rule
+ public DocumentMKBuilderProvider builderProvider = new
DocumentMKBuilderProvider();
+
+ @Test
+ public void limit() throws Exception {
+ DiffCache cache = new MemoryDiffCache(builderProvider.newBuilder()
+ .setCacheSegmentCount(1)
+ .memoryCacheDistribution(0, 0, 0, 99));
+ RevisionVector from = new RevisionVector(Revision.newRevision(1));
+ RevisionVector to = new RevisionVector(Revision.newRevision(1));
+ DiffCache.Entry entry = cache.newEntry(from, to, false);
+ entry.append("/", "^\"foo\":{}");
+ entry.append("/foo", changes(MemoryDiffCache.CACHE_VALUE_LIMIT));
+ entry.done();
+ assertNotNull(cache.getChanges(from, to, "/", null));
+ assertNull(cache.getChanges(from, to, "/foo", null));
+ }
+
+ private static String changes(int minLength) {
+ StringBuilder sb = new StringBuilder();
+ while (sb.length() < minLength) {
+ sb.append("^\"").append(UUID.randomUUID()).append("\":{}");
+ }
+ return sb.toString();
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheTest.java
------------------------------------------------------------------------------
svn:eol-style = native