virajjasani commented on code in PR #4874:
URL: https://github.com/apache/hbase/pull/4874#discussion_r1036447418
##########
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:
If we use `hbase.client.metrics.scope`, then this `scope` value would not be
unique across `AsyncConnectionImpl` objects IIUC.
--
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]