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 ca...@apache.org on 2019/08/04 06:02:50 UTC

svn commit: r1864357 - in /jackrabbit/oak/branches/1.8: ./ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/ oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/

Author: catholicon
Date: Sun Aug  4 06:02:50 2019
New Revision: 1864357

URL: http://svn.apache.org/viewvc?rev=1864357&view=rev
Log:
OAK-8114: IndexDefinitionBuilder should be smarter when to reindex while updating a definition (backport r1855522 from trunk)

Applying work done by Nitin Gupta at https://github.com/apache/jackrabbit-oak/pull/122. Thanks Nitin for the contribution.

Did a few more changes on top:
* check refresh only when reindex isn't required
* we had forgotten that index tags also don't require reindexing

Modified:
    jackrabbit/oak/branches/1.8/   (props changed)
    jackrabbit/oak/branches/1.8/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilder.java
    jackrabbit/oak/branches/1.8/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java

Propchange: jackrabbit/oak/branches/1.8/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Aug  4 06:02:50 2019
@@ -1,4 +1,4 @@
 /jackrabbit/oak/branches/1.0:1665962
 /jackrabbit/oak/branches/1.10:1854524
-/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821027,1821130,1821140-1821141,1821178,1821237,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821617,1821663,1821665,1821668,1821681,1821847,1821975-1821983,1822121,1822182,1822201,1822207,1822496,1822527,1822638,1822642,1822645,1822723,1822802,1822808,1822850,1822934,1823135,1823163,1823169,1823172,1823655,1823669,1824196,1824198,1824253,1824255,1824896,1824962,1825065,1825362,1825381,1825442,1825448,1825466,1825470-1825471,1825475,1825523,1825525,1825561,1825619-1825621,1825651,1825654,1825992,1826079,1826089-1826090,1826096,1826216,1826237,1826338,1826516,1826532,1826551,1826560,1826638,1826640,1826730,1826833,1826932,1826957,1827423,1827472,1827486,1827816,1827977,1828349,1828439,1828502,1828529,1828827,1828868,1828948,1829527,1829534,1829546,1829569,1829587,1829665,1829854,1829864,1829978,1829985,1829987,1829998,1830019,1830048
 ,1830160,1830171,1830197,1830209,1830239,1830347,1830748,1830911,1830923,1831157-1831158,1831163,1831190,1831374,1831560,1831689,1832258,1832376,1832379,1832535,1833308,1833347,1833702,1833833,1834109,1834112,1834117,1834287,1834291,1834302,1834312,1834326,1834328,1834336,1834428,1834468,1834483,1834610,1834648-1834649,1834681,1834823,1834857-1834858,1835056,1835060,1835062,1835518,1835521,1835635,1835642,1835780,1835819,1836082,1836121,1836167-1836168,1836170-1836187,1836189-1836196,1836206,1836487,1836493,1836548,1837057,1837274,1837296,1837326,1837475,1837503,1837547,1837569,1837596,1837600,1837657,1837718,1837998,1838076,1838637,1839549,1839570,1839637,1839746,1840019,1840024,1840031,1840226,1840455,1840462,1840574,1840769,1841314,1841352,1841909,1842089,1842240,1842677,1843175,1843222,1843231,1843398,1843618,1843621,1843637,1843652,1843669,1843905,1843911,1843994,1844070,1844110,1844325,1844549,1844625,1844627,1844642,1844728,1844775,1844932,1845135,1845336,1845405,1845415,1845
 730-1845731,1845863,1845865,1846057,1846162,1846396,1846429,1846486,1846581,1846617,1847088,1847096,1848073,1848181-1848182,1848191,1848217,1848729,1848769,1848822-1848823,1850221,1850319,1850343,1850837,1850874,1851533-1851535,1851619,1852120,1852135,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1853083,1853141,1853229,1853393,1853429,1853433,1853435,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854055,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854539,1854701,1854773-1854774,1854827,1854848,1854859,1854930,1855032,1855776,1855993,1856049,1856056,1856538,1856545,1856818,1857000,1857010,1857221,1857247,1857253,1857294,1857314,1857332,1857463,1857480,1857634,1857638,1857936,1858032,1858139,1858385,1858424,1858571,1858578,1858810,1858926,1859020,1859231,1859292,1859294,1859533,1859609,1859612,1859711,1859716,1859772,1859776,1859780,1859843,1859881,1860120,1860131,1860137,1860202,1860328,1860548,1
 860564-1860565,1861626,1862044,1862728,1862881
+/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821027,1821130,1821140-1821141,1821178,1821237,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821617,1821663,1821665,1821668,1821681,1821847,1821975-1821983,1822121,1822182,1822201,1822207,1822496,1822527,1822638,1822642,1822645,1822723,1822802,1822808,1822850,1822934,1823135,1823163,1823169,1823172,1823655,1823669,1824196,1824198,1824253,1824255,1824896,1824962,1825065,1825362,1825381,1825442,1825448,1825466,1825470-1825471,1825475,1825523,1825525,1825561,1825619-1825621,1825651,1825654,1825992,1826079,1826089-1826090,1826096,1826216,1826237,1826338,1826516,1826532,1826551,1826560,1826638,1826640,1826730,1826833,1826932,1826957,1827423,1827472,1827486,1827816,1827977,1828349,1828439,1828502,1828529,1828827,1828868,1828948,1829527,1829534,1829546,1829569,1829587,1829665,1829854,1829864,1829978,1829985,1829987,1829998,1830019,1830048
 ,1830160,1830171,1830197,1830209,1830239,1830347,1830748,1830911,1830923,1831157-1831158,1831163,1831190,1831374,1831560,1831689,1832258,1832376,1832379,1832535,1833308,1833347,1833702,1833833,1834109,1834112,1834117,1834287,1834291,1834302,1834312,1834326,1834328,1834336,1834428,1834468,1834483,1834610,1834648-1834649,1834681,1834823,1834857-1834858,1835056,1835060,1835062,1835518,1835521,1835635,1835642,1835780,1835819,1836082,1836121,1836167-1836168,1836170-1836187,1836189-1836196,1836206,1836487,1836493,1836548,1837057,1837274,1837296,1837326,1837475,1837503,1837547,1837569,1837596,1837600,1837657,1837718,1837998,1838076,1838637,1839549,1839570,1839637,1839746,1840019,1840024,1840031,1840226,1840455,1840462,1840574,1840769,1841314,1841352,1841909,1842089,1842240,1842677,1843175,1843222,1843231,1843398,1843618,1843621,1843637,1843652,1843669,1843905,1843911,1843994,1844070,1844110,1844325,1844549,1844625,1844627,1844642,1844728,1844775,1844932,1845135,1845336,1845405,1845415,1845
 730-1845731,1845863,1845865,1846057,1846162,1846396,1846429,1846486,1846581,1846617,1847088,1847096,1848073,1848181-1848182,1848191,1848217,1848729,1848769,1848822-1848823,1850221,1850319,1850343,1850837,1850874,1851533-1851535,1851619,1852120,1852135,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1853083,1853141,1853229,1853393,1853429,1853433,1853435,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854055,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854539,1854701,1854773-1854774,1854827,1854848,1854859,1854930,1855032,1855522,1855776,1855993,1856049,1856056,1856538,1856545,1856818,1857000,1857010,1857221,1857247,1857253,1857294,1857314,1857332,1857463,1857480,1857634,1857638,1857936,1858032,1858139,1858385,1858424,1858571,1858578,1858810,1858926,1859020,1859231,1859292,1859294,1859533,1859609,1859612,1859711,1859716,1859772,1859776,1859780,1859843,1859881,1860120,1860131,1860137,1860202,1860328,1
 860548,1860564-1860565,1861626,1862044,1862728,1862881
 /jackrabbit/trunk:1345480

Modified: jackrabbit/oak/branches/1.8/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilder.java?rev=1864357&r1=1864356&r2=1864357&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.8/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilder.java (original)
+++ jackrabbit/oak/branches/1.8/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilder.java Sun Aug  4 06:02:50 2019
@@ -19,6 +19,7 @@
 
 package org.apache.jackrabbit.oak.plugins.index.lucene.util;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -41,6 +42,7 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.ImmutableList.of;
 import static java.util.Arrays.asList;
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
@@ -137,7 +139,10 @@ public final class IndexDefinitionBuilde
     }
 
     public NodeState build(){
+        // make sure to check for reindex required before checking for refresh as refresh optimizes a bit using
+        // that assumption (we have tests that fail if the order is swapped btw)
         setReindexFlagIfRequired();
+        setRefreshFlagIfRequired();
         return builder.getNodeState();
     }
 
@@ -165,6 +170,16 @@ public final class IndexDefinitionBuilde
         }
     }
 
+    private void setRefreshFlagIfRequired() {
+        // Utilize the fact that reindex requirement is checked before checking for refresh
+        // It serves 2 purposes:
+        // * avoids setting up refresh if reindex is already set
+        // * avoid calling SelectiveEqualDiff#equal again
+        if (!isReindexRequired() && !initial.equals(builder.getNodeState())) {
+            tree.setProperty(LuceneIndexConstants.PROP_REFRESH_DEFN, true);
+        }
+    }
+
     private void setType() {
         PropertyState type = tree.getProperty(IndexConstants.TYPE_PROPERTY_NAME);
         if (type == null || !"disabled".equals(type.getValue(Type.STRING))) {
@@ -552,6 +567,20 @@ public final class IndexDefinitionBuilde
     }
 
     static class SelectiveEqualsDiff extends EqualsDiff {
+        // Properties for which changes shouldn't auto set the reindex flag
+        static final List<String> ignorablePropertiesList = of(
+                LuceneIndexConstants.PROP_WEIGHT,
+                FIELD_BOOST,
+                IndexConstants.QUERY_PATHS,
+                IndexConstants.INDEX_TAGS,
+                LuceneIndexConstants.BLOB_SIZE,
+                LuceneIndexConstants.COST_PER_ENTRY,
+                LuceneIndexConstants.COST_PER_EXECUTION);
+        static final List<String> ignorableFacetConfigProps = of(
+                LuceneIndexConstants.PROP_SECURE_FACETS,
+                LuceneIndexConstants.PROP_STATISTICAL_FACET_SAMPLE_SIZE,
+                LuceneIndexConstants.PROP_FACETS_TOP_CHILDREN);
+
         public static boolean equals(NodeState before, NodeState after) {
             return before.exists() == after.exists()
                     && after.compareAgainstBaseState(before, new SelectiveEqualsDiff());
@@ -563,10 +592,58 @@ public final class IndexDefinitionBuilde
                 Set<String> asyncBefore = getAsyncValuesWithoutNRT(before);
                 Set<String> asyncAfter = getAsyncValuesWithoutNRT(after);
                 return asyncBefore.equals(asyncAfter);
+            } else if (ignorablePropertiesList.contains(before.getName()) || ignorableFacetConfigProps.contains(before.getName())) {
+                return true;
             }
             return false;
         }
 
+        @Override
+        public boolean propertyAdded(PropertyState after) {
+            if(ignorablePropertiesList.contains(after.getName()) || ignorableFacetConfigProps.contains(after.getName())) {
+                return true;
+            }
+            return super.propertyAdded(after);
+        }
+
+        @Override
+        public boolean propertyDeleted(PropertyState before) {
+            if(ignorablePropertiesList.contains(before.getName()) || ignorableFacetConfigProps.contains(before.getName())) {
+                return true;
+            }
+            return super.propertyDeleted(before);
+        }
+
+        @Override
+        public boolean childNodeAdded(String name, NodeState after) {
+            if(name.equals(LuceneIndexConstants.PROP_FACETS)) {
+                // This here makes sure any new property under FACETS that might be added in future and if so might require
+                // reindexing - then addition of  facet node (/facet/foo) with such property lead to auto set of reindex flag
+                for(PropertyState property : after.getProperties()) {
+                    if(!ignorableFacetConfigProps.contains(property.getName())) {
+                        return super.childNodeAdded(name, after);
+                    }
+                }
+                return true;
+            }
+            return super.childNodeAdded(name, after);
+        }
+
+        @Override
+        public boolean childNodeDeleted(String name, NodeState before) {
+            if (name.equals(LuceneIndexConstants.PROP_FACETS)) {
+                // This here makes sure any new property under FACETS that might be added in future and if so might require
+                // reindexing - then deletion of facet node  with such property lead to auto set of reindex flag
+                for(PropertyState property : before.getProperties()) {
+                    if(!ignorableFacetConfigProps.contains(property.getName())) {
+                        return super.childNodeAdded(name, before);
+                    }
+                }
+                return true;
+            }
+            return super.childNodeDeleted(name, before);
+        }
+
         private Set<String> getAsyncValuesWithoutNRT(PropertyState state){
             Set<String> async = Sets.newHashSet(state.getValue(Type.STRINGS));
             async.remove(IndexConstants.INDEXING_MODE_NRT);

Modified: jackrabbit/oak/branches/1.8/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java?rev=1864357&r1=1864356&r2=1864357&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.8/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java (original)
+++ jackrabbit/oak/branches/1.8/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/IndexDefinitionBuilderTest.java Sun Aug  4 06:02:50 2019
@@ -36,12 +36,19 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.junit.After;
 import org.junit.Test;
 
+import static com.google.common.collect.ImmutableList.of;
 import static java.util.Arrays.asList;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.AGGREGATES;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.FIELD_BOOST;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PROP_FACETS;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PROP_REFRESH_DEFN;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.COST_PER_ENTRY;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.COST_PER_EXECUTION;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.BLOB_SIZE;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PROP_WEIGHT;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.apache.jackrabbit.oak.plugins.memory.MultiStringPropertyState.stringProperty;
 import static org.junit.Assert.*;
 
 public class IndexDefinitionBuilderTest {
@@ -215,6 +222,7 @@ public class IndexDefinitionBuilderTest
         assertFalse(builder.isReindexRequired());
         NodeState state = builder.build();
         assertFalse(state.getBoolean(REINDEX_PROPERTY_NAME));
+        assertFalse(state.getBoolean(PROP_REFRESH_DEFN));
 
 
         NodeState baseState = builder.build();
@@ -253,6 +261,507 @@ public class IndexDefinitionBuilderTest
     }
 
     @Test
+    public void noReindexWhenIfQueryPathsAddedOrChanged() {
+
+        NodeState currentNodeState = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.queryPaths("/a","/b");
+
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.queryPaths("/a","/c");
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().removeProperty(IndexConstants.QUERY_PATHS);
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+    }
+
+    @Test
+    public void noReindexWhenIfIndexTagsAddedOrChanged() {
+
+        NodeState currentNodeState = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().setProperty(stringProperty(IndexConstants.INDEX_TAGS, of("foo1", "foo2")));
+
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().setProperty(stringProperty(IndexConstants.INDEX_TAGS, of("foo2", "foo3")));
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().removeProperty(IndexConstants.INDEX_TAGS);
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+    }
+
+    @Test
+    public void noReindexWhenIfBlobSizeAddedOrChanged() {
+        NodeState currentNodeState = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().setProperty(BLOB_SIZE,32768);
+
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().setProperty(BLOB_SIZE,35768);
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().removeProperty(BLOB_SIZE);
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+    }
+
+    // This property is used in cost estimation - no reindexing required
+    // on property change
+    @Test
+    public void noReindexIfWeightPropertyAddedOrChanged() throws Exception {
+
+        builder.indexRule("nt:base").property("fooProp");
+
+        NodeState currentNodeState = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        //Unset the reindex flag first because first build would have set it .
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        // Add the property weight to fooProp - this shouldn't cause reindex flag to set
+        builder.indexRule("nt:base").property("fooProp").weight(10);
+
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+
+        // Now change the value for weight on fooProp - this also shouldn't lead to setting of reindex flag
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.indexRule("nt:base").property("fooProp").weight(20);
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        //Now check for property delete use case
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.indexRule("nt:base").property("fooProp").getBuilderTree().removeProperty(PROP_WEIGHT);
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+    }
+    // modifying boost value shouldn't require reindexing because we use
+    // QueryTime Boosts and not index time boosts. Refer OAK-3367 for details
+    @Test
+    public void noReindexIfBoostPropAddedOrChanged() throws  Exception {
+        builder.indexRule("nt:base").property("fooProp");
+
+        NodeState currentNodeState = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        //Unset the reindex flag first because first build would have set it .
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        // Add the property  boost - this shouldn't cause reindex flag to set
+        builder.indexRule("nt:base").property("fooProp").boost(1.0f);
+
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+
+        // Now change the value for boost - this also shouldn't lead to setting of reindex flag
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.indexRule("nt:base").property("fooProp").boost(2.0f);
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        //Now check for property delete use case
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.indexRule("nt:base").property("fooProp").getBuilderTree().removeProperty(FIELD_BOOST);
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+    }
+
+    // This is a node for configuration on how faceted search works
+    // Everything impacts querty time evauation - so no need of reindexing in case of changes
+    @Test
+    public void noReindexWhenFacetNodeAddedOrRemoved() throws Exception {
+        builder.indexRule("nt:base")
+                .property("foo1").facets();
+
+        NodeState currentNodeState  = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        //Unset the reindex flag first because first build would have set it .
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        //Add the facets child node now
+        builder.getBuilderTree().addChild(PROP_FACETS);
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        // Now test deleting the facets node should also not set the reindexing flag
+        nodeBuilder = currentNodeState.builder();
+
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().getChild(PROP_FACETS).remove();
+
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+    }
+
+    @Test
+    public void noReindexWhenFacetConfigChanged_topChildren() throws Exception {
+        builder.indexRule("nt:base")
+                .property("foo1").facets();
+
+        builder.getBuilderTree().addChild(PROP_FACETS);
+        NodeState currentNodeState  = builder.build();
+        nodeBuilder = currentNodeState.builder();
+        //Unset the reindex flag first because first build would have set it .
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        //Add top Children prop on facets node
+        builder.getBuilderTree().getChild(PROP_FACETS).setProperty(LuceneIndexConstants.PROP_FACETS_TOP_CHILDREN,100);
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+        nodeBuilder = currentNodeState.builder();
+
+        //Now test with changing the value - this too shouldn't set the reindexing flag
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().getChild(PROP_FACETS).setProperty(LuceneIndexConstants.PROP_FACETS_TOP_CHILDREN,200);
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        //Now check for property delete use case
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().getChild(PROP_FACETS).removeProperty(LuceneIndexConstants.PROP_FACETS_TOP_CHILDREN);
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+    }
+
+    @Test
+    public void noReindexWhenFacetConfigChanged_secure() throws Exception {
+        builder.indexRule("nt:base")
+                .property("foo1").facets();
+
+        builder.getBuilderTree().addChild(PROP_FACETS);
+
+        NodeState currentNodeState  = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        //Unset the reindex flag first because first build would have set it .
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        //Add top secure prop on facets node
+        builder.getBuilderTree().getChild(PROP_FACETS).setProperty(LuceneIndexConstants.PROP_SECURE_FACETS,LuceneIndexConstants.PROP_SECURE_FACETS_VALUE_SECURE);
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+
+        //Now test with changing the value - this too shouldn't set the reindexing flag
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().getChild(PROP_FACETS).setProperty(LuceneIndexConstants.PROP_SECURE_FACETS,LuceneIndexConstants.PROP_SECURE_FACETS_VALUE_INSECURE);
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+        //Now check for property delete use case
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().getChild(PROP_FACETS).removeProperty(LuceneIndexConstants.PROP_SECURE_FACETS);
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+    }
+
+    @Test
+    public void noReindexWhenFacetConfigChanged_sampleSize() throws Exception {
+        builder.indexRule("nt:base")
+                .property("foo1").facets();
+
+        builder.getBuilderTree().addChild(PROP_FACETS);
+
+        NodeState currentNodeState  = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        //Unset the reindex flag first because first build would have set it .
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        //Add top sample size prop on facets node
+        builder.getBuilderTree().getChild(PROP_FACETS).setProperty(LuceneIndexConstants.PROP_STATISTICAL_FACET_SAMPLE_SIZE,1000);
+        currentNodeState = builder.build();
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+
+        //Now test with changing the value - this too shouldn't set the reindexing flag
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().getChild(PROP_FACETS).setProperty(LuceneIndexConstants.PROP_STATISTICAL_FACET_SAMPLE_SIZE,2000);
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+        //Now check for property delete use case
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().getChild(PROP_FACETS).removeProperty(LuceneIndexConstants.PROP_STATISTICAL_FACET_SAMPLE_SIZE);
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+    }
+
+    @Test
+    public void noReindexWhenIfCostPerExecAddedOrChanged() {
+        builder.indexRule("nt:base");
+
+        NodeState currentNodeState = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        //Unset the reindex flag first because first build would have set it .
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().getChild("indexRules").getChild("nt:base").setProperty(COST_PER_EXECUTION, 2.0);
+        currentNodeState = builder.build();
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+
+        //Now test with changing the value - this too shouldn't set the reindexing flag
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().getChild("indexRules").getChild("nt:base").setProperty(COST_PER_EXECUTION, 3.0);
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        //Now check for property delete use case
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().getChild("indexRules").getChild("nt:base").removeProperty(COST_PER_EXECUTION);
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+    }
+
+    @Test
+    public void noReindexWhenIfCostPerEntryAddedOrChanged() {
+        builder.indexRule("nt:base");
+
+        NodeState currentNodeState = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        //Unset the reindex flag first because first build would have set it .
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().getChild("indexRules").getChild("nt:base").setProperty(COST_PER_ENTRY, 2.0);
+        currentNodeState = builder.build();
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+
+        //Now test with changing the value - this too shouldn't set the reindexing flag
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().getChild("indexRules").getChild("nt:base").setProperty(COST_PER_ENTRY, 3.0);
+        currentNodeState = builder.build();
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        //Now check for property delete use case
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().getChild("indexRules").getChild("nt:base").removeProperty(COST_PER_ENTRY);
+        currentNodeState = builder.build();
+
+        assertFalse(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertTrue(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+    }
+
+    @Test
+    public void reindexFlagSetWhenRequired() {
+
+        NodeState currentNodeState = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.includedPaths("/a", "/b");
+
+        currentNodeState = builder.build();
+        assertTrue(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.includedPaths("/a", "/c");
+        currentNodeState = builder.build();
+        assertTrue(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+        builder.getBuilderTree().removeProperty(PathFilter.PROP_INCLUDED_PATHS);
+        currentNodeState = builder.build();
+
+        assertTrue(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+    }
+
+    @Test
+    public void renidexIfFacetsNodeAddedwithSomeNewPropThatReqIndexing() throws Exception {
+        builder.indexRule("nt:base")
+                .property("foo1").facets();
+
+        NodeState currentNodeState  = builder.build();
+        nodeBuilder = currentNodeState.builder();
+
+        //Unset the reindex flag first because first build would have set it .
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().addChild(PROP_FACETS);
+
+        //Add foo prop on facets node
+        builder.getBuilderTree().getChild(PROP_FACETS).setProperty("foo","bar");
+        currentNodeState = builder.build();
+
+        assertTrue(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertFalse(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+        nodeBuilder = currentNodeState.builder();
+
+        //Now test with changing the value - this too should set the reindexing flag
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().getChild(PROP_FACETS).setProperty("foo","bar2");
+        currentNodeState = builder.build();
+        assertTrue(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertFalse(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        //now deleting the node
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.removeProperty(PROP_REFRESH_DEFN);
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().getChild(PROP_FACETS).remove();
+        currentNodeState = builder.build();
+        assertTrue(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertFalse(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+        nodeBuilder = currentNodeState.builder();
+        nodeBuilder.setProperty(REINDEX_PROPERTY_NAME, false);
+        builder = new IndexDefinitionBuilder(nodeBuilder);
+
+        builder.getBuilderTree().addChild(PROP_FACETS);
+
+        //Add foo prop on facets node
+        builder.getBuilderTree().getChild(PROP_FACETS).setProperty("foo","bar");
+        builder.getBuilderTree().getChild(PROP_FACETS).setProperty(LuceneIndexConstants.PROP_STATISTICAL_FACET_SAMPLE_SIZE,200);
+
+        currentNodeState = builder.build();
+        assertTrue(currentNodeState.getBoolean(REINDEX_PROPERTY_NAME));
+        assertFalse(currentNodeState.getBoolean(PROP_REFRESH_DEFN));
+
+    }
+
+    @Test
     public void propRuleCustomName() throws Exception{
         builder.indexRule("nt:base").property("foo").property("bar");
         builder.indexRule("nt:base").property("fooProp", "foo2");