hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [1/3] hbase git commit: HBASE-16211 JMXCacheBuster restarting the metrics system might cause tests to hang
Date Tue, 12 Jul 2016 21:09:13 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 176598860 -> 16be7bba5
  refs/heads/branch-1.3 51eee9a22 -> 5bd5f6446
  refs/heads/master 90ba723dc -> 6d94925af


HBASE-16211 JMXCacheBuster restarting the metrics system might cause tests to hang


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/6d94925a
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/6d94925a
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/6d94925a

Branch: refs/heads/master
Commit: 6d94925af9d2a3eb2f181d0aa1a875becf258fc8
Parents: 90ba723
Author: Enis Soztutar <enis@apache.org>
Authored: Tue Jul 12 13:43:52 2016 -0700
Committer: Enis Soztutar <enis@apache.org>
Committed: Tue Jul 12 13:43:52 2016 -0700

----------------------------------------------------------------------
 .../hadoop/metrics2/impl/JmxCacheBuster.java    | 31 ++++++++++++++++++++
 1 file changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/6d94925a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/impl/JmxCacheBuster.java
----------------------------------------------------------------------
diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/impl/JmxCacheBuster.java
b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/impl/JmxCacheBuster.java
index 8fcf623..1ae9bd4 100644
--- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/impl/JmxCacheBuster.java
+++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/impl/JmxCacheBuster.java
@@ -19,6 +19,7 @@ package org.apache.hadoop.metrics2.impl;
 
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.commons.logging.Log;
@@ -27,6 +28,9 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.metrics2.MetricsExecutor;
 import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
 import org.apache.hadoop.metrics2.lib.MetricsExecutorImpl;
+import org.apache.hadoop.util.StringUtils;
+
+import com.google.common.annotations.VisibleForTesting;
 
 /**
  * JMX caches the beans that have been exported; even after the values are removed from hadoop's
@@ -41,6 +45,7 @@ public class JmxCacheBuster {
   private static final Log LOG = LogFactory.getLog(JmxCacheBuster.class);
   private static AtomicReference<ScheduledFuture> fut = new AtomicReference<>(null);
   private static MetricsExecutor executor = new MetricsExecutorImpl();
+  private static AtomicBoolean stopped = new AtomicBoolean(false);
 
   private JmxCacheBuster() {
     // Static only cache.
@@ -50,16 +55,42 @@ public class JmxCacheBuster {
    * For JMX to forget about all previously exported metrics.
    */
   public static void clearJmxCache() {
+    if (LOG.isTraceEnabled()) {
+      LOG.trace("clearing JMX Cache" + StringUtils.stringifyException(new Exception()));
+    }
     //If there are more then 100 ms before the executor will run then everything should be
merged.
     ScheduledFuture future = fut.get();
     if ((future != null && (!future.isDone() && future.getDelay(TimeUnit.MILLISECONDS)
> 100))) {
       // BAIL OUT
       return;
     }
+    if (stopped.get()) {
+      return;
+    }
     future = executor.getExecutor().schedule(new JmxCacheBusterRunnable(), 5, TimeUnit.SECONDS);
     fut.set(future);
   }
 
+  /**
+   * Stops the clearing of JMX metrics and restarting the Hadoop metrics system. This is
needed for
+   * some test environments where we manually inject sources or sinks dynamically.
+   */
+  @VisibleForTesting
+  public static void stop() {
+    stopped.set(true);
+    ScheduledFuture future = fut.get();
+    future.cancel(false);
+  }
+
+  /**
+   * Restarts the stopped service.
+   * @see #stop()
+   */
+  @VisibleForTesting
+  public static void restart() {
+    stopped.set(false);
+  }
+
   final static class JmxCacheBusterRunnable implements Runnable {
     @Override
     public void run() {


Mime
View raw message