leventov commented on a change in pull request #6402: Thread-safe QueryMetrics
URL: https://github.com/apache/incubator-druid/pull/6402#discussion_r229344228
##########
File path: processing/src/main/java/org/apache/druid/query/QueryMetrics.java
##########
@@ -92,8 +94,24 @@
* 100% guarantee of compatibility, because methods could not only be added to
QueryMetrics, existing methods could also
* be changed or removed.
*
- * <p>QueryMetrics is designed for use from a single thread, implementations
shouldn't care about thread-safety.
+ * Thread safety consideration
+ * ---------------------------
+ * <p><b>All implementations of QueryMetrics must be Thread-safe.</b> This is
to facilitate some use cases (like JDBC)
+ * that needs to use QueryMetrics from multiple threads.
*
+ * <p>However, allowing multiple threads to use QueryMetrics can lead to bugs
that could be difficult to notice. e.g.,
+ * Segment processing threads could erroneously share one QueryMetrics,
overriding metrics of each other.
+ *
+ * <p>In order to catch such bugs ASAP, <b>all implementations should add the
following checks.</b> (see
+ * {@link DefaultQueryMetrics} for an example)
+ *
+ * 1. For all methods that add dimension: if the value of one dimension is
updated to another value, throws
+ * IllegalStateException.
+ * 2. For all methods that add metrics: if one metric is regitered more than
once, throws IllegalStateException
Review comment:
"registered"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]