lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r1607899 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/handler/component/ solr/core/src/java/org/apache/solr/util/ solr/core/src/test-files/solr/collection1/conf/ solr/core/src/test/org/apache/s...
Date Fri, 04 Jul 2014 17:56:39 GMT
Author: shalin
Date: Fri Jul  4 17:56:38 2014
New Revision: 1607899

URL: http://svn.apache.org/r1607899
Log:
SOLR-6223: SearchComponents may throw NPE when using shards.tolerant and there is a failure
in the 'GET_FIELDS/GET_HIGHLIGHTS/GET_DEBUG' phase

Added:
    lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-tolerant-search.xml
      - copied unchanged from r1607897, lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-tolerant-search.xml
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/TestTolerantSearch.java
      - copied unchanged from r1607897, lucene/dev/trunk/solr/core/src/test/org/apache/solr/TestTolerantSearch.java
Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/HighlightComponent.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1607899&r1=1607898&r2=1607899&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Fri Jul  4 17:56:38 2014
@@ -84,6 +84,9 @@ Bug Fixes
 * SOLR-6159: A ZooKeeper session expiry during setup can keep LeaderElector from joining
elections.
   (Steven Bower, shalin)
 
+* SOLR-6223: SearchComponents may throw NPE when using shards.tolerant and there is a failure
+  in the 'GET_FIELDS/GET_HIGHLIGHTS/GET_DEBUG' phase. (Tomás Fernández Löbbe via
shalin)
+
 Other Changes
 ---------------------
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java?rev=1607899&r1=1607898&r2=1607899&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
Fri Jul  4 17:56:38 2014
@@ -230,7 +230,7 @@ public class DebugComponent extends Sear
       }
 
       if (rb.isDebugResults()) {
-        explain = SolrPluginUtils.removeNulls(new SimpleOrderedMap<>(arr));
+         explain = SolrPluginUtils.removeNulls(arr, new SimpleOrderedMap<>());
       }
 
       if (!hasGetDebugResponses) {

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/HighlightComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/HighlightComponent.java?rev=1607899&r1=1607898&r2=1607899&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/HighlightComponent.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/HighlightComponent.java
Fri Jul  4 17:56:38 2014
@@ -182,6 +182,11 @@ public class HighlightComponent extends 
       for (ShardRequest sreq : rb.finished) {
         if ((sreq.purpose & ShardRequest.PURPOSE_GET_HIGHLIGHTS) == 0) continue;
         for (ShardResponse srsp : sreq.responses) {
+          if (srsp.getException() != null) {
+            // can't expect the highlight content if there was an exception for this request
+            // this should only happen when using shards.tolerant=true
+            continue;
+          }
           NamedList hl = (NamedList)srsp.getSolrResponse().getResponse().get("highlighting");
           for (int i=0; i<hl.size(); i++) {
             String id = hl.getName(i);
@@ -193,7 +198,7 @@ public class HighlightComponent extends 
       }
 
       // remove nulls in case not all docs were able to be retrieved
-      rb.rsp.add("highlighting", SolrPluginUtils.removeNulls(new SimpleOrderedMap(arr)));
     
+      rb.rsp.add("highlighting", SolrPluginUtils.removeNulls(arr, new SimpleOrderedMap<Object>()));
     
     }
   }
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java?rev=1607899&r1=1607898&r2=1607899&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java
Fri Jul  4 17:56:38 2014
@@ -133,6 +133,10 @@ public class MoreLikeThisComponent exten
         && rb.req.getParams().getBool(COMPONENT_NAME, false)) {
       log.debug("ShardRequest.response.size: " + sreq.responses.size());
       for (ShardResponse r : sreq.responses) {
+        if (r.getException() != null) {
+          // This should only happen in case of using shards.tolerant=true. Omit this ShardResponse
+          continue;
+        }
         NamedList<?> moreLikeThisReponse = (NamedList<?>) r.getSolrResponse()
             .getResponse().get("moreLikeThis");
         log.debug("ShardRequest.response.shard: " + r.getShard());

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java?rev=1607899&r1=1607898&r2=1607899&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
Fri Jul  4 17:56:38 2014
@@ -55,7 +55,6 @@ import org.apache.solr.common.SolrDocume
 import org.apache.solr.common.SolrDocumentList;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.*;
-import org.apache.solr.common.params.CursorMarkParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.common.util.StrUtils;
@@ -1064,7 +1063,9 @@ public class QueryComponent extends Sear
       populateNextCursorMarkFromMergedShards(rb);
 
       if (partialResults) {
-        rb.rsp.getResponseHeader().add( "partialResults", Boolean.TRUE );
+        if(rb.rsp.getResponseHeader().get("partialResults") == null) {
+          rb.rsp.getResponseHeader().add("partialResults", Boolean.TRUE);
+        }
       }
   }
 
@@ -1227,6 +1228,28 @@ public class QueryComponent extends Sear
       boolean removeKeyField = !rb.rsp.getReturnFields().wantsField(keyFieldName);
 
       for (ShardResponse srsp : sreq.responses) {
+        if (srsp.getException() != null) {
+          // Don't try to get the documents if there was an exception in the shard
+          if(rb.req.getParams().getBool(ShardParams.SHARDS_INFO, false)) {
+            @SuppressWarnings("unchecked")
+            NamedList<Object> shardInfo = (NamedList<Object>) rb.rsp.getValues().get(ShardParams.SHARDS_INFO);
+            @SuppressWarnings("unchecked")
+            SimpleOrderedMap<Object> nl = (SimpleOrderedMap<Object>) shardInfo.get(srsp.getShard());
+            if (nl.get("error") == null) {
+              // Add the error to the shards info section if it wasn't added before
+              Throwable t = srsp.getException();
+              if(t instanceof SolrServerException) {
+                t = ((SolrServerException)t).getCause();
+              }
+              nl.add("error", t.toString() );
+              StringWriter trace = new StringWriter();
+              t.printStackTrace(new PrintWriter(trace));
+              nl.add("trace", trace.toString() );
+            }
+          }
+          
+          continue;
+        }
         SolrDocumentList docs = (SolrDocumentList) srsp.getSolrResponse().getResponse().get("response");
 
         for (SolrDocument doc : docs) {

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java?rev=1607899&r1=1607898&r2=1607899&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java
Fri Jul  4 17:56:38 2014
@@ -425,7 +425,7 @@ public class TermVectorComponent extends
   public void finishStage(ResponseBuilder rb) {
     if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
       
-      NamedList termVectors = new NamedList<>();
+      NamedList<Object> termVectors = new NamedList<>();
       Map.Entry<String, Object>[] arr = new NamedList.NamedListEntry[rb.resultIds.size()];
 
       for (ShardRequest sreq : rb.finished) {
@@ -450,7 +450,7 @@ public class TermVectorComponent extends
         }
       }
       // remove nulls in case not all docs were able to be retrieved
-      termVectors.addAll(SolrPluginUtils.removeNulls(new NamedList<>(arr)));
+      termVectors.addAll(SolrPluginUtils.removeNulls(arr, new NamedList<Object>()));
       rb.rsp.add(TERM_VECTORS, termVectors);
     }
   }

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java?rev=1607899&r1=1607898&r2=1607899&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
Fri Jul  4 17:56:38 2014
@@ -702,21 +702,25 @@ public class SolrPluginUtils {
     }
     return s.toString().replace("\"","");
   }
-
-  public static NamedList removeNulls(NamedList nl) {
-    for (int i=0; i<nl.size(); i++) {
-      if (nl.getName(i)==null) {
-        NamedList newList = nl instanceof SimpleOrderedMap ? new SimpleOrderedMap() : new
NamedList();
-        for (int j=0; j<nl.size(); j++) {
-          String n = nl.getName(j);
-          if (n != null) {
-            newList.add(n, nl.getVal(j));
-          }
+  
+  /**
+   * Adds to {@code dest} all the not-null elements of {@code entries} that have non-null
names
+   * 
+   * @param entries The array of entries to be added to the {@link NamedList} {@code dest}
+   * @param dest The {@link NamedList} instance where the not-null elements of entries are
added
+   * @return Returns The {@code dest} input object
+   */
+  public static <T> NamedList<T> removeNulls(Map.Entry<String, T>[] entries,
NamedList<T> dest) {
+    for (int i=0; i<entries.length; i++) {
+      Map.Entry<String, T> entry = entries[i];
+      if (entry != null) {
+        String key = entry.getKey();
+        if (key != null) {
+          dest.add(key, entry.getValue());
         }
-        return newList;
       }
     }
-    return nl;
+    return dest;
   }
 
   /**



Mime
View raw message