Author: chetanm
Date: Wed Nov 2 13:33:36 2016
New Revision: 1767677
URL: http://svn.apache.org/viewvc?rev=1767677&view=rev
Log:
OAK-4974 - Enable configuring QueryEngineSettings via OSGi config
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsService.java
(with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsServiceTest.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettings.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsMBeanImpl.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettings.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettings.java?rev=1767677&r1=1767676&r2=1767677&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettings.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettings.java
Wed Nov 2 13:33:36 2016
@@ -36,16 +36,20 @@ public class QueryEngineSettings impleme
public static final boolean SQL2_OPTIMIZATION_2 =
Boolean.parseBoolean(System.getProperty(SQL2_OPTIMISATION_FLAG_2,
"true"));
+ static final String OAK_QUERY_LIMIT_IN_MEMORY = "oak.queryLimitInMemory";
+
private static final int DEFAULT_QUERY_LIMIT_IN_MEMORY =
- Integer.getInteger("oak.queryLimitInMemory", Integer.MAX_VALUE);
-
+ Integer.getInteger(OAK_QUERY_LIMIT_IN_MEMORY, Integer.MAX_VALUE);
+
+ static final String OAK_QUERY_LIMIT_READS = "oak.queryLimitReads";
private static final int DEFAULT_QUERY_LIMIT_READS =
- Integer.getInteger("oak.queryLimitReads", Integer.MAX_VALUE);
-
+ Integer.getInteger(OAK_QUERY_LIMIT_READS, Integer.MAX_VALUE);
+
+ static final String OAK_QUERY_FAIL_TRAVERSAL = "oak.queryFailTraversal";
private static final boolean DEFAULT_FAIL_TRAVERSAL =
- Boolean.getBoolean("oak.queryFailTraversal");
-
- private static final boolean DEFAULT_FULL_TEXT_COMPARISON_WITHOUT_INDEX =
+ Boolean.getBoolean(OAK_QUERY_FAIL_TRAVERSAL);
+
+ private static final boolean DEFAULT_FULL_TEXT_COMPARISON_WITHOUT_INDEX =
Boolean.getBoolean("oak.queryFullTextComparisonWithoutIndex");
private long limitInMemory = DEFAULT_QUERY_LIMIT_IN_MEMORY;
@@ -105,4 +109,14 @@ public class QueryEngineSettings impleme
return sql2Optimisation;
}
+ @Override
+ public String toString() {
+ return "QueryEngineSettings{" +
+ "limitInMemory=" + limitInMemory +
+ ", limitReads=" + limitReads +
+ ", failTraversal=" + failTraversal +
+ ", fullTextComparisonWithoutIndex=" +
fullTextComparisonWithoutIndex +
+ ", sql2Optimisation=" + sql2Optimisation +
+ '}';
+ }
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsMBeanImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsMBeanImpl.java?rev=1767677&r1=1767676&r2=1767677&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsMBeanImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsMBeanImpl.java
Wed Nov 2 13:33:36 2016
@@ -96,4 +96,8 @@ public class QueryEngineSettingsMBeanImp
return settings;
}
+ @Override
+ public String toString() {
+ return settings.toString();
+ }
}
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsService.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsService.java?rev=1767677&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsService.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsService.java
Wed Nov 2 13:33:36 2016
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.query;
+
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.jackrabbit.oak.api.jmx.QueryEngineSettingsMBean;
+import org.apache.jackrabbit.oak.commons.PropertiesUtil;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+ policy = ConfigurationPolicy.REQUIRE,
+ metatype = true,
+ label = "Apache Jackrabbit Query Engine Settings Service",
+ description = "Various settings exposed by Oak QueryEngine. Note that
settings done by system property " +
+ "supersedes the one defined via OSGi config"
+)
+public class QueryEngineSettingsService {
+ private static final int DEFAULT_QUERY_LIMIT_IN_MEMORY = Integer.MAX_VALUE;
+ @Property(
+ intValue = DEFAULT_QUERY_LIMIT_IN_MEMORY,
+ label = "In memory limit",
+ description = "Maximum number of entries that can be held in
memory while evaluating any query"
+ )
+ static final String QUERY_LIMIT_IN_MEMORY = "queryLimitInMemory";
+ private static final int DEFAULT_QUERY_LIMIT_READS = Integer.MAX_VALUE;
+ @Property(
+ intValue = DEFAULT_QUERY_LIMIT_READS,
+ label = "In memory read limit",
+ description = "Maximum number of results which can be read by any
query"
+ )
+ static final String QUERY_LIMIT_READS = "queryLimitReads";
+ private static final boolean DEFAULT_QUERY_FAIL_TRAVERSAL = false;
+ @Property(
+ boolValue = DEFAULT_QUERY_FAIL_TRAVERSAL,
+ label = "Fail traversal",
+ description = "If enabled any query execution which results in
traversal would fail."
+ )
+ static final String QUERY_FAIL_TRAVERSAL = "queryFailTraversal";
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Reference
+ private QueryEngineSettingsMBean queryEngineSettings;
+
+ @Activate
+ private void activate(BundleContext context, Map<String, Object> config) {
+ if (System.getProperty(QueryEngineSettings.OAK_QUERY_LIMIT_IN_MEMORY)
== null) {
+ int queryLimitInMemory =
PropertiesUtil.toInteger(config.get(QUERY_LIMIT_IN_MEMORY),
+ DEFAULT_QUERY_LIMIT_IN_MEMORY);
+ queryEngineSettings.setLimitInMemory(queryLimitInMemory);
+ } else {
+ logMsg(QUERY_LIMIT_IN_MEMORY,
QueryEngineSettings.OAK_QUERY_LIMIT_IN_MEMORY);
+ }
+
+ if (System.getProperty(QueryEngineSettings.OAK_QUERY_LIMIT_READS) ==
null) {
+ int queryLimitReads =
PropertiesUtil.toInteger(config.get(QUERY_LIMIT_READS),
+ DEFAULT_QUERY_LIMIT_READS);
+ queryEngineSettings.setLimitReads(queryLimitReads);
+ } else {
+ logMsg(QUERY_LIMIT_IN_MEMORY,
QueryEngineSettings.OAK_QUERY_LIMIT_READS);
+ }
+
+ if (System.getProperty(QueryEngineSettings.OAK_QUERY_FAIL_TRAVERSAL)
== null) {
+ boolean failTraversal =
PropertiesUtil.toBoolean(config.get(QUERY_FAIL_TRAVERSAL),
+ DEFAULT_QUERY_FAIL_TRAVERSAL);
+ queryEngineSettings.setFailTraversal(failTraversal);
+ } else {
+ logMsg(QUERY_FAIL_TRAVERSAL,
QueryEngineSettings.OAK_QUERY_FAIL_TRAVERSAL);
+ }
+
+ log.info("Initialize QueryEngine settings {}", queryEngineSettings);
+ }
+
+ private void logMsg(String key, String sysPropKey) {
+ log.info("For {} using value {} defined via system property {}", key,
+ System.getProperty(sysPropKey), sysPropKey);
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsService.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsServiceTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsServiceTest.java?rev=1767677&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsServiceTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsServiceTest.java
Wed Nov 2 13:33:36 2016
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.query;
+
+import java.util.Map;
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+import org.apache.jackrabbit.oak.api.jmx.QueryEngineSettingsMBean;
+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;
+
+import static org.junit.Assert.*;
+
+public class QueryEngineSettingsServiceTest {
+ private static final String UNSET = "UNSET";
+ @Rule
+ public final OsgiContext context = new OsgiContext();
+
+ private final Set<String> sysPropNames = ImmutableSet.of(
+ QueryEngineSettings.OAK_QUERY_LIMIT_IN_MEMORY,
+ QueryEngineSettings.OAK_QUERY_LIMIT_READS,
+ QueryEngineSettings.OAK_QUERY_FAIL_TRAVERSAL
+ );
+
+ private QueryEngineSettingsService settingsService = new
QueryEngineSettingsService();
+ private Map<String, String> sysPropValues = Maps.newHashMap();
+
+ @Before
+ public void setUp(){
+ collectExistingValues();
+ }
+
+ @After
+ public void resetSysProps(){
+ for (Map.Entry<String, String> e : sysPropValues.entrySet()){
+ String value = e.getValue();
+ if (UNSET.equals(value)){
+ System.clearProperty(e.getKey());
+ } else {
+ System.setProperty(e.getKey(), e.getValue());
+ }
+ }
+ }
+
+ @Test
+ public void osgiConfig() throws Exception{
+ QueryEngineSettings settings = new QueryEngineSettings();
+ context.registerService(QueryEngineSettingsMBean.class, settings);
+
+ Map<String, Object> config = Maps.newHashMap();
+ config.put(QueryEngineSettingsService.QUERY_LIMIT_READS, 100);
+ config.put(QueryEngineSettingsService.QUERY_LIMIT_IN_MEMORY, 142);
+ config.put(QueryEngineSettingsService.QUERY_FAIL_TRAVERSAL, true);
+
+ context.registerInjectActivateService(settingsService, config);
+ assertEquals(100, settings.getLimitReads());
+ assertEquals(142, settings.getLimitInMemory());
+ assertTrue(settings.getFailTraversal());
+ }
+
+ @Test
+ public void sysPropSupercedes() throws Exception{
+ System.setProperty(QueryEngineSettings.OAK_QUERY_LIMIT_IN_MEMORY,
"10");
+ System.setProperty(QueryEngineSettings.OAK_QUERY_LIMIT_READS, "11");
+ System.setProperty(QueryEngineSettings.OAK_QUERY_FAIL_TRAVERSAL,
"false");
+
+ QueryEngineSettings settings = new QueryEngineSettings();
+ context.registerService(QueryEngineSettingsMBean.class, settings);
+
+ Map<String, Object> config = Maps.newHashMap();
+ config.put(QueryEngineSettingsService.QUERY_LIMIT_READS, 100);
+ config.put(QueryEngineSettingsService.QUERY_LIMIT_IN_MEMORY, 142);
+ config.put(QueryEngineSettingsService.QUERY_FAIL_TRAVERSAL, true);
+
+ context.registerInjectActivateService(settingsService, config);
+ assertEquals(11, settings.getLimitReads());
+ assertEquals(10, settings.getLimitInMemory());
+ assertFalse(settings.getFailTraversal());
+ }
+
+ private void collectExistingValues() {
+ for(String key : sysPropNames){
+ String value = System.getProperty(key);
+ if (value != null){
+ sysPropValues.put(key, value);
+ } else {
+ sysPropValues.put(key, UNSET);
+ }
+ }
+ }
+
+}
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryEngineSettingsServiceTest.java
------------------------------------------------------------------------------
svn:eol-style = native