You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by an...@apache.org on 2016/04/20 00:34:17 UTC

[1/3] lucene-solr:branch_5_5: SOLR-8578: Successful or not, requests are not always fully consumed by Solrj clients and we count on HttpClient or the JVM.

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_5_5 b72711173 -> 607e91cda


SOLR-8578: Successful or not, requests are not always fully consumed by Solrj clients and we count on HttpClient or the JVM.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/50ae1fff
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/50ae1fff
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/50ae1fff

Branch: refs/heads/branch_5_5
Commit: 50ae1fff7c0a18576c59ec672eb3b6b6ad921781
Parents: b727111
Author: markrmiller <ma...@apache.org>
Authored: Wed Feb 10 15:32:56 2016 -0500
Committer: anshum <an...@apache.org>
Committed: Tue Apr 19 14:12:48 2016 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 ++
 .../solrj/impl/ConcurrentUpdateSolrClient.java  |  4 +-
 .../solr/client/solrj/impl/HttpSolrClient.java  |  7 +---
 .../java/org/apache/solr/common/util/Utils.java | 41 ++++++++++++++++++++
 4 files changed, 48 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50ae1fff/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 16278ed..328fb3e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -60,6 +60,9 @@ Bug Fixes
 * SOLR-8983: Cleanup clusterstate and replicas for a failed create collection request
   (Varun Thacker, Anshum Gupta)
 
+* SOLR-8578: Successful or not, requests are not always fully consumed by Solrj clients and we
+  count on HttpClient or the JVM. (Mark Miller)
+
 ======================= 5.5.0 =======================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50ae1fff/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
index 9c3e1ab..4ef9360 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
@@ -23,7 +23,6 @@ import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.ContentProducer;
 import org.apache.http.entity.EntityTemplate;
-import org.apache.http.util.EntityUtils;
 import org.apache.solr.client.solrj.ResponseParser;
 import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.SolrRequest;
@@ -41,6 +40,7 @@ import org.apache.solr.common.util.ExecutorUtil;
 import org.apache.solr.common.util.IOUtils;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SolrjNamedThreadFactory;
+import org.apache.solr.common.util.Utils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
@@ -314,7 +314,7 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
         } finally {
           try {
             if (response != null) {
-              EntityUtils.consume(response.getEntity());
+              Utils.consumeFully(response.getEntity());
             }
           } catch (Exception e) {
             log.error("Error consuming and closing http response stream.", e);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50ae1fff/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
index d5a41ff..edad4a4 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
@@ -56,6 +56,7 @@ import org.apache.solr.common.util.ContentStream;
 import org.apache.solr.common.util.ExecutorUtil;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SolrjNamedThreadFactory;
+import org.apache.solr.common.util.Utils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
@@ -590,11 +591,7 @@ public class HttpSolrClient extends SolrClient {
           "IOException occured when talking to server at: " + getBaseURL(), e);
     } finally {
       if (shouldClose) {
-        try {
-          EntityUtils.consume(entity);
-        } catch (IOException e) {
-          log.error("Error consuming and closing http response stream.", e);
-        }
+        Utils.consumeFully(entity);
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50ae1fff/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
index c807dbe..03b8b2c 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
@@ -17,7 +17,9 @@
 package org.apache.solr.common.util;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.StringReader;
+import java.lang.invoke.MethodHandles;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -31,16 +33,22 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.http.HttpEntity;
+import org.apache.http.util.EntityUtils;
 import org.apache.solr.common.SolrException;
 import org.noggit.CharArr;
 import org.noggit.JSONParser;
 import org.noggit.JSONWriter;
 import org.noggit.ObjectBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static java.util.Collections.unmodifiableList;
 import static java.util.Collections.unmodifiableSet;
 
 public class Utils {
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+  
   public static Map getDeepCopy(Map map, int maxDepth) {
     return getDeepCopy(map, maxDepth, true);
   }
@@ -161,6 +169,39 @@ public class Utils {
 
     return false;
   }
+  
+  /**
+   * If the passed entity has content, make sure it is fully
+   * read and closed.
+   * 
+   * @param entity to consume or null
+   */
+  public static void consumeFully(HttpEntity entity) {
+    if (entity != null) {
+      try {
+        // make sure the stream is full read
+        readFully(entity.getContent());
+      } catch (UnsupportedOperationException e) {
+        // nothing to do then
+      } catch (IOException e) {
+        // quiet
+      } finally {
+        // close the stream
+        EntityUtils.consumeQuietly(entity);
+      }
+    }
+  }
+
+  /**
+   * Make sure the InputStream is fully read.
+   * 
+   * @param is to read
+   * @throws IOException on problem with IO
+   */
+  private static void readFully(InputStream is) throws IOException {
+    is.skip(is.available());
+    while (is.read() != -1) {}
+  }
 
   public static final Pattern ARRAY_ELEMENT_INDEX = Pattern
       .compile("(\\S*?)\\[(\\d+)\\]");


[2/3] lucene-solr:branch_5_5: SOLR-8683: Always consume the full request on the server, not just in the case of an error.

Posted by an...@apache.org.
SOLR-8683: Always consume the full request on the server, not just in the case of an error.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/39c53331
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/39c53331
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/39c53331

Branch: refs/heads/branch_5_5
Commit: 39c53331490ed60b90d9e78441d0be65221c319e
Parents: 50ae1ff
Author: markrmiller <ma...@apache.org>
Authored: Tue Feb 16 15:48:11 2016 -0500
Committer: anshum <an...@apache.org>
Committed: Tue Apr 19 14:12:59 2016 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |   3 +
 .../org/apache/solr/servlet/HttpSolrCall.java   |  29 +----
 .../apache/solr/servlet/SolrDispatchFilter.java | 107 +++++++++++--------
 3 files changed, 69 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/39c53331/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 328fb3e..88375ce 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -63,6 +63,9 @@ Bug Fixes
 * SOLR-8578: Successful or not, requests are not always fully consumed by Solrj clients and we
   count on HttpClient or the JVM. (Mark Miller)
 
+* SOLR-8683: Always consume the full request on the server, not just in the case of an error.
+ (Mark Miller)
+
 ======================= 5.5.0 =======================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/39c53331/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
index c50e5be..4288396 100644
--- a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
+++ b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
@@ -623,13 +623,9 @@ public class HttpSolrCall {
     } finally {
       try {
         if (exp != null) {
-          try {
-            SimpleOrderedMap info = new SimpleOrderedMap();
-            int code = ResponseUtils.getErrorInfo(ex, info, log);
-            sendError(code, info.toString());
-          } finally {
-            consumeInput(req);
-          }
+          SimpleOrderedMap info = new SimpleOrderedMap();
+          int code = ResponseUtils.getErrorInfo(ex, info, log);
+          sendError(code, info.toString());
         }
       } finally {
         if (core == null && localCore != null) {
@@ -644,21 +640,6 @@ public class HttpSolrCall {
       response.sendError(code, message);
     } catch (EOFException e) {
       log.info("Unable to write error response, client closed connection or we are shutting down", e);
-    } finally {
-      consumeInput(req);
-    }
-  }
-
-  // when we send back an error, we make sure we read
-  // the full client request so that the client does
-  // not hit a connection reset and we can reuse the 
-  // connection - see SOLR-8453
-  private void consumeInput(HttpServletRequest req) {
-    try {
-      ServletInputStream is = req.getInputStream();
-      while (!is.isFinished() && is.read() != -1) {}
-    } catch (IOException e) {
-      log.info("Could not consume full client request", e);
     }
   }
 
@@ -745,10 +726,6 @@ public class HttpSolrCall {
       //else http HEAD request, nothing to write out, waited this long just to get ContentType
     } catch (EOFException e) {
       log.info("Unable to write response, client closed connection or we are shutting down", e);
-    } finally {
-      if (solrRsp.getException() != null) {
-        consumeInput(req);
-      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/39c53331/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
index baab3eb..7a0e4ef 100644
--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
@@ -19,6 +19,7 @@ package org.apache.solr.servlet;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
 import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
@@ -185,58 +186,76 @@ public class SolrDispatchFilter extends BaseSolrFilter {
   
   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain, boolean retry) throws IOException, ServletException {
     if (!(request instanceof HttpServletRequest)) return;
+    try {
 
-    if (cores == null || cores.isShutDown()) {
-      log.error("Error processing the request. CoreContainer is either not initialized or shutting down.");
-      throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE,
-          "Error processing the request. CoreContainer is either not initialized or shutting down.");
-    }
+      if (cores == null || cores.isShutDown()) {
+        log.error("Error processing the request. CoreContainer is either not initialized or shutting down.");
+        throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE,
+            "Error processing the request. CoreContainer is either not initialized or shutting down.");
+      }
 
-    AtomicReference<ServletRequest> wrappedRequest = new AtomicReference<>();
-    if (!authenticateRequest(request, response, wrappedRequest)) { // the response and status code have already been sent
-      return;
-    }
-    if (wrappedRequest.get() != null) {
-      request = wrappedRequest.get();
-    }
-    if (cores.getAuthenticationPlugin() != null) {
-      log.debug("User principal: {}", ((HttpServletRequest)request).getUserPrincipal());
-    }
+      AtomicReference<ServletRequest> wrappedRequest = new AtomicReference<>();
+      if (!authenticateRequest(request, response, wrappedRequest)) { // the response and status code have already been
+                                                                     // sent
+        return;
+      }
+      if (wrappedRequest.get() != null) {
+        request = wrappedRequest.get();
+      }
+      if (cores.getAuthenticationPlugin() != null) {
+        log.debug("User principal: {}", ((HttpServletRequest) request).getUserPrincipal());
+      }
 
-    // No need to even create the HttpSolrCall object if this path is excluded.
-    if(excludePatterns != null) {
-      String requestPath = ((HttpServletRequest) request).getServletPath();
-      String extraPath = ((HttpServletRequest)request).getPathInfo();
-      if (extraPath != null) { // In embedded mode, servlet path is empty - include all post-context path here for testing 
-        requestPath += extraPath;
+      // No need to even create the HttpSolrCall object if this path is excluded.
+      if (excludePatterns != null) {
+        String requestPath = ((HttpServletRequest) request).getServletPath();
+        String extraPath = ((HttpServletRequest) request).getPathInfo();
+        if (extraPath != null) { // In embedded mode, servlet path is empty - include all post-context path here for
+                                 // testing
+          requestPath += extraPath;
+        }
+        for (Pattern p : excludePatterns) {
+          Matcher matcher = p.matcher(requestPath);
+          if (matcher.lookingAt()) {
+            chain.doFilter(request, response);
+            return;
+          }
+        }
       }
-      for (Pattern p : excludePatterns) {
-        Matcher matcher = p.matcher(requestPath);
-        if (matcher.lookingAt()) {
-          chain.doFilter(request, response);
-          return;
+
+      HttpSolrCall call = getHttpSolrCall((HttpServletRequest) request, (HttpServletResponse) response, retry);
+      ExecutorUtil.setServerThreadFlag(Boolean.TRUE);
+      try {
+        Action result = call.call();
+        switch (result) {
+          case PASSTHROUGH:
+            chain.doFilter(request, response);
+            break;
+          case RETRY:
+            doFilter(request, response, chain, true);
+            break;
+          case FORWARD:
+            request.getRequestDispatcher(call.getPath()).forward(request, response);
+            break;
         }
+      } finally {
+        call.destroy();
+        ExecutorUtil.setServerThreadFlag(null);
       }
+    } finally {
+      consumeInputFully((HttpServletRequest) request);
     }
-
-    HttpSolrCall call = getHttpSolrCall((HttpServletRequest) request, (HttpServletResponse) response, retry);
-    ExecutorUtil.setServerThreadFlag(Boolean.TRUE);
+  }
+  
+  // we make sure we read the full client request so that the client does
+  // not hit a connection reset and we can reuse the 
+  // connection - see SOLR-8453 and SOLR-8683
+  private void consumeInputFully(HttpServletRequest req) {
     try {
-      Action result = call.call();
-      switch (result) {
-        case PASSTHROUGH:
-          chain.doFilter(request, response);
-          break;
-        case RETRY:
-          doFilter(request, response, chain, true);
-          break;
-        case FORWARD:
-          request.getRequestDispatcher(call.getPath()).forward(request, response);
-          break;
-      }  
-    } finally {
-      call.destroy();
-      ExecutorUtil.setServerThreadFlag(null);
+      ServletInputStream is = req.getInputStream();
+      while (!is.isFinished() && is.read() != -1) {}
+    } catch (IOException e) {
+      log.info("Could not consume full client request", e);
     }
   }
   


[3/3] lucene-solr:branch_5_5: SOLR-8701: CloudSolrClient decides that there are no healthy nodes to handle a request too early.

Posted by an...@apache.org.
SOLR-8701: CloudSolrClient decides that there are no healthy nodes to handle a request too early.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/607e91cd
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/607e91cd
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/607e91cd

Branch: refs/heads/branch_5_5
Commit: 607e91cdab50af1168f5bc8b8785cfa77f1e55ea
Parents: 39c5333
Author: markrmiller <ma...@apache.org>
Authored: Fri Feb 19 08:02:12 2016 -0500
Committer: anshum <an...@apache.org>
Committed: Tue Apr 19 14:13:09 2016 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                       |  3 +++
 .../apache/solr/client/solrj/impl/CloudSolrClient.java | 13 +++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/607e91cd/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 88375ce..819e804 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -66,6 +66,9 @@ Bug Fixes
 * SOLR-8683: Always consume the full request on the server, not just in the case of an error.
  (Mark Miller)
 
+* SOLR-8701: CloudSolrClient decides that there are no healthy nodes to handle a request too early.
+  (Mark Miller)
+
 ======================= 5.5.0 =======================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/607e91cd/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
index 7b74966..c7e670c 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
@@ -1077,12 +1077,6 @@ public class CloudSolrClient extends SolrClient {
         theUrlList = new ArrayList<>(urlList.size());
         theUrlList.addAll(urlList);
       }
-      if(theUrlList.isEmpty()) {
-        for (String s : collectionNames) {
-          if(s!=null) collectionStateCache.remove(s);
-        }
-        throw new SolrException(SolrException.ErrorCode.INVALID_STATE, "Could not find a healthy node to handle the request.");
-      }
 
       Collections.shuffle(theUrlList, rand);
       if (sendToLeaders) {
@@ -1093,6 +1087,13 @@ public class CloudSolrClient extends SolrClient {
         theUrlList.addAll(theReplicas);
       }
       
+      if (theUrlList.isEmpty()) {
+        for (String s : collectionNames) {
+          if (s != null) collectionStateCache.remove(s);
+        }
+        throw new SolrException(SolrException.ErrorCode.INVALID_STATE,
+            "Could not find a healthy node to handle the request.");
+      }
     }
 
     LBHttpSolrClient.Req req = new LBHttpSolrClient.Req(request, theUrlList);