vli02 commented on code in PR #4874:
URL: https://github.com/apache/hbase/pull/4874#discussion_r1036349972
##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java:
##########
@@ -47,13 +51,46 @@
/**
* This class is for maintaining the various connection statistics and
publishing them through the
* metrics interfaces. This class manages its own {@link MetricRegistry} and
{@link JmxReporter} so
- * as to not conflict with other uses of Yammer Metrics within the client
application. Instantiating
- * this class implicitly creates and "starts" instances of these classes; be
sure to call
- * {@link #shutdown()} to terminate the thread pools they allocate.
+ * as to not conflict with other uses of Yammer Metrics within the client
application. Calling
+ * {@link #getMetricsConnection()} implicitly creates and "starts" instances
of these classes; be
+ * sure to call {@link #deleteMetricsConnection()} to terminate the thread
pools they allocate. The
+ * metrics reporter will be shutdown {@link #shutdown()} when all connections
within this metrics
+ * instances are closed.
*/
@InterfaceAudience.Private
public class MetricsConnection implements StatisticTrackable {
+ static final Map<String, MetricsConnection> METRICS_INSTANCES =
+ new HashMap<String, MetricsConnection>();
+
+ static MetricsConnection getMetricsConnection(final String scope,
+ Supplier<ThreadPoolExecutor> batchPool, Supplier<ThreadPoolExecutor>
metaPool) {
+ MetricsConnection metrics;
+ synchronized (METRICS_INSTANCES) {
+ metrics = METRICS_INSTANCES.get(scope);
+ if (metrics == null) {
+ metrics = new MetricsConnection(scope, batchPool, metaPool);
+ METRICS_INSTANCES.put(scope, metrics);
+ } else {
+ metrics.addThreadPools(batchPool, metaPool);
+ }
+ metrics.incrConnectionCount();
+ }
+ return metrics;
+ }
+
+ static void deleteMetricsConnection(final String scope) {
+ synchronized (METRICS_INSTANCES) {
Review Comment:
The scope of this code block is not just per the single async connection
object, it is also per the single metrics object which might be shared among
multiple async connection objects.
##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java:
##########
@@ -54,6 +58,38 @@
@InterfaceAudience.Private
public class MetricsConnection implements StatisticTrackable {
+ static final Map<String, MetricsConnection> METRICS_INSTANCES =
+ new HashMap<String, MetricsConnection>();
+
+ static MetricsConnection getMetricsConnection(final AsyncConnection conn,
+ Supplier<ThreadPoolExecutor> batchPool, Supplier<ThreadPoolExecutor>
metaPool) {
+ String scope = getScope(conn);
+ MetricsConnection metrics;
+ synchronized (METRICS_INSTANCES) {
Review Comment:
I guess the scope that you meant here is the scope of this code block, it is
per async connection object, and the single metrics object which might be
shared among multiple async connection objects. Please refer the comment in the
deleteMetricsConnection() code block, too.
--
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]