Jackie-Jiang commented on code in PR #16728:
URL: https://github.com/apache/pinot/pull/16728#discussion_r2350122966


##########
pinot-spi/src/main/java/org/apache/pinot/spi/query/QueryThreadContext.java:
##########
@@ -18,680 +18,257 @@
  */
 package org.apache.pinot.spi.query;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonInclude;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Supplier;
-import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
+import java.util.function.Supplier;
 import javax.annotation.Nullable;
-import org.apache.pinot.spi.env.PinotConfiguration;
+import 
org.apache.pinot.spi.accounting.ThreadAccounting.DefaultThreadResourceUsageAccountant;
+import org.apache.pinot.spi.accounting.ThreadResourceUsageAccountant;
+import org.apache.pinot.spi.exception.EarlyTerminationException;
+import org.apache.pinot.spi.exception.QueryErrorCode;
+import org.apache.pinot.spi.exception.QueryException;
 import org.apache.pinot.spi.executor.DecoratorExecutorService;
 import org.apache.pinot.spi.trace.LoggerConstants;
-import org.apache.pinot.spi.utils.CommonConstants;
-import org.apache.pinot.spi.utils.JsonUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
 
-/**
- * The {@code QueryThreadContext} class is a thread-local context for storing 
common query-related information
- * associated to the current thread.
- *
- * <p>It is used to pass information between different layers of the query 
execution stack without changing the
- * method signatures. This is also used to populate the {@link MDC} context 
for logging.
- *
- * Use {@link #open(String)} to initialize the empty context. As any other 
{@link AutoCloseable} object, it should be
- * used within a try-with-resources block to ensure the context is properly 
closed and removed from the thread-local
- * storage.
- *
- * Sometimes it is necessary to copy the state of the {@link 
QueryThreadContext} from one thread to another. In this
- * case, use the {@link #createMemento()} method to capture the state of the 
{@link QueryThreadContext} in the current
- * thread and then use the {@link #open(Memento)} method to initialize the 
context in the target thread with the state
- * captured in the {@link Memento} object. The API may be a bit cumbersome, 
but it ensures that the state is always
- * copied between threads in a safe way and makes it impossible to use the 
{@link QueryThreadContext} from another
- * thread by mistake.
- *
- * It is guaranteed that all server and broker threads running SSE and MSE 
will have this context initialized as soon
- * as the request is received. Ingestion threads that use the query execution 
stack will also have this context
- * initialized.
- */
-public class QueryThreadContext {
-  private static final Logger LOGGER = 
LoggerFactory.getLogger(QueryThreadContext.class);
-  private static final ThreadLocal<Instance> THREAD_LOCAL = new 
ThreadLocal<>();
-  public static volatile boolean _strictMode;
-  private static final FakeInstance FAKE_INSTANCE = new FakeInstance();
-
-  static {
-    // This is a hack to know if assertions are enabled or not
-    boolean assertEnabled = false;
-    //CHECKSTYLE:OFF
-    assert assertEnabled = true;
-    //CHECKSTYLE:ON
-    _strictMode = assertEnabled;
-  }
 
-  /**
-   * Private constructor to prevent instantiation.
-   *
-   * Use {@link #open(String)} to initialize the context instead.
-   */
-  private QueryThreadContext() {
-  }
+/// The [QueryThreadContext] class is a thread-local context for storing 
common query-related information associated to
+/// the current thread.
+///
+/// It is used to pass information between different layers of the query 
execution stack without changing the method
+/// signatures. This is also used to populate the [org.slf4j.MDC] context for 
logging.
+///
+/// Use [#open] to initialize the empty context. As any other [AutoCloseable] 
object, it should be used within a
+/// try-with-resources block to ensure the context is properly closed and 
removed from the thread-local storage and
+/// resource usage accountant.
+@JsonInclude(JsonInclude.Include.NON_NULL)

Review Comment:
   Agree we shouldn't serialize it in production. Currently we opened some 
debug APIs in `PinotBrokerDebug` and `DebugResource` (for server) and it is 
used only for debugging purpose. Added some javadocs about it



-- 
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