You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by en...@apache.org on 2016/07/12 21:09:14 UTC
[2/3] hbase git commit: HBASE-16211 JMXCacheBuster restarting the
metrics system might cause tests to hang
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/16be7bba
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/16be7bba
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/16be7bba
Branch: refs/heads/branch-1
Commit: 16be7bba53165240b3bb90fcf30126a91052ac95
Parents: 1765988
Author: Enis Soztutar <en...@apache.org>
Authored: Tue Jul 12 13:43:52 2016 -0700
Committer: Enis Soztutar <en...@apache.org>
Committed: Tue Jul 12 13:43:58 2016 -0700
----------------------------------------------------------------------
.../hadoop/metrics2/impl/JmxCacheBuster.java | 31 ++++++++++++++++++++
1 file changed, 31 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/16be7bba/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() {