Author: chetanm
Date: Thu Dec 8 05:18:46 2016
New Revision: 1773183
URL: http://svn.apache.org/viewvc?rev=1773183&view=rev
Log:
OAK-4400 - Correlate index with the index definition used to build it
-- Incorporated feedback from Alex around logging
-- Moved the feature flag to OSGi config
-- Added testcase for feature flag
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderServiceTest.java
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java?rev=1773183&r1=1773182&r2=1773183&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
Thu Dec 8 05:18:46 2016
@@ -99,15 +99,7 @@ public final class IndexDefinition imple
private static final Logger log =
LoggerFactory.getLogger(IndexDefinition.class);
- public static final boolean DISABLE_STORED_INDEX_DEFINITION =
- Boolean.getBoolean("oak.lucene.disableStoredIndexDefinition");
-
- static {
- if (DISABLE_STORED_INDEX_DEFINITION){
- log.info("Feature to ensure that index definition match the index
state is set to be disabled. Change in " +
- "index definition would now effect query plans and might
lead to inconsistent results");
- }
- }
+ private static boolean disableStoredIndexDefinition;
/**
* Default number of seconds after which to delete actively. Default is
-1, meaning disabled.
@@ -544,6 +536,14 @@ public final class IndexDefinition imple
return false;
}
+ public static boolean isDisableStoredIndexDefinition() {
+ return disableStoredIndexDefinition;
+ }
+
+ public static void setDisableStoredIndexDefinition(boolean
disableStoredIndexDefinitionDefault) {
+ IndexDefinition.disableStoredIndexDefinition =
disableStoredIndexDefinitionDefault;
+ }
+
@Override
public String toString() {
return "Lucene Index : " + indexName;
@@ -1695,7 +1695,7 @@ public final class IndexDefinition imple
}
private static NodeState getIndexDefinitionState(NodeState defn) {
- if (DISABLE_STORED_INDEX_DEFINITION){
+ if (isDisableStoredIndexDefinition()){
return defn;
}
NodeState storedState = defn.getChildNode(INDEX_DEFINITION_NODE);
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java?rev=1773183&r1=1773182&r2=1773183&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java
Thu Dec 8 05:18:46 2016
@@ -194,7 +194,7 @@ public class LuceneIndexEditorContext {
//as index definition does not get modified as part of IndexUpdate run
in most case we rely on base state
//For case where index definition is rewritten there we get fresh state
NodeState defnState = indexDefnRewritten ?
definitionBuilder.getNodeState() : definitionBuilder.getBaseState();
- if (!IndexDefinition.DISABLE_STORED_INDEX_DEFINITION) {
+ if (!IndexDefinition.isDisableStoredIndexDefinition()) {
definitionBuilder.setChildNode(IndexDefinition.INDEX_DEFINITION_NODE,
NodeStateCloner.cloneVisibleState(defnState));
}
String uid = configureUniqueId(definitionBuilder);
@@ -283,7 +283,7 @@ public class LuceneIndexEditorContext {
private static IndexDefinition createIndexDefinition(NodeState root,
NodeBuilder definition, IndexingContext
indexingContext, boolean asyncIndexing) {
NodeState defnState = definition.getBaseState();
- if (asyncIndexing){
+ if (asyncIndexing &&
!IndexDefinition.isDisableStoredIndexDefinition()){
if (definition.getBoolean(LuceneIndexConstants.PROP_REFRESH_DEFN)){
definition.removeProperty(LuceneIndexConstants.PROP_REFRESH_DEFN);
NodeState clonedState =
NodeStateCloner.cloneVisibleState(defnState);
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java?rev=1773183&r1=1773182&r2=1773183&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java
Thu Dec 8 05:18:46 2016
@@ -213,6 +213,16 @@ public class LuceneIndexProviderService
)
private static final String PROP_HYBRID_QUEUE_SIZE = "hybridQueueSize";
+ private static final boolean PROP_DISABLE_DEFN_STORAGE_DEFAULT = false;
+ @Property(
+ boolValue = PROP_DISABLE_DEFN_STORAGE_DEFAULT,
+ label = "Disable index definition storage",
+ description = "By default index definitions would be stored at
time of reindexing to ensure that future " +
+ "modifications to it are not effective untill index is
reindex. Set this to true would disable " +
+ "this feature"
+ )
+ private static final String PROP_DISABLE_STORED_INDEX_DEFINITION =
"disableStoredIndexDefinition";
+
private Whiteboard whiteboard;
private BackgroundObserver backgroundObserver;
@@ -270,6 +280,7 @@ public class LuceneIndexProviderService
return;
}
+ configureIndexDefinitionStorage(config);
configureBooleanClauseLimit(config);
initializeFactoryClassLoaders(getClass().getClassLoader());
@@ -575,6 +586,16 @@ public class LuceneIndexProviderService
}
}
+ private void configureIndexDefinitionStorage(Map<String, ?> config) {
+ boolean disableStorage =
PropertiesUtil.toBoolean(config.get(PROP_DISABLE_STORED_INDEX_DEFINITION),
+ PROP_DISABLE_DEFN_STORAGE_DEFAULT);
+ if (disableStorage){
+ log.info("Feature to ensure that index definition matches the
index state is disabled. Change in " +
+ "index definition would now affect query plans and might
lead to inconsistent results.");
+ IndexDefinition.setDisableStoredIndexDefinition(disableStorage);
+ }
+ }
+
private void registerGCMonitor(Whiteboard whiteboard,
final IndexTracker tracker) {
GCMonitor gcMonitor = new GCMonitor.Empty() {
Modified:
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderServiceTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderServiceTest.java?rev=1773183&r1=1773182&r2=1773183&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderServiceTest.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderServiceTest.java
Thu Dec 8 05:18:46 2016
@@ -52,6 +52,7 @@ import org.apache.lucene.search.BooleanQ
import org.apache.lucene.util.InfoStream;
import org.apache.sling.testing.mock.osgi.MockOsgi;
import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -81,6 +82,11 @@ public class LuceneIndexProviderServiceT
MockOsgi.injectServices(service, context.bundleContext());
}
+ @After
+ public void after(){
+ IndexDefinition.setDisableStoredIndexDefinition(false);
+ }
+
@Test
public void defaultSetup() throws Exception{
MockOsgi.activate(service, context.bundleContext(),
getDefaultConfig());
@@ -96,6 +102,7 @@ public class LuceneIndexProviderServiceT
IndexCopier indexCopier = service.getIndexCopier();
assertNotNull("IndexCopier should be initialized as CopyOnRead is
enabled by default", indexCopier);
assertTrue(indexCopier.isPrefetchEnabled());
+ assertFalse(IndexDefinition.isDisableStoredIndexDefinition());
assertNotNull("CopyOnRead should be enabled by default",
context.getService(CopyOnReadStatsMBean.class));
assertNotNull(context.getService(CacheStatsMBean.class));
@@ -219,6 +226,16 @@ public class LuceneIndexProviderServiceT
}
@Test
+ public void indexDefnStorafe() throws Exception{
+ Map<String,Object> config = getDefaultConfig();
+ config.put("disableStoredIndexDefinition", true);
+ MockOsgi.activate(service, context.bundleContext(), config);
+
+ assertTrue(IndexDefinition.isDisableStoredIndexDefinition());
+ }
+
+
+ @Test
public void blobStoreRegistered() throws Exception{
MockOsgi.activate(service, context.bundleContext(),
getDefaultConfig());
LuceneIndexEditorProvider editorProvider =
Modified:
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java?rev=1773183&r1=1773182&r2=1773183&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
(original)
+++
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
Thu Dec 8 05:18:46 2016
@@ -167,6 +167,7 @@ public class LucenePropertyIndexTest ext
@After
public void after() {
new ExecutorCloser(executorService).close();
+ IndexDefinition.setDisableStoredIndexDefinition(false);
}
@Override
@@ -2522,7 +2523,24 @@ public class LucenePropertyIndexTest ext
//Definition state should be recreated
assertTrue(NodeStateUtils.getNode(nodeStore.getRoot(),
clonedDefnPath).exists());
+ }
+
+ @Test
+ public void disableIndexDefnStorage() throws Exception{
+ IndexDefinition.setDisableStoredIndexDefinition(true);
+
+ IndexDefinitionBuilder idxb = new IndexDefinitionBuilder().noAsync();
+ idxb.indexRule("nt:base").property("foo").propertyIndex();
+ Tree idx = root.getTree("/").getChild("oak:index").addChild("test1");
+ idxb.build(idx);
+ Tree rootTree = root.getTree("/");
+ rootTree.addChild("a").setProperty("foo", "bar");
+ rootTree.addChild("b").setProperty("bar", "bar");
+ root.commit();
+
+ String clonedDefnPath = "/oak:index/test1/" + INDEX_DEFINITION_NODE;
+ assertFalse(NodeStateUtils.getNode(nodeStore.getRoot(),
clonedDefnPath).exists());
}
private void assertPlanAndQuery(String query, String planExpectation,
List<String> paths){