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 da...@apache.org on 2014/06/20 14:49:30 UTC

svn commit: r1604166 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/

Author: davide
Date: Fri Jun 20 12:49:29 2014
New Revision: 1604166

URL: http://svn.apache.org/r1604166
Log:
OAK-1899 Ordered index fails with old index content

fixed the ArrayIndexOutOfBoundsException during the set of :next and
added log messages for easing future debugging.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/OrderedContentMirrorStoreStrategy.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/OrderedContentMirrorStorageStrategyTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/OrderedContentMirrorStoreStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/OrderedContentMirrorStoreStrategy.java?rev=1604166&r1=1604165&r2=1604166&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/OrderedContentMirrorStoreStrategy.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/OrderedContentMirrorStoreStrategy.java Fri Jun 20 12:49:29 2014
@@ -23,6 +23,7 @@ import static org.apache.jackrabbit.oak.
 import java.util.Collections;
 import java.util.Deque;
 import java.util.Iterator;
+import java.util.List;
 import java.util.NoSuchElementException;
 import java.util.Random;
 
@@ -47,6 +48,7 @@ import org.slf4j.LoggerFactory;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 
 /**
  * Same as for {@link ContentMirrorStoreStrategy} but the order of the keys is kept by using the
@@ -149,6 +151,7 @@ public class OrderedContentMirrorStoreSt
                                         
     @Override
     void prune(final NodeBuilder index, final Deque<NodeBuilder> builders, final String key) {
+        LOG.debug("prune() - deleting: {}", key);
         for (NodeBuilder node : builders) {
             if (node.hasProperty("match") || node.getChildNodeCount(1) > 0) {
                 return;
@@ -166,11 +169,25 @@ public class OrderedContentMirrorStoreSt
                             walkedLanes
                             );
                         lane0Next = getPropertyNext(walkedLanes[0]);
+                        if (LOG.isDebugEnabled()) {
+                            for (int i = 0; i < walkedLanes.length; i++) {
+                                LOG.debug("prune() - walkedLanes[{}]: {}", i,
+                                    walkedLanes[i].getName());
+                            }
+                        }
                         for (int lane = walkedLanes.length - 1; lane >= 0; lane--) {
                             prevNext = getPropertyNext(walkedLanes[lane], lane);
                             if (key.equals(prevNext)) {
                                 // if it's actually pointing to us let's deal with it
                                 currNext = getPropertyNext(node, lane);
+                                if (LOG.isDebugEnabled()) {
+                                    LOG.debug(
+                                        "prune() - setting next for '{}' on lane '{}' with '{}'",
+                                        new Object[] {
+                                        walkedLanes[lane].getName(),
+                                        lane,
+                                        currNext});
+                                }
                                 setPropertyNext(index.getChildNode(walkedLanes[lane].getName()),
                                     currNext, lane);
                             }
@@ -997,7 +1014,23 @@ public class OrderedContentMirrorStoreSt
         if (node != null && value != null && lane >= 0 && lane < OrderedIndex.LANES) {
             PropertyState next = node.getProperty(NEXT);
             if (next != null) {
-                String[] values = Iterables.toArray(next.getValue(Type.STRINGS), String.class);
+                String[] values;
+                if (next.isArray()) {
+                    values = Iterables.toArray(next.getValue(Type.STRINGS), String.class);
+                    if (values.length < OrderedIndex.LANES) {
+                        // it could be we increased the number of lanes and running on some existing
+                        // content
+                        LOG.debug("topping-up the number of lanes.");
+                        List<String> vv = Lists.newArrayList(values);
+                        for (int i = vv.size(); i <= OrderedIndex.LANES; i++) {
+                            vv.add("");
+                        }
+                        values = vv.toArray(new String[0]);
+                    }
+                } else {
+                    values = Iterables.toArray(EMPTY_NEXT, String.class);
+                    values[0] = next.getValue(Type.STRING);
+                }
                 values[lane] = value;
                 setPropertyNext(node, values);
             }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/OrderedContentMirrorStorageStrategyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/OrderedContentMirrorStorageStrategyTest.java?rev=1604166&r1=1604165&r2=1604166&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/OrderedContentMirrorStorageStrategyTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/OrderedContentMirrorStorageStrategyTest.java Fri Jun 20 12:49:29 2014
@@ -1662,7 +1662,55 @@ public class OrderedContentMirrorStorage
         assertNotNull(":next cannot be null", n.getProperty(NEXT));
         assertEquals(ImmutableList.of("a", "b", "c", "a"),
             n.getProperty(NEXT).getValue(Type.STRINGS));
-    }
+
+        n = EmptyNodeState.EMPTY_NODE.builder();
+        n.setProperty(NEXT, "a", Type.STRING);
+        OrderedContentMirrorStoreStrategy.setPropertyNext(n, "b", 0);
+        assertNotNull(n);
+        assertNotNull(":next cannot be null", n.getProperty(NEXT));
+        assertEquals(ImmutableList.of("b", "", "", ""),
+            n.getProperty(NEXT).getValue(Type.STRINGS));
+
+        n = EmptyNodeState.EMPTY_NODE.builder();
+        n.setProperty(NEXT, "a", Type.STRING);
+        OrderedContentMirrorStoreStrategy.setPropertyNext(n, "b", 1);
+        assertNotNull(n);
+        assertNotNull(":next cannot be null", n.getProperty(NEXT));
+        assertEquals(ImmutableList.of("a", "b", "", ""),
+            n.getProperty(NEXT).getValue(Type.STRINGS));
+
+        n = EmptyNodeState.EMPTY_NODE.builder();
+        n.setProperty(NEXT, "a", Type.STRING);
+        OrderedContentMirrorStoreStrategy.setPropertyNext(n, "b", 2);
+        assertNotNull(n);
+        assertNotNull(":next cannot be null", n.getProperty(NEXT));
+        assertEquals(ImmutableList.of("a", "", "b", ""),
+            n.getProperty(NEXT).getValue(Type.STRINGS));
+
+        n = EmptyNodeState.EMPTY_NODE.builder();
+        n.setProperty(NEXT, "a", Type.STRING);
+        OrderedContentMirrorStoreStrategy.setPropertyNext(n, "b", 3);
+        assertNotNull(n);
+        assertNotNull(":next cannot be null", n.getProperty(NEXT));
+        assertEquals(ImmutableList.of("a", "", "", "b"),
+            n.getProperty(NEXT).getValue(Type.STRINGS));
+
+        n = EmptyNodeState.EMPTY_NODE.builder();
+        n.setProperty(NEXT, ImmutableList.of("a", "b"), Type.STRINGS);
+        OrderedContentMirrorStoreStrategy.setPropertyNext(n, "c", 1);
+        assertNotNull(n);
+        assertNotNull(":next cannot be null", n.getProperty(NEXT));
+        assertEquals(ImmutableList.of("a", "c", "", ""),
+            n.getProperty(NEXT).getValue(Type.STRINGS));
+
+        n = EmptyNodeState.EMPTY_NODE.builder();
+        n.setProperty(NEXT, ImmutableList.of("a", "b"), Type.STRINGS);
+        OrderedContentMirrorStoreStrategy.setPropertyNext(n, "c", 3);
+        assertNotNull(n);
+        assertNotNull(":next cannot be null", n.getProperty(NEXT));
+        assertEquals(ImmutableList.of("a", "b", "", "c"),
+            n.getProperty(NEXT).getValue(Type.STRINGS));
+}
     
     @Test
     public void getNext() {