HDFS-14388. RBF: Prevent loading metric system when disabled. Contributed by Inigo Goiri.

This commit is contained in:
Ayush Saxena 2019-03-23 12:16:31 +05:30 committed by Brahma Reddy Battula
parent 9a9fbbe145
commit 0dbd87874a
5 changed files with 117 additions and 29 deletions

View File

@ -154,48 +154,66 @@ public void proxyOpFailureStandby() {
@Override @Override
public void proxyOpFailureCommunicate() { public void proxyOpFailureCommunicate() {
if (metrics != null) {
metrics.incrProxyOpFailureCommunicate(); metrics.incrProxyOpFailureCommunicate();
} }
}
@Override @Override
public void proxyOpFailureClientOverloaded() { public void proxyOpFailureClientOverloaded() {
if (metrics != null) {
metrics.incrProxyOpFailureClientOverloaded(); metrics.incrProxyOpFailureClientOverloaded();
} }
}
@Override @Override
public void proxyOpNotImplemented() { public void proxyOpNotImplemented() {
if (metrics != null) {
metrics.incrProxyOpNotImplemented(); metrics.incrProxyOpNotImplemented();
} }
}
@Override @Override
public void proxyOpRetries() { public void proxyOpRetries() {
if (metrics != null) {
metrics.incrProxyOpRetries(); metrics.incrProxyOpRetries();
} }
}
@Override @Override
public void proxyOpNoNamenodes() { public void proxyOpNoNamenodes() {
if (metrics != null) {
metrics.incrProxyOpNoNamenodes(); metrics.incrProxyOpNoNamenodes();
} }
}
@Override @Override
public void routerFailureStateStore() { public void routerFailureStateStore() {
if (metrics != null) {
metrics.incrRouterFailureStateStore(); metrics.incrRouterFailureStateStore();
} }
}
@Override @Override
public void routerFailureSafemode() { public void routerFailureSafemode() {
if (metrics != null) {
metrics.incrRouterFailureSafemode(); metrics.incrRouterFailureSafemode();
} }
}
@Override @Override
public void routerFailureReadOnly() { public void routerFailureReadOnly() {
if (metrics != null) {
metrics.incrRouterFailureReadOnly(); metrics.incrRouterFailureReadOnly();
} }
}
@Override @Override
public void routerFailureLocked() { public void routerFailureLocked() {
if (metrics != null) {
metrics.incrRouterFailureLocked(); metrics.incrRouterFailureLocked();
} }
}
/** /**

View File

@ -0,0 +1,56 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hdfs.server.federation.metrics;
/**
* Implementation of the State Store metrics which does not do anything.
* This is used when the metrics are disabled (e.g., tests).
*/
public class NullStateStoreMetrics extends StateStoreMetrics {
public void addRead(long latency) {}
public long getReadOps() {
return -1;
}
public double getReadAvg() {
return -1;
}
public void addWrite(long latency) {}
public long getWriteOps() {
return -1;
}
public double getWriteAvg() {
return -1;
}
public void addFailure(long latency) { }
public long getFailureOps() {
return -1;
}
public double getFailureAvg() {
return -1;
}
public void addRemove(long latency) {}
public long getRemoveOps() {
return -1;
}
public double getRemoveAvg() {
return -1;
}
public void setCacheSize(String name, int size) {}
public void reset() {}
public void shutdown() {}
}

View File

@ -39,7 +39,7 @@
*/ */
@Metrics(name = "StateStoreActivity", about = "Router metrics", @Metrics(name = "StateStoreActivity", about = "Router metrics",
context = "dfs") context = "dfs")
public final class StateStoreMetrics implements StateStoreMBean { public class StateStoreMetrics implements StateStoreMBean {
private final MetricsRegistry registry = new MetricsRegistry("router"); private final MetricsRegistry registry = new MetricsRegistry("router");
@ -54,6 +54,8 @@ public final class StateStoreMetrics implements StateStoreMBean {
private Map<String, MutableGaugeInt> cacheSizes; private Map<String, MutableGaugeInt> cacheSizes;
protected StateStoreMetrics() {}
private StateStoreMetrics(Configuration conf) { private StateStoreMetrics(Configuration conf) {
registry.tag(SessionId, "RouterSession"); registry.tag(SessionId, "RouterSession");
registry.tag(ProcessName, "Router"); registry.tag(ProcessName, "Router");

View File

@ -304,12 +304,17 @@ public RouterRpcServer(Configuration configuration, Router router,
this.rpcAddress = new InetSocketAddress( this.rpcAddress = new InetSocketAddress(
confRpcAddress.getHostName(), listenAddress.getPort()); confRpcAddress.getHostName(), listenAddress.getPort());
if (conf.getBoolean(RBFConfigKeys.DFS_ROUTER_METRICS_ENABLE,
RBFConfigKeys.DFS_ROUTER_METRICS_ENABLE_DEFAULT)) {
// Create metrics monitor // Create metrics monitor
Class<? extends RouterRpcMonitor> rpcMonitorClass = this.conf.getClass( Class<? extends RouterRpcMonitor> rpcMonitorClass = this.conf.getClass(
RBFConfigKeys.DFS_ROUTER_METRICS_CLASS, RBFConfigKeys.DFS_ROUTER_METRICS_CLASS,
RBFConfigKeys.DFS_ROUTER_METRICS_CLASS_DEFAULT, RBFConfigKeys.DFS_ROUTER_METRICS_CLASS_DEFAULT,
RouterRpcMonitor.class); RouterRpcMonitor.class);
this.rpcMonitor = ReflectionUtils.newInstance(rpcMonitorClass, conf); this.rpcMonitor = ReflectionUtils.newInstance(rpcMonitorClass, conf);
} else {
this.rpcMonitor = null;
}
// Create the client // Create the client
this.rpcClient = new RouterRpcClient(this.conf, this.router, this.rpcClient = new RouterRpcClient(this.conf, this.router,
@ -326,7 +331,7 @@ protected void serviceInit(Configuration configuration) throws Exception {
this.conf = configuration; this.conf = configuration;
if (this.rpcMonitor == null) { if (this.rpcMonitor == null) {
LOG.error("Cannot instantiate Router RPC metrics class"); LOG.info("Do not start Router RPC metrics");
} else { } else {
this.rpcMonitor.init(this.conf, this, this.router.getStateStore()); this.rpcMonitor.init(this.conf, this, this.router.getStateStore());
} }

View File

@ -33,6 +33,7 @@
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.server.federation.metrics.NullStateStoreMetrics;
import org.apache.hadoop.hdfs.server.federation.metrics.StateStoreMBean; import org.apache.hadoop.hdfs.server.federation.metrics.StateStoreMBean;
import org.apache.hadoop.hdfs.server.federation.metrics.StateStoreMetrics; import org.apache.hadoop.hdfs.server.federation.metrics.StateStoreMetrics;
import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys; import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
@ -172,6 +173,8 @@ protected void serviceInit(Configuration config) throws Exception {
this.cacheUpdater = new StateStoreCacheUpdateService(this); this.cacheUpdater = new StateStoreCacheUpdateService(this);
addService(this.cacheUpdater); addService(this.cacheUpdater);
if (conf.getBoolean(RBFConfigKeys.DFS_ROUTER_METRICS_ENABLE,
RBFConfigKeys.DFS_ROUTER_METRICS_ENABLE_DEFAULT)) {
// Create metrics for the State Store // Create metrics for the State Store
this.metrics = StateStoreMetrics.create(conf); this.metrics = StateStoreMetrics.create(conf);
@ -186,6 +189,10 @@ protected void serviceInit(Configuration config) throws Exception {
} catch (MetricsException e) { } catch (MetricsException e) {
LOG.error("Failed to register State Store bean {}", e.getMessage()); LOG.error("Failed to register State Store bean {}", e.getMessage());
} }
} else {
LOG.info("State Store metrics not enabled");
this.metrics = new NullStateStoreMetrics();
}
super.serviceInit(this.conf); super.serviceInit(this.conf);
} }