Author: catholicon
Date: Wed Sep 13 19:33:35 2017
New Revision: 1808278

URL: http://svn.apache.org/viewvc?rev=1808278&view=rev
Log:
OAK-6656: OrderedPropertyIndexEditorProvider does not return Editor to 
IndexUpdate leading to "ordered" being marked as missing type

(backport r1808128, r1808142 from trunk)
Treat type="ordered" similar to disabled "disabled". Also, warn message from 
Index provider would have index path which has type="ordered".
Also, fix tests along with making hit count non-static (as that made test 
execution depend on each other)


Modified:
    jackrabbit/oak/branches/1.6/   (props changed)
    
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
    
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedIndex.java
    
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProvider.java
    
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProviderTest.java

Propchange: jackrabbit/oak/branches/1.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Sep 13 19:33:35 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,1785917,1785919,1785946,1786122,1787074,1787145,1787217,1787425,1788056,1788378,1788387-1788389,1788463,1788476,1788850,1789056,1789534,1790382,1792463,1792742,1792746,1793013,1793088,1793618,1793627,1793644,1794393,1794417,1794683,1795138,1795314,1795330,1795475,1795488,1795491,1795502,1795594,1795613,1795618,1796144,1796230,1796239,1796274,1796278,1796988,1798035,1798834,1799219,1799389,1799393,1799924,1800269,1800606,1800613,1800974,1801011,1801013,1801118-1801119,1801675,1802260,1802262,1802286,1802548,1802934,1802938,1802973,1803026,1803247-1803249,1803951,1803953-1803955,1805851-1805852,1806668,1807308,1808125
 ,1808246
+/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,1785917,1785919,1785946,1786122,1787074,1787145,1787217,1787425,1788056,1788378,1788387-1788389,1788463,1788476,1788850,1789056,1789534,1790382,1792463,1792742,1792746,1793013,1793088,1793618,1793627,1793644,1794393,1794417,1794683,1795138,1795314,1795330,1795475,1795488,1795491,1795502,1795594,1795613,1795618,1796144,1796230,1796239,1796274,1796278,1796988,1798035,1798834,1799219,1799389,1799393,1799924,1800269,1800606,1800613,1800974,1801011,1801013,1801118-1801119,1801675,1802260,1802262,1802286,1802548,1802934,1802938,1802973,1803026,1803247-1803249,1803951,1803953-1803955,1805851-1805852,1806668,1807308,1808125
 ,1808128,1808142,1808246
 /jackrabbit/trunk:1345480

Modified: 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java?rev=1808278&r1=1808277&r2=1808278&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
 (original)
+++ 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
 Wed Sep 13 19:33:35 2017
@@ -446,7 +446,7 @@ public class IndexUpdate implements Edit
         private boolean failOnMissingIndexProvider = Boolean
                 .getBoolean("oak.indexUpdate.failOnMissingIndexProvider");
 
-        private final Set<String> ignore = newHashSet("disabled");
+        private final Set<String> ignore = newHashSet("disabled", "ordered");
 
         public void onMissingIndex(String type, NodeBuilder definition, String 
indexPath)
                 throws CommitFailedException {

Modified: 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedIndex.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedIndex.java?rev=1808278&r1=1808277&r2=1808278&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedIndex.java
 (original)
+++ 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedIndex.java
 Wed Sep 13 19:33:35 2017
@@ -31,12 +31,11 @@ public interface OrderedIndex {
     /**
      * Deprecation message tracked when using the ordered index.
      */
-    String DEPRECATION_MESSAGE = 
+    String DEPRECATION_MESSAGE =
         "Ordered Index has been deprecated since Oak 1.1.8. " +
-        "Please replace the index definitions with Lucene Property index " +
-        "and remove the index providers from the repository. " + 
+        "Please replace the index definition ({}) with Lucene Property index " 
+
+        "and remove the index providers from the repository. " +
         "See docs at http://jackrabbit.apache.org/oak/docs";;
-
     /**
      * the deprecation message will be tracked every N times
      */

Modified: 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProvider.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProvider.java?rev=1808278&r1=1808277&r2=1808278&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProvider.java
 (original)
+++ 
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProvider.java
 Wed Sep 13 19:33:35 2017
@@ -23,6 +23,7 @@ import javax.annotation.Nonnull;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.plugins.index.ContextAwareCallback;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
@@ -35,7 +36,7 @@ import org.slf4j.LoggerFactory;
 @Service(IndexEditorProvider.class)
 public class OrderedPropertyIndexEditorProvider implements 
IndexEditorProvider, OrderedIndex {
    private static final Logger LOG = 
LoggerFactory.getLogger(OrderedPropertyIndexEditorProvider.class);
-   private static int hits;
+   private int hits;
    private static int threshold = OrderedIndex.TRACK_DEPRECATION_EVERY;
    
    @Override
@@ -46,11 +47,15 @@ public class OrderedPropertyIndexEditorP
                                 @Nonnull IndexUpdateCallback callback) throws 
CommitFailedException {
         if (OrderedIndex.TYPE.equals(type)) {
             if (hit() % threshold == 0) {
-                LOG.warn(OrderedIndex.DEPRECATION_MESSAGE);                
+                if (callback instanceof ContextAwareCallback) {
+                    LOG.warn(DEPRECATION_MESSAGE, 
((ContextAwareCallback)callback).getIndexingContext().getIndexPath());
+                } else {
+                    LOG.warn(OrderedIndex.DEPRECATION_MESSAGE, definition);
+                }
             }
         }
         return null;
-    }
+   }
    
    private synchronized int hit() {
        return hits++;

Modified: 
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProviderTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProviderTest.java?rev=1808278&r1=1808277&r2=1808278&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProviderTest.java
 (original)
+++ 
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/OrderedPropertyIndexEditorProviderTest.java
 Wed Sep 13 19:33:35 2017
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_CONTENT_NODE_NAME;
 import static 
org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
+import static 
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static org.hamcrest.CoreMatchers.hasItem;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -30,11 +31,11 @@ import java.util.List;
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
 import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
 import org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider;
 import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
-import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
 import org.apache.jackrabbit.oak.plugins.tree.TreeFactory;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
@@ -54,18 +55,22 @@ public class OrderedPropertyIndexEditorP
     
     private final String indexName = "mickey";
     private final String indexedProperty = "mouse";
+
+    private final String DEPRECATION_MESSAGE = 
OrderedIndex.DEPRECATION_MESSAGE.replace("{}",
+            "/" + INDEX_DEFINITIONS_NAME + "/" + indexName);
     
-    private void createIndexDef(NodeBuilder root) throws RepositoryException {
-        IndexUtils
-        .createIndexDefinition(
-            new NodeUtil(TreeFactory.createTree(root
-                .child(IndexConstants.INDEX_DEFINITIONS_NAME))), indexName, 
false,
-            new String[] { indexedProperty }, null, OrderedIndex.TYPE);
+    private Tree createIndexDef(NodeBuilder root) throws RepositoryException {
+        return IndexUtils
+                .createIndexDefinition(
+                        new NodeUtil(TreeFactory.createTree(root
+                                
.child(IndexConstants.INDEX_DEFINITIONS_NAME))), indexName, false,
+                        new String[] { indexedProperty }, null, 
OrderedIndex.TYPE)
+                .getTree();
     }
     
     @Test
     public void withIndexDefSingleNode() throws RepositoryException, 
CommitFailedException {
-        NodeBuilder root = InitialContent.INITIAL_CONTENT.builder();
+        NodeBuilder root = EMPTY_NODE.builder();
         
         createIndexDef(root);
         
@@ -76,7 +81,7 @@ public class OrderedPropertyIndexEditorP
         custom.starting();
         root = hook.processCommit(before, after, CommitInfo.EMPTY).builder();
         assertEquals(1, custom.getLogs().size());
-        assertThat(custom.getLogs(), 
hasItem(OrderedIndex.DEPRECATION_MESSAGE));
+        assertThat(custom.getLogs(), hasItem(DEPRECATION_MESSAGE));
         custom.finished();
         
         NodeBuilder b = 
root.getChildNode(IndexConstants.INDEX_DEFINITIONS_NODE_TYPE)
@@ -88,10 +93,10 @@ public class OrderedPropertyIndexEditorP
     public void withIndexMultipleNodes() throws RepositoryException, 
CommitFailedException {
         final int threshold = 5;
         final int nodes = 16;
-        final int traces = nodes / threshold;
+        final int traces = 1 + (nodes - 1) / threshold;
         OrderedPropertyIndexEditorProvider.setThreshold(threshold);
-        final List<String> expected = Collections.nCopies(traces, 
OrderedIndex.DEPRECATION_MESSAGE); 
-        NodeBuilder root = InitialContent.INITIAL_CONTENT.builder();
+        final List<String> expected = Collections.nCopies(traces, 
DEPRECATION_MESSAGE);
+        NodeBuilder root = EMPTY_NODE.builder();
         createIndexDef(root);
 
         custom.starting();
@@ -107,4 +112,20 @@ public class OrderedPropertyIndexEditorP
         
assertFalse(root.getChildNode(INDEX_DEFINITIONS_NAME).getChildNode(indexName)
             .getChildNode(INDEX_CONTENT_NODE_NAME).exists());
     }
+
+    @Test
+    public void providerShouldBeAvailable() throws Exception {
+        CommitHook hook = new EditorHook(new IndexUpdateProvider(
+                new OrderedPropertyIndexEditorProvider(), null, true));
+
+        NodeBuilder root = EMPTY_NODE.builder();
+
+        createIndexDef(root).setProperty("reindex", false);
+
+        NodeState before = root.getNodeState();
+        root.child("foo");
+        NodeState after = root.getNodeState();
+
+        hook.processCommit(before, after, CommitInfo.EMPTY);
+    }
 }


Reply via email to