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 to...@apache.org on 2018/08/22 08:12:07 UTC
svn commit: r1838613 - in /jackrabbit/oak/branches/1.8/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java
Author: tomekr
Date: Wed Aug 22 08:12:07 2018
New Revision: 1838613
URL: http://svn.apache.org/viewvc?rev=1838613&view=rev
Log:
OAK-7540: Unique property index update fails in composite NodeStore setup
Unique indexes try to read existing properties which are accidently
creating index structure parent for read only mounts as well.
Modified:
jackrabbit/oak/branches/1.8/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
jackrabbit/oak/branches/1.8/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java
Modified: jackrabbit/oak/branches/1.8/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java?rev=1838613&r1=1838612&r2=1838613&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.8/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java (original)
+++ jackrabbit/oak/branches/1.8/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java Wed Aug 22 08:12:07 2018
@@ -29,6 +29,7 @@ import static org.apache.jackrabbit.oak.
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_CONTENT_NODE_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.PROPERTY_NAMES;
import static org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexUtil.encode;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
import java.util.Collections;
import java.util.Iterator;
@@ -44,6 +45,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
import org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
import org.apache.jackrabbit.oak.plugins.memory.PropertyValues;
import org.apache.jackrabbit.oak.plugins.nodetype.TypePredicate;
import org.apache.jackrabbit.oak.spi.commit.Editor;
@@ -291,10 +293,17 @@ class PropertyIndexEditor implements Ind
String properties = definition.getString(PROPERTY_NAMES);
boolean uniqueIndex = keysToCheckForUniqueness != null;
for (IndexStoreStrategy strategy : getStrategies(uniqueIndex)) {
- Supplier<NodeBuilder> index = memoize(() -> definition.child(strategy.getIndexNodeName()));
+ String indexNodeName = strategy.getIndexNodeName();
+ Supplier<NodeBuilder> index = memoize(() -> definition.child(indexNodeName));
if (uniqueIndex) {
+ Supplier<NodeBuilder> roBuilder;
+ if (definition.hasChildNode(indexNodeName)) {
+ roBuilder = index;
+ } else {
+ roBuilder = () -> EMPTY_NODE.builder();
+ }
keysToCheckForUniqueness.addAll(getExistingKeys(
- afterKeys, index, strategy));
+ afterKeys, roBuilder, strategy));
}
strategy.update(index, getPath(), properties, definition,
beforeKeys, afterKeys);
Modified: jackrabbit/oak/branches/1.8/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java?rev=1838613&r1=1838612&r2=1838613&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.8/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java (original)
+++ jackrabbit/oak/branches/1.8/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java Wed Aug 22 08:12:07 2018
@@ -993,6 +993,47 @@ public class PropertyIndexTest {
assertTrue(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/content", "abc")).exists());
}
+ @Test
+ public void mountWithCommitInWritableMountForUniqueIndex() throws Exception{
+ NodeState root = INITIAL_CONTENT;
+
+ // Add index definition
+ NodeBuilder builder = root.builder();
+ NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo",
+ true, true, ImmutableSet.of("foo"), null);
+ index.setProperty("entryCount", -1);
+ NodeState before = builder.getNodeState();
+
+ // Add some content and process it through the property index hook
+ builder.child("content").setProperty("foo", "abc");
+ NodeState after = builder.getNodeState();
+
+ MountInfoProvider mip = Mounts.newBuilder()
+ .readOnlyMount("foo", "/readOnly")
+ .build();
+
+ CompositeHook hook = new CompositeHook(
+ new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider().with(mip))),
+ new EditorHook(new ValidatorProvider(){
+ protected Validator getRootValidator(NodeState before, NodeState after, CommitInfo info) {
+ return new PrivateStoreValidator("/", mip);
+ }
+ })
+ );
+
+ NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
+
+ Mount defMount = mip.getDefaultMount();
+ NodeState indexedState = getNode(indexed, "/oak:index/foo/" + getNodeForMount(defMount) + "/abc");
+ assertTrue(indexedState.exists());
+ Iterable<String> values = indexedState.getStrings("entry");
+ assertEquals(1, Iterables.size(values));
+ assertEquals("/content", Iterables.getFirst(values, null));
+
+ Mount roMount = mip.getMountByName("foo");
+ assertFalse(getNode(indexed, "/oak:index/foo/" + getNodeForMount(roMount)).exists());
+ }
+
@Test(expected = CommitFailedException.class)
public void mountAndUniqueIndexes() throws Exception {
NodeState root = INITIAL_CONTENT;