You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kr...@apache.org on 2016/10/11 16:14:22 UTC
lucene-solr:master: SOLR-8969: Resolve NPE for SQLHandler when in
non-cloud mode
Repository: lucene-solr
Updated Branches:
refs/heads/master d25aba233 -> b00f10916
SOLR-8969: Resolve NPE for SQLHandler when in non-cloud mode
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b00f1091
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b00f1091
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b00f1091
Branch: refs/heads/master
Commit: b00f10916bfdcd1bdf138ba46a8204091e0bb428
Parents: d25aba2
Author: Kevin Risden <kr...@apache.org>
Authored: Fri May 27 13:17:23 2016 -0500
Committer: Kevin Risden <kr...@apache.org>
Committed: Tue Oct 11 11:13:47 2016 -0500
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +
.../org/apache/solr/handler/SQLHandler.java | 7 +-
.../solr/handler/TestSQLHandlerNonCloud.java | 92 ++++++++++++++++++++
3 files changed, 100 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b00f1091/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 271cec4..27939d6 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -265,6 +265,8 @@ Other Changes
* SOLR-8385: Narrow StreamFactory.withFunctionName clazz parameter to prevent misconfiguration (Jason Gerlowski, Kevin Risden)
+* SOLR-8969: SQLHandler causes NPE in non-cloud mode (Markus Jelsma, Kevin Risden)
+
================== 6.2.1 ==================
Bug Fixes
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b00f1091/solr/core/src/java/org/apache/solr/handler/SQLHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/SQLHandler.java b/solr/core/src/java/org/apache/solr/handler/SQLHandler.java
index f0240c6..5fcf938 100644
--- a/solr/core/src/java/org/apache/solr/handler/SQLHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/SQLHandler.java
@@ -88,6 +88,7 @@ public class SQLHandler extends RequestHandlerBase implements SolrCoreAware , Pe
}
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ static final String sqlNonCloudErrorMsg = "/sql handler only works in Solr Cloud mode";
public void inform(SolrCore core) {
@@ -111,7 +112,7 @@ public class SQLHandler extends RequestHandlerBase implements SolrCoreAware , Pe
String sql = params.get("stmt");
int numWorkers = params.getInt("numWorkers", 1);
String workerCollection = params.get("workerCollection", defaultWorkerCollection);
- String workerZkhost = params.get("workerZkhost",defaultZkhost);
+ String workerZkhost = params.get("workerZkhost", defaultZkhost);
String mode = params.get("aggregationMode", "map_reduce");
StreamContext context = new StreamContext();
@@ -120,6 +121,10 @@ public class SQLHandler extends RequestHandlerBase implements SolrCoreAware , Pe
try {
+ if(workerZkhost == null) {
+ throw new IllegalStateException(sqlNonCloudErrorMsg);
+ }
+
if(sql == null) {
throw new Exception("stmt parameter cannot be null");
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b00f1091/solr/core/src/test/org/apache/solr/handler/TestSQLHandlerNonCloud.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/TestSQLHandlerNonCloud.java b/solr/core/src/test/org/apache/solr/handler/TestSQLHandlerNonCloud.java
new file mode 100644
index 0000000..8623290
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/handler/TestSQLHandlerNonCloud.java
@@ -0,0 +1,92 @@
+/*
+ * 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.solr.handler;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.stream.SolrStream;
+import org.apache.solr.client.solrj.io.stream.TupleStream;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.IOUtils;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestSQLHandlerNonCloud extends SolrJettyTestBase {
+
+ private static File createSolrHome() throws Exception {
+ File workDir = createTempDir().toFile();
+ setupJettyTestHome(workDir, DEFAULT_TEST_COLLECTION_NAME);
+ return workDir;
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ File solrHome = createSolrHome();
+ solrHome.deleteOnExit();
+ createJetty(solrHome.getAbsolutePath());
+ }
+
+ @Test
+ public void testSQLHandler() throws Exception {
+ String sql = "select id, field_i, str_s from " + DEFAULT_TEST_COLLECTION_NAME + " limit 10";
+ SolrParams sParams = mapParams(CommonParams.QT, "/sql", "stmt", sql);
+ String url = jetty.getBaseUrl() + "/" + DEFAULT_TEST_COLLECTION_NAME;
+
+ SolrStream solrStream = new SolrStream(url, sParams);
+ try {
+ getTuples(solrStream);
+ fail(SQLHandler.sqlNonCloudErrorMsg);
+ } catch (IOException e) {
+ assertTrue(e.getMessage().contains(SQLHandler.sqlNonCloudErrorMsg));
+ }
+ }
+
+ private List<Tuple> getTuples(TupleStream tupleStream) throws IOException {
+ List<Tuple> tuples = new ArrayList<>();
+ try {
+ tupleStream.open();
+ for (; ; ) {
+ Tuple t = tupleStream.read();
+ if (t.EOF) {
+ break;
+ } else {
+ tuples.add(t);
+ }
+ }
+ } finally {
+ IOUtils.closeQuietly(tupleStream);
+ }
+ return tuples;
+ }
+
+ public static SolrParams mapParams(String... vals) {
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ assertEquals("Parameters passed in here must be in pairs!", 0, (vals.length % 2));
+ for (int idx = 0; idx < vals.length; idx += 2) {
+ params.add(vals[idx], vals[idx + 1]);
+ }
+
+ return params;
+ }
+}