-
Couldn't load subscription status.
- Fork 9.1k
HDFS-16678. RBF should supports disable getNodeUsage() in RBFMetrics #4606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ | |
| import javax.management.ObjectName; | ||
| import javax.management.StandardMBean; | ||
|
|
||
| import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hdfs.protocol.DatanodeInfo; | ||
| import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; | ||
|
|
@@ -113,6 +114,8 @@ public class RBFMetrics implements RouterMBean, FederationMBean { | |
| /** Prevent holding the page from load too long. */ | ||
| private final long timeOut; | ||
|
|
||
| /** Enable/Disable getNodeUsage. **/ | ||
| private boolean enableGetDNUsage; | ||
|
|
||
| /** Router interface. */ | ||
| private final Router router; | ||
|
|
@@ -175,6 +178,8 @@ public RBFMetrics(Router router) throws IOException { | |
| Configuration conf = router.getConfig(); | ||
| this.timeOut = conf.getTimeDuration(RBFConfigKeys.DN_REPORT_TIME_OUT, | ||
| RBFConfigKeys.DN_REPORT_TIME_OUT_MS_DEFAULT, TimeUnit.MILLISECONDS); | ||
| this.enableGetDNUsage = conf.getBoolean(RBFConfigKeys.DFS_ROUTER_ENABLE_GET_DN_USAGE_KEY, | ||
| RBFConfigKeys.DFS_ROUTER_ENABLE_GET_DN_USAGE_DEFAULT); | ||
| this.topTokenRealOwners = conf.getInt( | ||
| RBFConfigKeys.DFS_ROUTER_METRICS_TOP_NUM_TOKEN_OWNERS_KEY, | ||
| RBFConfigKeys.DFS_ROUTER_METRICS_TOP_NUM_TOKEN_OWNERS_KEY_DEFAULT); | ||
|
|
@@ -184,6 +189,11 @@ public RBFMetrics(Router router) throws IOException { | |
| ms.register(RBFMetrics.class.getName(), "RBFActivity Metrics", this); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public void setEnableGetDNUsage(boolean enableGetDNUsage) { | ||
| this.enableGetDNUsage = enableGetDNUsage; | ||
| } | ||
|
|
||
| /** | ||
| * Unregister the JMX beans. | ||
| */ | ||
|
|
@@ -537,35 +547,34 @@ public int getNumEnteringMaintenanceDataNodes() { | |
|
|
||
| @Override // NameNodeMXBean | ||
| public String getNodeUsage() { | ||
| float median = 0; | ||
| float max = 0; | ||
| float min = 0; | ||
| float dev = 0; | ||
| double median = 0; | ||
| double max = 0; | ||
| double min = 0; | ||
| double dev = 0; | ||
|
|
||
| final Map<String, Map<String, Object>> info = new HashMap<>(); | ||
| try { | ||
| RouterRpcServer rpcServer = this.router.getRpcServer(); | ||
| DatanodeInfo[] live = rpcServer.getDatanodeReport( | ||
| DatanodeReportType.LIVE, false, timeOut); | ||
| DatanodeInfo[] live = null; | ||
| if (this.enableGetDNUsage) { | ||
| RouterRpcServer rpcServer = this.router.getRpcServer(); | ||
| live = rpcServer.getDatanodeReport(DatanodeReportType.LIVE, false, timeOut); | ||
| } else { | ||
| LOG.debug("Getting node usage is disabled."); | ||
| } | ||
|
|
||
| if (live.length > 0) { | ||
| float totalDfsUsed = 0; | ||
| float[] usages = new float[live.length]; | ||
| if (live != null && live.length > 0) { | ||
| double[] usages = new double[live.length]; | ||
| int i = 0; | ||
| for (DatanodeInfo dn : live) { | ||
| usages[i++] = dn.getDfsUsedPercent(); | ||
| totalDfsUsed += dn.getDfsUsedPercent(); | ||
| } | ||
| totalDfsUsed /= live.length; | ||
| Arrays.sort(usages); | ||
| median = usages[usages.length / 2]; | ||
| max = usages[usages.length - 1]; | ||
| min = usages[0]; | ||
|
|
||
| for (i = 0; i < usages.length; i++) { | ||
| dev += (usages[i] - totalDfsUsed) * (usages[i] - totalDfsUsed); | ||
| } | ||
| dev = (float) Math.sqrt(dev / usages.length); | ||
| StandardDeviation deviation = new StandardDeviation(); | ||
| dev = deviation.evaluate(usages); | ||
| } | ||
| } catch (IOException e) { | ||
| LOG.error("Cannot get the live nodes: {}", e.getMessage()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel it would be better this way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do we want to have the full stack trace? I think it is pretty clear what the error is here without it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @slfan1989 @goiri for your review. I think |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.