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

2020-06-04 Thread GitBox


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



##
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:
   in fact, it's true; as it is a private method and called inside 
SolrRequestInfo





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] NazerkeBS commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-06-04 Thread GitBox


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



##
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:
   actually that's enough





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] NazerkeBS commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-06-04 Thread GitBox


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



##
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:
   it can be null; when getRequestInfo is called, in case of the 
stack.isEmpty(), it returns null;





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] NazerkeBS commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-06-04 Thread GitBox


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



##
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:
   it can be null; when getRequestInfo is called, if the stack.isEmpty(), 
it returns null;





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] NazerkeBS commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-05-25 Thread GitBox


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



##
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:
   Initially I set it to 100, then there was one test (CloudAuthStreamTest) 
was failing due to this capacity. So increased it to 150.





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] NazerkeBS commented on a change in pull request #1527: SOLR-14384 Stack SolrRequestInfo

2020-05-19 Thread GitBox


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



##
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:
   what would you suggest for the stack size limit?





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