Author: mreutegg
Date: Tue Jun 27 14:11:44 2017
New Revision: 1800064
URL: http://svn.apache.org/viewvc?rev=1800064&view=rev
Log:
OAK-6351: Invalidate cache entries when getChildNodes() is aborted
Merged revision 1798834 from trunk
Modified:
jackrabbit/oak/branches/1.6/ (props changed)
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Propchange: jackrabbit/oak/branches/1.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 27 14:11:44 2017
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1781068,1781075,1781248,1781386,1781846,1781907,1782000,1782029,1782196,1782447,1782476,1782770,1782945,1782966,1782973,1782990,1783061,1783066,1783089,1783104-1783105,1783110,1783619,1783720,1783731,1783733,1783738,1783742,1783773,1783855,1783891,1784023,1784034,1784130,1784162,1784251,1784401,1784551,1784574,1784689,1785095,1785108,1785283,1785838,1785919,1785946,1787074,1787145,1787217,1787425,1788056,1788378,1788387-1788389,1788850,1789056,1789534,1790382,1792463,1792742,1792746,1793088,1793618,1793627,1793644,1795138,1795314,1795330,1795475,1795488,1795491,1795502,1795594,1795613,1795618,1796144,1796230,1796239,1796274,1796278,1796988,1798035
+/jackrabbit/oak/trunk:1781068,1781075,1781248,1781386,1781846,1781907,1782000,1782029,1782196,1782447,1782476,1782770,1782945,1782966,1782973,1782990,1783061,1783066,1783089,1783104-1783105,1783110,1783619,1783720,1783731,1783733,1783738,1783742,1783773,1783855,1783891,1784023,1784034,1784130,1784162,1784251,1784401,1784551,1784574,1784689,1785095,1785108,1785283,1785838,1785919,1785946,1787074,1787145,1787217,1787425,1788056,1788378,1788387-1788389,1788850,1789056,1789534,1790382,1792463,1792742,1792746,1793088,1793618,1793627,1793644,1795138,1795314,1795330,1795475,1795488,1795491,1795502,1795594,1795613,1795618,1796144,1796230,1796239,1796274,1796278,1796988,1798035,1798834
/jackrabbit/trunk:1345480
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1800064&r1=1800063&r2=1800064&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
Tue Jun 27 14:11:44 2017
@@ -1180,20 +1180,16 @@ public final class DocumentNodeStore
String p = concat(parent.getPath(), input);
DocumentNodeState result = getNode(p, readRevision);
if (result == null) {
- //This is very unexpected situation - parent's child list
declares the child to exist, while
- //its node state is null. Let's put some extra effort to
do some logging
+ // This is very unexpected situation - parent's child list
+ // declares the child to exist, while its node state is
+ // null. Let's put some extra effort to do some logging
+ // and invalidate the affected cache entries.
String id = Utils.getIdFromPath(p);
- String cachedDocStr, uncachedDocStr;
- try {
- cachedDocStr = store.find(Collection.NODES,
id).asString();
- } catch (DocumentStoreException dse) {
- cachedDocStr = dse.toString();
- }
- try {
- uncachedDocStr = store.find(Collection.NODES, id,
0).asString();
- } catch (DocumentStoreException dse) {
- uncachedDocStr = dse.toString();
- }
+ String cachedDocStr = docAsString(id, true);
+ String uncachedDocStr = docAsString(id, false);
+ nodeCache.invalidate(new PathRev(p, readRevision));
+ nodeChildrenCache.invalidate(childNodeCacheKey(
+ parent.getPath(), readRevision, name));
String exceptionMsg = String.format(
"Aborting getChildNodes() - DocumentNodeState is
null for %s at %s " +
"{\"cachedDoc\":{%s},
\"uncachedDoc\":{%s}}",
@@ -1203,6 +1199,24 @@ public final class DocumentNodeStore
return result.withRootRevision(parent.getRootRevision(),
parent.isFromExternalChange());
}
+
+ private String docAsString(String id, boolean cached) {
+ try {
+ NodeDocument doc;
+ if (cached) {
+ doc = store.find(Collection.NODES, id);
+ } else {
+ doc = store.find(Collection.NODES, id, 0);
+ }
+ if (doc == null) {
+ return "<null>";
+ } else {
+ return doc.asString();
+ }
+ } catch (DocumentStoreException e) {
+ return e.toString();
+ }
+ }
});
}
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1800064&r1=1800063&r2=1800064&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
Tue Jun 27 14:11:44 2017
@@ -2886,6 +2886,43 @@ public class DocumentNodeStoreTest {
assertTrue("Two added paths should have forced flush", numChangedPaths
== 0);
}
+ // OAK-6351
+ @Test
+ public void inconsistentNodeChildrenCache() throws Exception {
+ DocumentNodeStore ns = builderProvider.newBuilder().getNodeStore();
+ NodeBuilder builder = ns.getRoot().builder();
+ builder.child("a");
+ builder.child("b");
+ merge(ns, builder);
+ builder = ns.getRoot().builder();
+ builder.child("b").remove();
+ merge(ns, builder);
+ RevisionVector head = ns.getHeadRevision();
+
+ // simulate an incorrect cache entry
+ PathRev key = new PathRev("/", head);
+ DocumentNodeState.Children c = new DocumentNodeState.Children();
+ c.children.add("a");
+ c.children.add("b");
+ ns.getNodeChildrenCache().put(key, c);
+
+ try {
+ for (ChildNodeEntry entry : ns.getRoot().getChildNodeEntries()) {
+ entry.getName();
+ }
+ fail("must fail with DocumentStoreException");
+ } catch (DocumentStoreException e) {
+ // expected
+ }
+ // next attempt must succeed
+ List<String> names = Lists.newArrayList();
+ for (ChildNodeEntry entry : ns.getRoot().getChildNodeEntries()) {
+ names.add(entry.getName());
+ }
+ assertEquals(1L, names.size());
+ assertTrue(names.contains("a"));
+ }
+
private static class TestException extends RuntimeException {
}