[GitHub] [lucene-solr] dsmiley commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-06-04 Thread GitBox


dsmiley commented on a change in pull request #1527:
URL: https://github.com/apache/lucene-solr/pull/1527#discussion_r435405488



##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -52,35 +56,60 @@
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static SolrRequestInfo getRequestInfo() {
-return threadLocal.get();
+Deque stack = threadLocal.get();
+if (stack.isEmpty()) return null;
+return stack.peek();
   }
 
+  /** Adds the SolrRequestInfo onto the stack provided that the stack is not 
reached MAX_STACK_SIZE */
   public static void setRequestInfo(SolrRequestInfo info) {
-// TODO: temporary sanity check... this can be changed to just an assert 
in the future
-SolrRequestInfo prev = threadLocal.get();
-if (prev != null) {
-  log.error("Previous SolrRequestInfo was not closed!  req={}", 
prev.req.getOriginalParams());
-  log.error("prev == info : {}", prev.req == info.req, new 
RuntimeException());
+Deque stack = threadLocal.get();
+if (info == null) {
+  throw new IllegalArgumentException("SolrRequestInfo is null");
+} else {
+  if (stack.size() <= MAX_STACK_SIZE) {
+stack.push(info);
+  } else {
+assert true : "SolrRequestInfo Stack is full";
+log.error("SolrRequestInfo Stack is full");
+  }
 }
-assert prev == null;
-
-threadLocal.set(info);
   }
 
+  /** Removes the most recent SolrRequestInfo from the stack */
   public static void clearRequestInfo() {
-try {
-  SolrRequestInfo info = threadLocal.get();
-  if (info != null && info.closeHooks != null) {
-for (Closeable hook : info.closeHooks) {
-  try {
-hook.close();
-  } catch (Exception e) {
-SolrException.log(log, "Exception during close hook", e);
-  }
+Deque stack = threadLocal.get();
+if (stack.isEmpty()) {
+  log.error("clearRequestInfo called too many times");
+} else {
+  SolrRequestInfo info = stack.pop();
+  closeHooks(info);
+}
+  }
+
+  /**
+   * This reset method is more of a protection mechanism as
+   * we expect it to be empty by now because all "set" calls need to be 
balanced with a "clear".
+   */
+  public static void reset() {
+Deque stack = threadLocal.get();
+boolean isEmpty = stack.isEmpty();
+while (!stack.isEmpty()) {
+  SolrRequestInfo info = stack.pop();
+  closeHooks(info);
+}
+assert isEmpty : "SolrRequestInfo Stack should have been cleared.";
+  }
+
+  private static void closeHooks(SolrRequestInfo info) {
+if (info != null && info.closeHooks != null) {

Review comment:
   The callers of this method will not pass null though; right?

##
File path: 
solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java
##
@@ -271,7 +273,9 @@ public void writeResults(ResultContext ctx, JavaBinCodec 
codec) throws IOExcepti
   throw new SolrServerException(ex);
 } finally {
   if (req != null) req.close();
-  SolrRequestInfo.clearRequestInfo();
+  if (mustClearSolrRequestInfo) {

Review comment:
   Hmm; might it simply be enough to call clearRequestInfo if req != null, 
thus no new boolean?

##
File path: 
solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java
##
@@ -71,6 +71,7 @@
   protected final String coreName;
   private final SolrRequestParsers _parser;
   private final RequestWriterSupplier supplier;
+  private boolean mustClearSolrRequestInfo = false;

Review comment:
   This change is highly suspicious.  Why is this boolean now a field of 
EmbeddedSolrServer?  It doesn't seem like *state* of this object and so I don't 
think it belongs here.  It seems like a transient status in the course of work 
within the method that sets/clears the requestInfo.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene-solr] dsmiley commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-06-03 Thread GitBox


dsmiley commented on a change in pull request #1527:
URL: https://github.com/apache/lucene-solr/pull/1527#discussion_r434752288



##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -52,35 +56,60 @@
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static SolrRequestInfo getRequestInfo() {
-return threadLocal.get();
+Deque stack = threadLocal.get();
+if (stack.isEmpty()) return null;
+return stack.peek();
   }
 
+  /** Adds the SolrRequestInfo onto the stack provided that the stack is not 
reached MAX_STACK_SIZE */
   public static void setRequestInfo(SolrRequestInfo info) {
-// TODO: temporary sanity check... this can be changed to just an assert 
in the future
-SolrRequestInfo prev = threadLocal.get();
-if (prev != null) {
-  log.error("Previous SolrRequestInfo was not closed!  req={}", 
prev.req.getOriginalParams());
-  log.error("prev == info : {}", prev.req == info.req, new 
RuntimeException());
+Deque stack = threadLocal.get();
+if (info == null) {
+  throw new IllegalArgumentException("SolrRequestInfo is null");
+} else {
+  if (stack.size() <= MAX_STACK_SIZE) {
+stack.push(info);
+  } else {
+assert true : "SolrRequestInfo Stack is full";

Review comment:
   assert false

##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -52,35 +56,60 @@
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static SolrRequestInfo getRequestInfo() {
-return threadLocal.get();
+Deque stack = threadLocal.get();
+if (stack.isEmpty()) return null;
+return stack.peek();
   }
 
+  /** Adds the SolrRequestInfo onto the stack provided that the stack is not 
reached MAX_STACK_SIZE */
   public static void setRequestInfo(SolrRequestInfo info) {
-// TODO: temporary sanity check... this can be changed to just an assert 
in the future
-SolrRequestInfo prev = threadLocal.get();
-if (prev != null) {
-  log.error("Previous SolrRequestInfo was not closed!  req={}", 
prev.req.getOriginalParams());
-  log.error("prev == info : {}", prev.req == info.req, new 
RuntimeException());
+Deque stack = threadLocal.get();
+if (info == null) {
+  throw new IllegalArgumentException("SolrRequestInfo is null");
+} else {
+  if (stack.size() <= MAX_STACK_SIZE) {
+stack.push(info);
+  } else {
+assert true : "SolrRequestInfo Stack is full";
+log.error("SolrRequestInfo Stack is full");
+  }
 }
-assert prev == null;
-
-threadLocal.set(info);
   }
 
+  /** Removes the most recent SolrRequestInfo from the stack */
   public static void clearRequestInfo() {
-try {
-  SolrRequestInfo info = threadLocal.get();
-  if (info != null && info.closeHooks != null) {
-for (Closeable hook : info.closeHooks) {
-  try {
-hook.close();
-  } catch (Exception e) {
-SolrException.log(log, "Exception during close hook", e);
-  }
+Deque stack = threadLocal.get();
+if (stack.isEmpty()) {
+  log.error("clearRequestInfo called too many times");
+} else {
+  SolrRequestInfo info = stack.pop();
+  closeHooks(info);
+}
+  }
+
+  /**
+   * This reset method is more of a protection mechanism as
+   * we expect it to be empty by now because all "set" calls need to be 
balanced with a "clear".
+   */
+  public static void reset() {
+Deque stack = threadLocal.get();
+boolean isEmpty = stack.isEmpty();
+while (!stack.isEmpty()) {
+  SolrRequestInfo info = stack.pop();
+  closeHooks(info);
+}
+assert isEmpty : "SolrRequestInfo Stack should have been cleared.";
+  }
+
+  private static void closeHooks(SolrRequestInfo info) {
+if (info != null && info.closeHooks != null) {

Review comment:
   but it cannot be null any more?

##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -52,35 +56,60 @@
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static SolrRequestInfo getRequestInfo() {
-return threadLocal.get();
+Deque stack = threadLocal.get();
+if (stack.isEmpty()) return null;
+return stack.peek();
   }
 
+  /** Adds the SolrRequestInfo onto the stack provided that the stack is not 
reached MAX_STACK_SIZE */
   public static void setRequestInfo(SolrRequestInfo info) {
-// TODO: temporary sanity check... this can be changed to just an assert 
in the future
-SolrRequestInfo prev = threadLocal.get();
-if (prev != null) {
-  log.error("Previous SolrRequestInfo was not closed!  req={}", 
prev.req.getOriginalParams());
-  log.error("prev == info : {}", prev.req == info.req, new 
RuntimeException());
+Deque stack = threadL

[GitHub] [lucene-solr] dsmiley commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-06-02 Thread GitBox


dsmiley commented on a change in pull request #1527:
URL: https://github.com/apache/lucene-solr/pull/1527#discussion_r434081511



##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -52,35 +56,53 @@
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static SolrRequestInfo getRequestInfo() {
-return threadLocal.get();
+if (threadLocal.get().isEmpty()) return null;

Review comment:
   Instead of calling threadLocal.get() twice, can you please just call it 
once?  This goes for all the other methods in this class too.

##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -52,35 +56,53 @@
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static SolrRequestInfo getRequestInfo() {
-return threadLocal.get();
+if (threadLocal.get().isEmpty()) return null;
+return threadLocal.get().peek();
   }
 
+  /** Adds the SolrRequestInfo onto the stack provided that the stack is not 
reached MAX_STACK_SIZE */
   public static void setRequestInfo(SolrRequestInfo info) {
-// TODO: temporary sanity check... this can be changed to just an assert 
in the future
-SolrRequestInfo prev = threadLocal.get();
-if (prev != null) {
-  log.error("Previous SolrRequestInfo was not closed!  req={}", 
prev.req.getOriginalParams());
-  log.error("prev == info : {}", prev.req == info.req, new 
RuntimeException());
+if (info == null) {
+  throw new IllegalArgumentException("SolrRequestInfo is null");
+} else {
+  if (threadLocal.get().size() <= MAX_STACK_SIZE) {
+threadLocal.get().push(info);
+  } else {
+log.error("SolrRequestInfo Stack is full");

Review comment:
   add assertion

##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -52,35 +56,53 @@
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static SolrRequestInfo getRequestInfo() {
-return threadLocal.get();
+if (threadLocal.get().isEmpty()) return null;
+return threadLocal.get().peek();
   }
 
+  /** Adds the SolrRequestInfo onto the stack provided that the stack is not 
reached MAX_STACK_SIZE */
   public static void setRequestInfo(SolrRequestInfo info) {
-// TODO: temporary sanity check... this can be changed to just an assert 
in the future
-SolrRequestInfo prev = threadLocal.get();
-if (prev != null) {
-  log.error("Previous SolrRequestInfo was not closed!  req={}", 
prev.req.getOriginalParams());
-  log.error("prev == info : {}", prev.req == info.req, new 
RuntimeException());
+if (info == null) {
+  throw new IllegalArgumentException("SolrRequestInfo is null");
+} else {
+  if (threadLocal.get().size() <= MAX_STACK_SIZE) {
+threadLocal.get().push(info);
+  } else {
+log.error("SolrRequestInfo Stack is full");
+  }
 }
-assert prev == null;
-
-threadLocal.set(info);
   }
 
+  /** Removes the most recent SolrRequestInfo from the stack */
   public static void clearRequestInfo() {
-try {
-  SolrRequestInfo info = threadLocal.get();
-  if (info != null && info.closeHooks != null) {
-for (Closeable hook : info.closeHooks) {
-  try {
-hook.close();
-  } catch (Exception e) {
-SolrException.log(log, "Exception during close hook", e);
-  }
+if (threadLocal.get().isEmpty()) {
+  log.error("clearRequestInfo called too many times");
+} else {
+  SolrRequestInfo info = threadLocal.get().pop();
+  closeHooks(info);
+}
+  }
+
+  /** Removes all the SolrRequestInfos from the stack */

Review comment:
   comment that we expect it to be empty by now because all "set" calls 
need to be balanced with a "clear".  Thus this reset method is more of a 
protection mechanism.

##
File path: solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
##
@@ -145,6 +145,8 @@
   public static final String INTERNAL_REQUEST_COUNT = "_forwardedCount";
 
   public static final Random random;
+
+  private boolean pushedSolrRequestInfo = false;

Review comment:
   I know I suggested this name but lets call this 
"mustClearSolrRequestInfo"





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene-solr] dsmiley commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-05-26 Thread GitBox


dsmiley commented on a change in pull request #1527:
URL: https://github.com/apache/lucene-solr/pull/1527#discussion_r430017058



##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -38,7 +40,13 @@
 
 
 public class SolrRequestInfo {
-  protected final static ThreadLocal threadLocal = new 
ThreadLocal<>();
+
+  protected final static int capacity = 150;

Review comment:
   I suggest debugging/investigating there to understand _why_.  Maybe this 
cap has exposed an actual problem?





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene-solr] dsmiley commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-05-22 Thread GitBox


dsmiley commented on a change in pull request #1527:
URL: https://github.com/apache/lucene-solr/pull/1527#discussion_r429352375



##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -38,7 +40,13 @@
 
 
 public class SolrRequestInfo {
-  protected final static ThreadLocal threadLocal = new 
ThreadLocal<>();
+
+  protected final static int capacity = 150;
+
+  protected final static ThreadLocal> threadLocal = 
ThreadLocal.withInitial(() -> {
+Deque stack = new ArrayDeque<>(capacity);

Review comment:
   I think you can simply do a lambda reference to ArrayDequeue::new.  No 
need initialize with an internal capacity.  Honestly I'd prefer a LinkedList 
because in practice this stack will be extremely small (zero, one, sometimes 
two, very unlikely more).  But I leave that impl choice to you.

##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -38,7 +40,13 @@
 
 
 public class SolrRequestInfo {
-  protected final static ThreadLocal threadLocal = new 
ThreadLocal<>();
+
+  protected final static int capacity = 150;

Review comment:
   This should be MAX_STACK_SIZE I think.  
   Can anyone ( @mkhludnev ?) venture to guess how, realistically, we might 
reach upwards of 150?  I can't imagine more than a few, let alone 150.

##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -52,35 +60,48 @@
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static SolrRequestInfo getRequestInfo() {
-return threadLocal.get();
+if (threadLocal.get().isEmpty()) return null;
+return threadLocal.get().peek();
   }
 
   public static void setRequestInfo(SolrRequestInfo info) {
-// TODO: temporary sanity check... this can be changed to just an assert 
in the future
-SolrRequestInfo prev = threadLocal.get();
-if (prev != null) {
-  log.error("Previous SolrRequestInfo was not closed!  req={}", 
prev.req.getOriginalParams());
-  log.error("prev == info : {}", prev.req == info.req, new 
RuntimeException());
+if (info == null) {
+  throw new IllegalArgumentException("SolrRequestInfo is null");
+} else {
+  if (threadLocal.get().size() <= capacity) {
+threadLocal.get().push(info);
+  } else {
+log.error("SolrRequestInfo Stack is full");
+  }
 }
-assert prev == null;
-
-threadLocal.set(info);
   }
 
   public static void clearRequestInfo() {
-try {
-  SolrRequestInfo info = threadLocal.get();
-  if (info != null && info.closeHooks != null) {
-for (Closeable hook : info.closeHooks) {
-  try {
-hook.close();
-  } catch (Exception e) {
-SolrException.log(log, "Exception during close hook", e);
-  }
+if (threadLocal.get().isEmpty()) {
+  log.error("clearRequestInfo called too many times");
+} else {
+  SolrRequestInfo info = threadLocal.get().pop();
+  closeHooks(info);
+}
+  }
+
+  public static void reset() {

Review comment:
   Add javadoc please

##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -52,35 +60,48 @@
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static SolrRequestInfo getRequestInfo() {
-return threadLocal.get();
+if (threadLocal.get().isEmpty()) return null;
+return threadLocal.get().peek();
   }
 
   public static void setRequestInfo(SolrRequestInfo info) {

Review comment:
   Add javadoc please

##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -52,35 +60,48 @@
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static SolrRequestInfo getRequestInfo() {
-return threadLocal.get();
+if (threadLocal.get().isEmpty()) return null;
+return threadLocal.get().peek();
   }
 
   public static void setRequestInfo(SolrRequestInfo info) {
-// TODO: temporary sanity check... this can be changed to just an assert 
in the future
-SolrRequestInfo prev = threadLocal.get();
-if (prev != null) {
-  log.error("Previous SolrRequestInfo was not closed!  req={}", 
prev.req.getOriginalParams());
-  log.error("prev == info : {}", prev.req == info.req, new 
RuntimeException());
+if (info == null) {
+  throw new IllegalArgumentException("SolrRequestInfo is null");
+} else {
+  if (threadLocal.get().size() <= capacity) {
+threadLocal.get().push(info);
+  } else {
+log.error("SolrRequestInfo Stack is full");
+  }
 }
-assert prev == null;
-
-threadLocal.set(info);
   }
 
   public static void clearRequestInfo() {

Review comment:
   Add javadoc please





This is an automated 

[GitHub] [lucene-solr] dsmiley commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-05-19 Thread GitBox


dsmiley commented on a change in pull request #1527:
URL: https://github.com/apache/lucene-solr/pull/1527#discussion_r427323443



##
File path: solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java
##
@@ -52,35 +54,44 @@
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static SolrRequestInfo getRequestInfo() {
-return threadLocal.get();
+if (threadLocal.get().isEmpty()) return null;
+return threadLocal.get().peek();
   }
 
   public static void setRequestInfo(SolrRequestInfo info) {
-// TODO: temporary sanity check... this can be changed to just an assert 
in the future
-SolrRequestInfo prev = threadLocal.get();
-if (prev != null) {
-  log.error("Previous SolrRequestInfo was not closed!  req={}", 
prev.req.getOriginalParams());
-  log.error("prev == info : {}", prev.req == info.req, new 
RuntimeException());
+if (info == null) {
+  throw new IllegalArgumentException("SolrRequestInfo is null");
+} else {
+  threadLocal.get().push(info);

Review comment:
   Good idea!





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene-solr] dsmiley commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-05-19 Thread GitBox


dsmiley commented on a change in pull request #1527:
URL: https://github.com/apache/lucene-solr/pull/1527#discussion_r427323730



##
File path: solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
##
@@ -456,6 +457,7 @@ public void doFilter(ServletRequest _request, 
ServletResponse _response, FilterC
 
   GlobalTracer.get().clearContext();
   consumeInputFully(request, response);
+  SolrRequestInfo.reset();

Review comment:
   That is what `reset` _does_





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org