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 al...@apache.org on 2016/08/04 14:33:23 UTC
svn commit: r1755193 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java
Author: alexparvulescu
Date: Thu Aug 4 14:33:23 2016
New Revision: 1755193
URL: http://svn.apache.org/viewvc?rev=1755193&view=rev
Log:
OAK-4641 Using same index definition for both async and sync indexing
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java?rev=1755193&r1=1755192&r2=1755193&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java Thu Aug 4 14:33:23 2016
@@ -62,8 +62,6 @@ import org.apache.jackrabbit.oak.spi.sta
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Objects;
-
public class IndexUpdate implements Editor {
private static final Logger log = LoggerFactory.getLogger(IndexUpdate.class);
@@ -190,7 +188,7 @@ public class IndexUpdate implements Edit
NodeState before) throws CommitFailedException {
for (String name : definitions.getChildNodeNames()) {
NodeBuilder definition = definitions.getChildNode(name);
- if (Objects.equal(rootState.async, definition.getString(ASYNC_PROPERTY_NAME))) {
+ if (isIncluded(rootState.async, definition)) {
String type = definition.getString(TYPE_PROPERTY_NAME);
if (type == null) {
// probably not an index def
@@ -229,6 +227,21 @@ public class IndexUpdate implements Edit
}
}
+ static boolean isIncluded(String asyncRef, NodeBuilder definition) {
+ if (definition.hasProperty(ASYNC_PROPERTY_NAME)) {
+ PropertyState p = definition.getProperty(ASYNC_PROPERTY_NAME);
+ List<String> opt = newArrayList(p.getValue(Type.STRINGS));
+ if (asyncRef == null) {
+ // sync index job, accept synonyms
+ return opt.contains("") || opt.contains("sync");
+ } else {
+ return opt.contains(asyncRef);
+ }
+ } else {
+ return asyncRef == null;
+ }
+ }
+
private void manageIndexPath(NodeBuilder definition, String name) {
String path = definition.getString(INDEX_PATH);
if (path == null){
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java?rev=1755193&r1=1755192&r2=1755193&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java Thu Aug 4 14:33:23 2016
@@ -492,6 +492,44 @@ public class IndexUpdateTest {
return c;
}
+ @Test
+ public void testAsyncMVPDefinition() throws Exception {
+ NodeBuilder base;
+ // async null
+ base = EmptyNodeState.EMPTY_NODE.builder();
+ assertTrue(IndexUpdate.isIncluded(null, base));
+ assertFalse(IndexUpdate.isIncluded("async", base));
+
+ // async single value
+ base = EmptyNodeState.EMPTY_NODE.builder().setProperty(
+ ASYNC_PROPERTY_NAME, "async");
+ assertFalse(IndexUpdate.isIncluded(null, base));
+ assertTrue(IndexUpdate.isIncluded("async", base));
+
+ // async multiple values: "" for sync
+ base = EmptyNodeState.EMPTY_NODE.builder()
+ .setProperty(ASYNC_PROPERTY_NAME, Sets.newHashSet("", "async"),
+ Type.STRINGS);
+ assertTrue(IndexUpdate.isIncluded(null, base));
+ assertTrue(IndexUpdate.isIncluded("async", base));
+ assertFalse(IndexUpdate.isIncluded("async-other", base));
+
+ // async multiple values: "sync" for sync
+ base = EmptyNodeState.EMPTY_NODE.builder().setProperty(
+ ASYNC_PROPERTY_NAME, Sets.newHashSet("sync", "async"),
+ Type.STRINGS);
+ assertTrue(IndexUpdate.isIncluded(null, base));
+ assertTrue(IndexUpdate.isIncluded("async", base));
+ assertFalse(IndexUpdate.isIncluded("async-other", base));
+
+ // async multiple values: no sync present
+ base = EmptyNodeState.EMPTY_NODE.builder().setProperty(
+ ASYNC_PROPERTY_NAME, Sets.newHashSet("async", "async-other"),
+ Type.STRINGS);
+ assertFalse(IndexUpdate.isIncluded(null, base));
+ assertTrue(IndexUpdate.isIncluded("async", base));
+ assertTrue(IndexUpdate.isIncluded("async-other", base));
+ }
}