gus-asf commented on a change in pull request #265:
URL: https://github.com/apache/solr/pull/265#discussion_r694823001



##########
File path: solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
##########
@@ -438,147 +170,88 @@ public void doFilter(ServletRequest _request, 
ServletResponse _response, FilterC
     HttpServletRequest request = closeShield((HttpServletRequest)_request, 
retry);
     HttpServletResponse response = closeShield((HttpServletResponse)_response, 
retry);
 
-    String requestPath = ServletUtils.getPathAfterContext(request);
-    // No need to even create the HttpSolrCall object if this path is excluded.
-    if (excludePatterns != null) {
-      for (Pattern p : excludePatterns) {
-        Matcher matcher = p.matcher(requestPath);
-        if (matcher.lookingAt()) {
-          chain.doFilter(request, response);
-          return;
-        }
-      }
+    if (excludedPath(excludePatterns, request, response, chain)) {
+      return;
     }
-
-    Tracer tracer = cores == null ? GlobalTracer.get() : cores.getTracer();
-    Span span = buildSpan(tracer, request);
-    request.setAttribute(Tracer.class.getName(), tracer);
-    request.setAttribute(Span.class.getName(), span);
-    boolean accepted = false;
-    try (var scope = tracer.scopeManager().activate(span)) {
-      assert scope != null; // prevent javac warning about scope being unused
-
-      if (cores == null || cores.isShutDown()) {
-        try {
-          init.await();
-        } catch (InterruptedException e) { //well, no wait then
-        }
-        final String msg = "Error processing the request. CoreContainer is 
either not initialized or shutting down.";
-        if (cores == null || cores.isShutDown()) {
-          log.error(msg);
-          throw new UnavailableException(msg);
-        }
-      }
-
+    Tracer t = getCores() == null ? GlobalTracer.get() : 
getCores().getTracer();
+    request.setAttribute(Tracer.class.getName(), t);
+    RateLimitManager rateLimitManager = 
coreService.getService().getRateLimitManager();
+    request.setAttribute(RateLimitManager.class.getName(), rateLimitManager);
+    ServletUtils.rateLimitRequest(request, response, () -> {
       try {
-        accepted = rateLimitManager.handleRequest(request);
-      } catch (InterruptedException e) {
-        Thread.currentThread().interrupt();
-        throw new SolrException(ErrorCode.SERVER_ERROR, e.getMessage());
+        dispatch(chain, request, response, retry);
+      } catch (IOException | ServletException | SolrAuthenticationException e) 
{
+        throw new ExceptionWhileTracing( e);
       }
+    }, true);
+  }
 
-      if (!accepted) {
-        String errorMessage = "Too many requests for this request type." +
-            "Please try after some time or increase the quota for this request 
type";
-
-        response.sendError(429, errorMessage);
-      }
+  private static Span getSpan(HttpServletRequest req) {
+    return (Span) req.getAttribute(ATTR_TRACING_SPAN);
+  }
 
-      AtomicReference<HttpServletRequest> wrappedRequest = new 
AtomicReference<>();
-      if (!authenticateRequest(request, response, wrappedRequest)) { // the 
response and status code have already been sent
-        return;
-      }
+  private void dispatch(FilterChain chain, HttpServletRequest request, 
HttpServletResponse response, boolean retry) throws IOException, 
ServletException, SolrAuthenticationException {
 
-      if (wrappedRequest.get() != null) {
-        request = wrappedRequest.get();
-      }
 
-      if (cores.getAuthenticationPlugin() != null) {
-        if (log.isDebugEnabled()) {
-          log.debug("User principal: {}", request.getUserPrincipal());
-        }
-        span.setTag(Tags.DB_USER, String.valueOf(request.getUserPrincipal()));
-      }
 
-      HttpSolrCall call = getHttpSolrCall(request, response, retry);
-      ExecutorUtil.setServerThreadFlag(Boolean.TRUE);
-      try {
-        Action result = call.call();
-        switch (result) {
-          case PASSTHROUGH:
-            span.log("SolrDispatchFilter PASSTHROUGH");
-            chain.doFilter(request, response);
-            break;
-          case RETRY:
-            span.log("SolrDispatchFilter RETRY");
-            doFilter(request, response, chain, true); // RECURSION
-            break;
-          case FORWARD:
-            span.log("SolrDispatchFilter FORWARD");
-            request.getRequestDispatcher(call.getPath()).forward(request, 
response);
-            break;
-          case ADMIN:
-          case PROCESS:
-          case REMOTEQUERY:
-          case RETURN:
-            break;
-        }
-      } finally {
-        call.destroy();
-        ExecutorUtil.setServerThreadFlag(null);
-      }
-    } finally {
-      consumeInputFully(request, response);
-      SolrRequestInfo.reset();
-      SolrRequestParsers.cleanupMultipartFiles(request);
-
-      if (accepted) {
-        rateLimitManager.decrementActiveRequests(request);
-      }
-      span.setTag(Tags.HTTP_STATUS, response.getStatus());
-      span.finish();
+    AtomicReference<HttpServletRequest> wrappedRequest = new 
AtomicReference<>();
+    if (!authenticateRequest(request, response, wrappedRequest)) { // the 
response and status code have already been sent

Review comment:
       actually... I should probably just throw from the method and return the 
request. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to