Author: baedke
Date: Wed Sep 28 15:42:35 2016
New Revision: 1762686
URL: http://svn.apache.org/viewvc?rev=1762686&view=rev
Log:
OAK-4715: Reduce DocumentStore reads for local changes
Modified:
jackrabbit/oak/branches/1.4/ (props changed)
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Propchange: jackrabbit/oak/branches/1.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Sep 28 15:42:35 2016
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735081,1735141,1735267,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738136,1738138,1738207,1738234,1738252,1738775,1738795,1738833,1738950,1738957,1738963,1739712,1739760,1739867,1739894,1739959-1739960,1740114,1740116,1740250,1740333,1740349,1740360,1740625-1740626,1740774,1740837,1740879,1740971,1741016,1741032,1741339,1741343,1742077,1742117,1742125,1742363,1742520,1742888,1742916,1743097,1743172,1743343,1743674,1744265,1744292,1744589,1744670,1744672,1744959,1745038,1745127,1745197,1745336,1745368,1746086,1746117,1746342,1746345,1746408,1746696,1746981,1747198,1747200,1747341-1747342,1747380,1747387,1747406,1747492,1747512,1747654,1748505,1748553,1748722,1748870,1749275,1749350,1749424,1749443,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750052,1750076-1750077,1750287,1750457,1750462
,1750465,1750495,1750626,1750809,1750886,1751410,1751445-1751446,1751478,1751753,1751755,1751871,1752198,1752202,1752259,1752273-1752274,1752283,1752292,1752438,1752447-1752448,1752508,1752596,1752616,1752659,1752672,1753262,1753331-1753332,1753335-1753336,1753355,1753444,1754117,1754239,1755157,1755191,1756520,1756580,1757119,1757166,1759433,1760340,1760373,1760387,1760661-1760662,1761412,1761444,1761571,1761762,1761787,1761876,1762453,1762612,1762632,1762635
+/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735081,1735141,1735267,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738136,1738138,1738207,1738234,1738252,1738775,1738795,1738833,1738950,1738957,1738963,1739712,1739760,1739867,1739894,1739959-1739960,1740114,1740116,1740250,1740333,1740349,1740360,1740625-1740626,1740774,1740837,1740879,1740971,1741016,1741032,1741339,1741343,1742077,1742117,1742125,1742363,1742520,1742888,1742916,1743097,1743172,1743343,1743674,1744265,1744292,1744589,1744670,1744672,1744959,1745038,1745127,1745197,1745336,1745368,1746086,1746117,1746342,1746345,1746408,1746696,1746981,1747198,1747200,1747341-1747342,1747380,1747387,1747406,1747492,1747512,1747654,1748505,1748553,1748722,1748870,1749275,1749350,1749424,1749443,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750052,1750076-1750077,1750287,1750457,1750462
,1750465,1750495,1750626,1750809,1750886,1751410,1751445-1751446,1751478,1751753,1751755,1751871,1752198,1752202,1752259,1752273-1752274,1752283,1752292,1752438,1752447-1752448,1752508,1752596,1752616,1752659,1752672,1753262,1753331-1753332,1753335-1753336,1753355,1753444,1754117,1754239,1755157,1755191,1756520,1756580,1757119,1757166,1758213,1758713,1759433,1760340,1760373,1760387,1760661-1760662,1761412,1761444,1761571,1761762,1761787,1761876,1762453,1762612,1762632,1762635
/jackrabbit/trunk:1345480
Modified:
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1762686&r1=1762685&r2=1762686&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
(original)
+++
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
Wed Sep 28 15:42:35 2016
@@ -1132,12 +1132,20 @@ public final class DocumentNodeStore
List<String> removed, List<String> changed,
DiffCache.Entry cacheEntry) {
if (isNew) {
+ // determine the revision for the nodeChildrenCache entry when
+ // the node is new. Fallback to after revision in case document
+ // is not in the cache. (OAK-4715)
+ NodeDocument doc = store.getIfCached(NODES, getIdFromPath(path));
+ RevisionVector afterLastRev = after;
+ if (doc != null) {
+ afterLastRev = new RevisionVector(doc.getLastRev().values());
+ afterLastRev = afterLastRev.update(rev);
+ }
if (added.isEmpty()) {
// this is a leaf node.
// check if it has the children flag set
- NodeDocument doc = store.find(NODES, getIdFromPath(path));
if (doc != null && doc.hasChildren()) {
- PathRev key = childNodeCacheKey(path, after, null);
+ PathRev key = childNodeCacheKey(path, afterLastRev, null);
LOG.debug("nodeChildrenCache.put({},{})", key,
"NO_CHILDREN");
nodeChildrenCache.put(key, DocumentNodeState.NO_CHILDREN);
}
@@ -1148,7 +1156,7 @@ public final class DocumentNodeStore
set.add(Utils.unshareString(PathUtils.getName(p)));
}
c.children.addAll(set);
- PathRev key = childNodeCacheKey(path, after, null);
+ PathRev key = childNodeCacheKey(path, afterLastRev, null);
LOG.debug("nodeChildrenCache.put({},{})", key, c);
nodeChildrenCache.put(key, c);
}
Modified:
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1762686&r1=1762685&r2=1762686&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
(original)
+++
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Wed Sep 28 15:42:35 2016
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertFal
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -64,6 +65,7 @@ import java.util.concurrent.locks.Reentr
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
@@ -74,6 +76,7 @@ import com.google.common.collect.Sets;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.json.JsopDiff;
import org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler;
import org.apache.jackrabbit.oak.plugins.commit.ConflictHook;
import org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider;
@@ -91,6 +94,7 @@ import org.apache.jackrabbit.oak.spi.com
import org.apache.jackrabbit.oak.spi.commit.EditorHook;
import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.commit.Observer;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -98,6 +102,7 @@ import org.apache.jackrabbit.oak.spi.sta
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.stats.Clock;
import org.junit.After;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.Logger;
@@ -2703,6 +2708,97 @@ public class DocumentNodeStoreTest {
assertTrue(parent.hasChildNode("baz"));
}
+ @Ignore("OAK-4687")
+ @Test
+ public void exceptionHandlingInCommit() throws Exception{
+ DocumentNodeStore ns = builderProvider.newBuilder().getNodeStore();
+ final TestException testException = new TestException();
+ final AtomicBoolean failCommit = new AtomicBoolean();
+ ns.addObserver(new Observer() {
+ @Override
+ public void contentChanged(@Nonnull NodeState root, @Nullable
CommitInfo info) {
+ if (failCommit.get()){
+ throw testException;
+ }
+ }
+ });
+
+
+ NodeBuilder b1 = ns.getRoot().builder();
+ b1.child("parent");
+ failCommit.set(true);
+ try {
+ merge(ns, b1);
+ fail();
+ } catch(Exception e){
+ assertSame(testException, Throwables.getRootCause(e));
+ }
+ }
+
+ // OAK-4715
+ @Test
+ public void localChangesFromCache() throws Exception {
+ final AtomicInteger numQueries = new AtomicInteger();
+ DocumentStore store = new MemoryDocumentStore() {
+ @Nonnull
+ @Override
+ public <T extends Document> List<T> query(Collection<T> collection,
+ String fromKey,
+ String toKey,
+ int limit) {
+ if (collection == Collection.NODES) {
+ numQueries.incrementAndGet();
+ }
+ return super.query(collection, fromKey, toKey, limit);
+ }
+ };
+ DocumentNodeStore ns1 = builderProvider.newBuilder().setClusterId(1)
+ .setAsyncDelay(0).setDocumentStore(store).getNodeStore();
+ NodeBuilder builder = ns1.getRoot().builder();
+ builder.child("node-1");
+ merge(ns1, builder);
+ ns1.runBackgroundOperations();
+ DocumentNodeStore ns2 = builderProvider.newBuilder().setClusterId(2)
+ .setAsyncDelay(0).setDocumentStore(store).getNodeStore();
+ builder = ns2.getRoot().builder();
+ builder.child("node-2");
+ merge(ns2, builder);
+ ns2.runBackgroundOperations();
+ ns1.runBackgroundOperations();
+
+ NodeState before = ns1.getRoot();
+
+ builder = before.builder();
+ builder.child("node-1").child("foo").child("bar");
+ NodeState after = merge(ns1, builder);
+
+ numQueries.set(0);
+ JsopDiff.diffToJsop(before, after);
+ assertEquals(0, numQueries.get());
+
+ before = after;
+ builder = ns1.getRoot().builder();
+ builder.child("node-1").child("foo").child("bar").setProperty("p", 1);
+ after = merge(ns1, builder);
+
+ numQueries.set(0);
+ JsopDiff.diffToJsop(before, after);
+ assertEquals(0, numQueries.get());
+
+ before = after;
+ builder = ns1.getRoot().builder();
+ builder.child("node-1").child("foo").child("bar").remove();
+ after = merge(ns1, builder);
+
+ numQueries.set(0);
+ JsopDiff.diffToJsop(before, after);
+ assertEquals(0, numQueries.get());
+ }
+
+ private static class TestException extends RuntimeException {
+
+ }
+
private static DocumentNodeState asDocumentNodeState(NodeState state) {
if (!(state instanceof DocumentNodeState)) {
throw new IllegalArgumentException("Not a DocumentNodeState");