Author: amitj
Date: Tue Jul 7 06:24:17 2015
New Revision: 1689579
URL: http://svn.apache.org/r1689579
Log:
OAK-3020: Async Update fails after IllegalArgumentException
Merged revisions 1687175, 1689577 from trunk
Modified:
jackrabbit/oak/branches/1.2/ (props changed)
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/Aggregate.java
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/AggregateTest.java
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 7 06:24:17 2015
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820,1684868,1685023,1685370,1685552,1685589-1685590
,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688636,1688817,1689003
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820,1684868,1685023,1685370,1685552,1685589-1685590
,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687175,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688636,1688817,1689003,1689577
/jackrabbit/trunk:1345480
Modified:
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/Aggregate.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/Aggregate.java?rev=1689579&r1=1689578&r2=1689579&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/Aggregate.java
(original)
+++
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/Aggregate.java
Tue Jul 7 06:24:17 2015
@@ -78,7 +78,7 @@ class Aggregate {
return includes;
}
- public void collectAggregates(NodeState root, ResultCollector collector)
throws CommitFailedException {
+ public void collectAggregates(NodeState root, ResultCollector collector) {
if (nodeTypeName.equals(ConfigUtil.getPrimaryTypeName(root))) {
List<Matcher> matchers = createMatchers();
collectAggregates(root, matchers, collector);
@@ -112,7 +112,7 @@ class Aggregate {
}
private static void collectAggregates(NodeState nodeState, List<Matcher>
matchers,
- ResultCollector collector) throws
CommitFailedException {
+ ResultCollector collector) {
for (ChildNodeEntry cne : nodeState.getChildNodeEntries()) {
List<Matcher> nextSet = newArrayListWithCapacity(matchers.size());
for (Matcher m : matchers) {
@@ -190,13 +190,12 @@ class Aggregate {
}
public void collectResults(T rootInclude, String rootIncludePath,
- String nodePath, NodeState nodeState,
ResultCollector results)
- throws CommitFailedException {
+ String nodePath, NodeState nodeState,
ResultCollector results) {
collectResults(nodePath, nodeState, results);
}
public void collectResults(String nodePath, NodeState nodeState,
- ResultCollector results) throws
CommitFailedException {
+ ResultCollector results) {
}
@@ -240,7 +239,7 @@ class Aggregate {
@Override
public void collectResults(NodeInclude rootInclude, String
rootIncludePath, String nodePath,
- NodeState nodeState, ResultCollector
results) throws CommitFailedException {
+ NodeState nodeState, ResultCollector
results) {
//For supporting jcr:contains(jcr:content, 'foo')
if (rootInclude.relativeNode){
results.onResult(new NodeIncludeResult(nodePath,
rootIncludePath, nodeState));
@@ -309,8 +308,7 @@ class Aggregate {
}
@Override
- public void collectResults(String nodePath, NodeState nodeState,
ResultCollector results)
- throws CommitFailedException {
+ public void collectResults(String nodePath, NodeState nodeState,
ResultCollector results) {
if (pattern != null) {
for (PropertyState ps : nodeState.getProperties()) {
if (pattern.matcher(ps.getName()).matches()) {
@@ -340,9 +338,9 @@ class Aggregate {
}
public static interface ResultCollector {
- void onResult(NodeIncludeResult result) throws CommitFailedException;
+ void onResult(NodeIncludeResult result);
- void onResult(PropertyIncludeResult result) throws
CommitFailedException;
+ void onResult(PropertyIncludeResult result);
}
public static class NodeIncludeResult {
@@ -508,8 +506,7 @@ class Aggregate {
null, currentPath));
}
- public void collectResults(ResultCollector results)
- throws CommitFailedException {
+ public void collectResults(ResultCollector results) {
checkArgument(status == Status.MATCH_FOUND);
//If result being collected as part of reaggregation then take path
Modified:
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java?rev=1689579&r1=1689578&r2=1689579&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
(original)
+++
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
Tue Jul 7 06:24:17 2015
@@ -297,13 +297,12 @@ public class LuceneIndexEditor implement
throw new CommitFailedException("Lucene", 3,
"Failed to index the node " + path, e);
} catch (IllegalArgumentException ie) {
- throw new CommitFailedException("Lucene", 3,
- "Failed to index the node " + path, ie);
+ log.warn("Failed to index the node [{}]", path, ie);
}
return false;
}
- private Document makeDocument(String path, NodeState state, boolean
isUpdate) throws CommitFailedException {
+ private Document makeDocument(String path, NodeState state, boolean
isUpdate) {
if (!isIndexable()) {
return null;
}
@@ -386,7 +385,7 @@ public class LuceneIndexEditor implement
NodeState state,
PropertyState property,
String pname,
- PropertyDefinition pd) throws
CommitFailedException {
+ PropertyDefinition pd) {
boolean includeTypeForFullText =
indexingRule.includePropertyType(property.getType().tag());
if (Type.BINARY.tag() == property.getType().tag()
&& includeTypeForFullText) {
@@ -433,7 +432,7 @@ public class LuceneIndexEditor implement
return pname;
}
- private boolean addTypedFields(List<Field> fields, PropertyState property,
String pname) throws CommitFailedException {
+ private boolean addTypedFields(List<Field> fields, PropertyState property,
String pname) {
int tag = property.getType().tag();
boolean fieldAdded = false;
for (int i = 0; i < property.count(); i++) {
@@ -460,7 +459,15 @@ public class LuceneIndexEditor implement
private boolean addTypedOrderedFields(List<Field> fields,
PropertyState property,
String pname,
- PropertyDefinition pd) throws
CommitFailedException {
+ PropertyDefinition pd) {
+ // Ignore and warn if property multi-valued as not supported
+ if (property.getType().isArray()) {
+ log.warn(
+ "Ignoring ordered property {} of type {} for path {} as
multivalued ordered property not supported",
+ pname, Type.fromTag(property.getType().tag(), true),
getPath());
+ return false;
+ }
+
int tag = property.getType().tag();
int idxDefinedTag = pd.getType();
// Try converting type to the defined type in the index definition
@@ -475,37 +482,35 @@ public class LuceneIndexEditor implement
String name = FieldNames.createDocValFieldName(pname);
boolean fieldAdded = false;
- for (int i = 0; i < property.count(); i++) {
- Field f = null;
- try {
- if (tag == Type.LONG.tag()) {
- //TODO Distinguish fields which need to be used for search
and for sort
- //If a field is only used for Sort then it can be stored
with less precision
- f = new NumericDocValuesField(name,
property.getValue(Type.LONG, i));
- } else if (tag == Type.DATE.tag()) {
- String date = property.getValue(Type.DATE, i);
- f = new NumericDocValuesField(name,
FieldFactory.dateToLong(date));
- } else if (tag == Type.DOUBLE.tag()) {
- f = new DoubleDocValuesField(name,
property.getValue(Type.DOUBLE, i));
- } else if (tag == Type.BOOLEAN.tag()) {
- f = new SortedDocValuesField(name,
- new BytesRef(property.getValue(Type.BOOLEAN,
i).toString()));
- } else if (tag == Type.STRING.tag()) {
- f = new SortedDocValuesField(name,
- new BytesRef(property.getValue(Type.STRING, i)));
- }
+ Field f = null;
+ try {
+ if (tag == Type.LONG.tag()) {
+ //TODO Distinguish fields which need to be used for search and
for sort
+ //If a field is only used for Sort then it can be stored with
less precision
+ f = new NumericDocValuesField(name,
property.getValue(Type.LONG));
+ } else if (tag == Type.DATE.tag()) {
+ String date = property.getValue(Type.DATE);
+ f = new NumericDocValuesField(name,
FieldFactory.dateToLong(date));
+ } else if (tag == Type.DOUBLE.tag()) {
+ f = new DoubleDocValuesField(name,
property.getValue(Type.DOUBLE));
+ } else if (tag == Type.BOOLEAN.tag()) {
+ f = new SortedDocValuesField(name,
+ new BytesRef(property.getValue(Type.BOOLEAN).toString()));
+ } else if (tag == Type.STRING.tag()) {
+ f = new SortedDocValuesField(name,
+ new BytesRef(property.getValue(Type.STRING)));
+ }
- if (f != null) {
- fields.add(f);
- fieldAdded = true;
- }
- } catch (Exception e) {
- log.warn(
- "Ignoring ordered property. Could not convert property {}
of type {} to type " +
- "{} for path {}",
- pname, Type.fromTag(property.getType().tag(), false),
- Type.fromTag(tag, false), getPath(), e);
+ if (f != null) {
+ fields.add(f);
+ fieldAdded = true;
}
+ } catch (Exception e) {
+ log.warn(
+ "Ignoring ordered property. Could not convert property {} of
type {} to type " +
+ "{} for path {}",
+ pname, Type.fromTag(property.getType().tag(), false),
+ Type.fromTag(tag, false), getPath(), e);
}
return fieldAdded;
}
@@ -642,11 +647,11 @@ public class LuceneIndexEditor implement
}
private boolean indexAggregates(final String path, final List<Field>
fields,
- final NodeState state) throws
CommitFailedException {
+ final NodeState state) {
final AtomicBoolean dirtyFlag = new AtomicBoolean();
indexingRule.getAggregate().collectAggregates(state, new
Aggregate.ResultCollector() {
@Override
- public void onResult(Aggregate.NodeIncludeResult result) throws
CommitFailedException {
+ public void onResult(Aggregate.NodeIncludeResult result) {
boolean dirty = indexAggregatedNode(path, fields, result);
if (dirty) {
dirtyFlag.set(true);
@@ -654,7 +659,7 @@ public class LuceneIndexEditor implement
}
@Override
- public void onResult(Aggregate.PropertyIncludeResult result)
throws CommitFailedException {
+ public void onResult(Aggregate.PropertyIncludeResult result) {
boolean dirty = false;
if (result.pd.ordered) {
dirty |= addTypedOrderedFields(fields,
result.propertyState,
@@ -678,10 +683,8 @@ public class LuceneIndexEditor implement
* @param fields indexed fields
* @param result aggregate result
* @return true if a field was created for passed node result
- * @throws CommitFailedException
*/
- private boolean indexAggregatedNode(String path, List<Field> fields,
Aggregate.NodeIncludeResult result)
- throws CommitFailedException {
+ private boolean indexAggregatedNode(String path, List<Field> fields,
Aggregate.NodeIncludeResult result) {
//rule for node being aggregated might be null if such nodes
//are not indexed on there own. In such cases we rely in current
//rule for some checks
Modified:
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/AggregateTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/AggregateTest.java?rev=1689579&r1=1689578&r2=1689579&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/AggregateTest.java
(original)
+++
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/AggregateTest.java
Tue Jul 7 06:24:17 2015
@@ -386,12 +386,12 @@ public class AggregateTest {
final ListMultimap<String, NodeIncludeResult> nodeResults =
ArrayListMultimap.create();
final Map<String, PropertyIncludeResult> propResults = newHashMap();
@Override
- public void onResult(NodeIncludeResult result) throws
CommitFailedException{
+ public void onResult(NodeIncludeResult result) {
nodeResults.put(result.nodePath, result);
}
@Override
- public void onResult(PropertyIncludeResult result) throws
CommitFailedException {
+ public void onResult(PropertyIncludeResult result) {
propResults.put(result.propertyPath, result);
}
Modified:
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java?rev=1689579&r1=1689578&r2=1689579&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
(original)
+++
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
Tue Jul 7 06:24:17 2015
@@ -38,6 +38,7 @@ import static javax.jcr.PropertyType.TYP
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
import static org.apache.jackrabbit.JcrConstants.NT_BASE;
import static
org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
@@ -66,6 +67,7 @@ import com.google.common.base.Function;
import com.google.common.collect.Iterators;
import com.google.common.collect.Maps;
import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
import org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider;
@@ -753,6 +755,25 @@ public class LuceneIndexTest {
assertEquals(1,
copier.getIndexDir("/oak:index/lucene").listFiles().length);
}
+ @Test
+ public void multiValuesForOrderedIndexShouldNotThrow() {
+ NodeBuilder index =
newLuceneIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", null);
+ NodeBuilder singleProp = TestUtil.child(index,
"indexRules/nt:base/properties/single");
+ singleProp.setProperty(LuceneIndexConstants.PROP_PROPERTY_INDEX, true);
+ singleProp.setProperty(LuceneIndexConstants.PROP_ORDERED, true);
+ singleProp.setProperty(LuceneIndexConstants.PROP_INCLUDED_TYPE,
PropertyType.TYPENAME_STRING);
+
+ NodeState before = builder.getNodeState();
+ builder.setProperty("single", asList("baz", "bar"), Type.STRINGS);
+ NodeState after = builder.getNodeState();
+
+ try {
+ HOOK.processCommit(before, after, CommitInfo.EMPTY);
+ } catch (CommitFailedException e) {
+ fail("Exception thrown when indexing invalid content");
+ }
+ }
+
@After
public void cleanUp(){
for (File d: dirs){
Modified:
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java?rev=1689579&r1=1689578&r2=1689579&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
(original)
+++
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
Tue Jul 7 06:24:17 2015
@@ -894,6 +894,37 @@ public class LucenePropertyIndexTest ext
assertSortedString();
}
+ @Test
+ public void sortQueriesWithStringIgnoredMulti_OrderedProps() throws
Exception {
+ Tree idx = createIndex("test1", of("foo", "bar"));
+ idx.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("bar"),
STRINGS));
+ idx.setProperty(createProperty(ORDERED_PROP_NAMES, of("foo"),
STRINGS));
+ idx.addChild(PROP_NODE).addChild("foo");
+ root.commit();
+
+ Tree test = root.getTree("/").addChild("test");
+ List<String> values = createStrings(NUMBER_OF_NODES);
+ List<Tuple> tuples = Lists.newArrayListWithCapacity(values.size());
+ for(int i = 0; i < values.size(); i++){
+ Tree child = test.addChild("n" + i);
+ child.setProperty("foo", values.get(i));
+ child.setProperty("bar", "baz");
+ tuples.add(new Tuple(values.get(i), child.getPath()));
+ }
+
+ //Add a wrong multi-valued property
+ Tree child = test.addChild("a");
+ child.setProperty("foo", of("w", "z"), Type.STRINGS);
+ child.setProperty("bar", "baz");
+ root.commit();
+
+ assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] =
'baz' order by [foo]", Lists
+ .newArrayList(Iterables.concat(Lists.newArrayList("/test/a"),
getSortedPaths(tuples, OrderDirection.ASC))));
+ assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] =
'baz' order by [foo] DESC", Lists
+ .newArrayList(Iterables.concat(getSortedPaths(tuples,
OrderDirection.DESC), Lists.newArrayList("/test/a")
+ )));
+ }
+
void assertSortedString() throws CommitFailedException {
Tree test = root.getTree("/").addChild("test");
List<String> values = createStrings(NUMBER_OF_NODES);