HBASE-6848 Make hbase-hadoop-compat findbugs clean

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1388252 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2012-09-20 22:51:30 +00:00
parent ed98705af6
commit 8c393a32a8
19 changed files with 143 additions and 130 deletions

View File

@ -43,6 +43,12 @@
<Bug pattern="NP_BOOLEAN_RETURN_NULL" />
</Match>
<!-- This is read by a thread from hadoop and findbugs never finds it -->
<Match>
<Bug code="UrF"/>
<Class name="org.apache.hadoop.hbase.metrics.BaseMetricsSourceImpl"/>
</Match>
<Match>
<Class name="org.apache.hadoop.hbase.regionserver.StoreFile$Writer" />
<Bug pattern="NP_NULL_PARAM_DEREF" />

View File

@ -33,6 +33,11 @@ public class CompatibilityFactory {
public static final String EXCEPTION_START = "Could not create ";
public static final String EXCEPTION_END = " Is the hadoop compatibility jar on the classpath?";
/**
* This is a static only class don't let any instance be created.
*/
protected CompatibilityFactory() {}
public static synchronized <T> T getInstance(Class<T> klass) {
T instance = null;
try {

View File

@ -32,9 +32,13 @@ import java.util.ServiceLoader;
*/
public class CompatibilitySingletonFactory extends CompatibilityFactory {
private static final Log LOG = LogFactory.getLog(CompatibilitySingletonFactory.class);
private static final Map<Class, Object> instances = new HashMap<Class, Object>();
/**
* This is a static only class don't let anyone create an instance.
*/
protected CompatibilitySingletonFactory() { }
/**
* Get the singleton instance of Any classes defined by compatibiliy jar's
*

View File

@ -28,78 +28,78 @@ public interface MasterMetricsSource extends BaseMetricsSource {
/**
* The name of the metrics
*/
public static final String METRICS_NAME = "HMaster";
static final String METRICS_NAME = "HMaster";
/**
* The context metrics will be under.
*/
public static final String METRICS_CONTEXT = "hmaster";
static final String METRICS_CONTEXT = "hmaster";
/**
* The name of the metrics context that metrics will be under in jmx
*/
public static final String METRICS_JMX_CONTEXT = "HMaster";
static final String METRICS_JMX_CONTEXT = "HMaster";
/**
* Description
*/
public static final String METRICS_DESCRIPTION = "Metrics about HBase master server";
static final String METRICS_DESCRIPTION = "Metrics about HBase master server";
// Strings used for exporting to metrics system.
public static final String MASTER_ACTIVE_TIME_NAME = "masterActiveTime";
public static final String MASTER_START_TIME_NAME = "masterStartTime";
public static final String AVERAGE_LOAD_NAME = "averageLoad";
public static final String NUM_REGION_SERVERS_NAME = "numRegionServers";
public static final String NUM_DEAD_REGION_SERVERS_NAME = "numDeadRegionServers";
public static final String ZOOKEEPER_QUORUM_NAME = "zookeeperQuorum";
public static final String SERVER_NAME_NAME = "serverName";
public static final String CLUSTER_ID_NAME = "clusterId";
public static final String IS_ACTIVE_MASTER_NAME = "isActiveMaster";
public static final String SPLIT_TIME_NAME = "hlogSplitTime";
public static final String SPLIT_SIZE_NAME = "hlogSplitSize";
public static final String CLUSTER_REQUESTS_NAME = "clusterRequests";
public static final String RIT_COUNT_NAME = "ritCount";
public static final String RIT_COUNT_OVER_THRESHOLD_NAME = "ritCountOverThreshold";
public static final String RIT_OLDEST_AGE_NAME = "ritOldestAge";
public static final String MASTER_ACTIVE_TIME_DESC = "Master Active Time";
public static final String MASTER_START_TIME_DESC = "Master Start Time";
public static final String AVERAGE_LOAD_DESC = "AverageLoad";
public static final String NUMBER_OF_REGION_SERVERS_DESC = "Number of RegionServers";
public static final String NUMBER_OF_DEAD_REGION_SERVERS_DESC = "Number of dead RegionServers";
public static final String ZOOKEEPER_QUORUM_DESC = "Zookeeper Quorum";
public static final String SERVER_NAME_DESC = "Server Name";
public static final String CLUSTER_ID_DESC = "Cluster Id";
public static final String IS_ACTIVE_MASTER_DESC = "Is Active Master";
public static final String SPLIT_TIME_DESC = "Time it takes to finish HLog.splitLog()";
public static final String SPLIT_SIZE_DESC = "Size of HLog files being split";
static final String MASTER_ACTIVE_TIME_NAME = "masterActiveTime";
static final String MASTER_START_TIME_NAME = "masterStartTime";
static final String AVERAGE_LOAD_NAME = "averageLoad";
static final String NUM_REGION_SERVERS_NAME = "numRegionServers";
static final String NUM_DEAD_REGION_SERVERS_NAME = "numDeadRegionServers";
static final String ZOOKEEPER_QUORUM_NAME = "zookeeperQuorum";
static final String SERVER_NAME_NAME = "serverName";
static final String CLUSTER_ID_NAME = "clusterId";
static final String IS_ACTIVE_MASTER_NAME = "isActiveMaster";
static final String SPLIT_TIME_NAME = "hlogSplitTime";
static final String SPLIT_SIZE_NAME = "hlogSplitSize";
static final String CLUSTER_REQUESTS_NAME = "clusterRequests";
static final String RIT_COUNT_NAME = "ritCount";
static final String RIT_COUNT_OVER_THRESHOLD_NAME = "ritCountOverThreshold";
static final String RIT_OLDEST_AGE_NAME = "ritOldestAge";
static final String MASTER_ACTIVE_TIME_DESC = "Master Active Time";
static final String MASTER_START_TIME_DESC = "Master Start Time";
static final String AVERAGE_LOAD_DESC = "AverageLoad";
static final String NUMBER_OF_REGION_SERVERS_DESC = "Number of RegionServers";
static final String NUMBER_OF_DEAD_REGION_SERVERS_DESC = "Number of dead RegionServers";
static final String ZOOKEEPER_QUORUM_DESC = "Zookeeper Quorum";
static final String SERVER_NAME_DESC = "Server Name";
static final String CLUSTER_ID_DESC = "Cluster Id";
static final String IS_ACTIVE_MASTER_DESC = "Is Active Master";
static final String SPLIT_TIME_DESC = "Time it takes to finish HLog.splitLog()";
static final String SPLIT_SIZE_DESC = "Size of HLog files being split";
/**
* Increment the number of requests the cluster has seen.
* @param inc Ammount to increment the total by.
*/
public void incRequests(final int inc);
void incRequests(final int inc);
/**
* Set the number of regions in transition.
* @param ritCount count of the regions in transition.
*/
public void setRIT(int ritCount);
void setRIT(int ritCount);
/**
* Set the count of the number of regions that have been in transition over the threshold time.
* @param ritCountOverThreshold number of regions in transition for longer than threshold.
*/
public void setRITCountOverThreshold(int ritCountOverThreshold);
void setRITCountOverThreshold(int ritCountOverThreshold);
/**
* Set the oldest region in transition.
* @param age age of the oldest RIT.
*/
public void setRITOldestAge(long age);
void setRITOldestAge(long age);
public void updateSplitTime(long time);
void updateSplitTime(long time);
public void updateSplitSize(long size);
void updateSplitSize(long size);
}

View File

@ -23,6 +23,6 @@ package org.apache.hadoop.hbase.master.metrics;
*/
public interface MasterMetricsSourceFactory {
public MasterMetricsSource create(MasterMetricsWrapper beanWrapper);
MasterMetricsSource create(MasterMetricsWrapper beanWrapper);
}

View File

@ -27,59 +27,59 @@ public interface MasterMetricsWrapper {
/**
* Get ServerName
*/
public String getServerName();
String getServerName();
/**
* Get Average Load
* @return Average Load
*/
public double getAverageLoad();
double getAverageLoad();
/**
* Get the Cluster ID
* @return Cluster ID
*/
public String getClusterId();
String getClusterId();
/**
* Get the Zookeeper Quorum Info
* @return Zookeeper Quorum Info
*/
public String getZookeeperQuorum();
String getZookeeperQuorum();
/**
* Get the co-processors
* @return Co-processors
*/
public String[] getCoprocessors();
String[] getCoprocessors();
/**
* Get hbase master start time
* @return Start time of master in milliseconds
*/
public long getMasterStartTime();
long getMasterStartTime();
/**
* Get the hbase master active time
* @return Time in milliseconds when master became active
*/
public long getMasterActiveTime();
long getMasterActiveTime();
/**
* Whether this master is the active master
* @return True if this is the active master
*/
public boolean getIsActiveMaster();
boolean getIsActiveMaster();
/**
* Get the live region servers
* @return Live region servers
*/
public int getRegionServers();
int getRegionServers();
/**
* Get the dead region servers
* @return Dead region Servers
*/
public int getDeadRegionServers();
int getDeadRegionServers();
}

View File

@ -26,7 +26,7 @@ public interface BaseMetricsSource {
/**
* Clear out the metrics and re-prepare the source.
*/
public void init();
void init();
/**
* Set a gauge to a specific value.
@ -34,7 +34,7 @@ public interface BaseMetricsSource {
* @param gaugeName the name of the gauge
* @param value the value
*/
public void setGauge(String gaugeName, long value);
void setGauge(String gaugeName, long value);
/**
* Add some amount to a gauge.
@ -42,7 +42,7 @@ public interface BaseMetricsSource {
* @param gaugeName the name of the gauge
* @param delta the amount to change the gauge by.
*/
public void incGauge(String gaugeName, long delta);
void incGauge(String gaugeName, long delta);
/**
* Subtract some amount from a gauge.
@ -50,14 +50,14 @@ public interface BaseMetricsSource {
* @param gaugeName the name of the gauge
* @param delta the amount to change the gauge by.
*/
public void decGauge(String gaugeName, long delta);
void decGauge(String gaugeName, long delta);
/**
* Remove a gauge and no longer announce it.
*
* @param key Name of the gauge to remove.
*/
public void removeGauge(String key);
void removeGauge(String key);
/**
* Add some amount to a counter.
@ -65,7 +65,7 @@ public interface BaseMetricsSource {
* @param counterName the name of the counter
* @param delta the amount to change the counter by.
*/
public void incCounters(String counterName, long delta);
void incCounters(String counterName, long delta);
/**
* Add some value to a histogram.
@ -73,7 +73,7 @@ public interface BaseMetricsSource {
* @param name the name of the histogram
* @param value the value to add to the histogram
*/
public void updateHistogram(String name, long value);
void updateHistogram(String name, long value);
/**
@ -82,7 +82,7 @@ public interface BaseMetricsSource {
* @param name the name of the quantile
* @param value the value to add to the quantile
*/
public void updateQuantile(String name, long value);
void updateQuantile(String name, long value);
/**
@ -90,6 +90,6 @@ public interface BaseMetricsSource {
*
* @param key
*/
public void removeCounter(String key);
void removeCounter(String key);
}

View File

@ -32,7 +32,7 @@ public interface MBeanSource {
* @param theMbean the actual MBean
* @return ObjectName from jmx
*/
public ObjectName register(String serviceName, String metricsName,
ObjectName register(String serviceName, String metricsName,
Object theMbean);
}

View File

@ -28,21 +28,21 @@ public interface ReplicationMetricsSource extends BaseMetricsSource {
/**
* The name of the metrics
*/
public static final String METRICS_NAME = "ReplicationMetrics";
static final String METRICS_NAME = "ReplicationMetrics";
/**
* The name of the metrics context that metrics will be under.
*/
public static final String METRICS_CONTEXT = "replicationmetrics";
static final String METRICS_CONTEXT = "replicationmetrics";
/**
* The name of the metrics context that metrics will be under.
*/
public static final String METRICS_JMX_CONTEXT = "ReplicationMetrics";
static final String METRICS_JMX_CONTEXT = "ReplicationMetrics";
/**
* A description.
*/
public static final String METRICS_DESCRIPTION = "Metrics about HBase replication";
static final String METRICS_DESCRIPTION = "Metrics about HBase replication";
}

View File

@ -25,54 +25,54 @@ import org.apache.hadoop.hbase.metrics.BaseMetricsSource;
*/
public interface ThriftServerMetricsSource extends BaseMetricsSource {
public static final String BATCH_GET_KEY = "batchGet";
public static final String BATCH_MUTATE_KEY = "batchMutate";
public static final String TIME_IN_QUEUE_KEY = "timeInQueue";
public static final String THRIFT_CALL_KEY = "thriftCall";
public static final String SLOW_THRIFT_CALL_KEY = "slowThriftCall";
public static final String CALL_QUEUE_LEN_KEY = "callQueueLen";
static final String BATCH_GET_KEY = "batchGet";
static final String BATCH_MUTATE_KEY = "batchMutate";
static final String TIME_IN_QUEUE_KEY = "timeInQueue";
static final String THRIFT_CALL_KEY = "thriftCall";
static final String SLOW_THRIFT_CALL_KEY = "slowThriftCall";
static final String CALL_QUEUE_LEN_KEY = "callQueueLen";
/**
* Add how long an operation was in the queue.
* @param time
*/
public void incTimeInQueue(long time);
void incTimeInQueue(long time);
/**
* Set the call queue length.
* @param len Time
*/
public void setCallQueueLen(int len);
void setCallQueueLen(int len);
/**
* Add how many keys were in a batch get.
* @param diff Num Keys
*/
public void incNumRowKeysInBatchGet(int diff);
void incNumRowKeysInBatchGet(int diff);
/**
* Add how many keys were in a batch mutate.
* @param diff Num Keys
*/
public void incNumRowKeysInBatchMutate(int diff);
void incNumRowKeysInBatchMutate(int diff);
/**
* Add how long a method took
* @param name Method name
* @param time Time
*/
public void incMethodTime(String name, long time);
void incMethodTime(String name, long time);
/**
* Add how long a call took
* @param time Time
*/
public void incCall(long time);
void incCall(long time);
/**
* Increment how long a slow call took.
* @param time Time
*/
public void incSlowCall(long time);
void incSlowCall(long time);
}

View File

@ -21,15 +21,15 @@ package org.apache.hadoop.hbase.thrift.metrics;
/** Factory that will be used to create metrics sources for the two diffent types of thrift servers. */
public interface ThriftServerMetricsSourceFactory {
public static final String METRICS_NAME = "Thrift";
public static final String METRICS_DESCRIPTION = "Thrift Server Metrics";
public static final String THRIFT_ONE_METRICS_CONTEXT = "thrift-one";
public static final String THRIFT_ONE_JMX_CONTEXT = "Thrift,sub=ThriftOne";
public static final String THRIFT_TWO_METRICS_CONTEXT = "thrift-two";
public static final String THRIFT_TWO_JMX_CONTEXT = "Thrift,sub=ThriftTwo";
static final String METRICS_NAME = "Thrift";
static final String METRICS_DESCRIPTION = "Thrift Server Metrics";
static final String THRIFT_ONE_METRICS_CONTEXT = "thrift-one";
static final String THRIFT_ONE_JMX_CONTEXT = "Thrift,sub=ThriftOne";
static final String THRIFT_TWO_METRICS_CONTEXT = "thrift-two";
static final String THRIFT_TWO_JMX_CONTEXT = "Thrift,sub=ThriftTwo";
public ThriftServerMetricsSource createThriftOneSource();
ThriftServerMetricsSource createThriftOneSource();
public ThriftServerMetricsSource createThriftTwoSource();
ThriftServerMetricsSource createThriftTwoSource();
}

View File

@ -23,16 +23,15 @@ package org.apache.hadoop.metrics;
*/
public interface MetricHistogram {
public static final String NUM_OPS_METRIC_NAME = "_num_ops";
public static final String MIN_METRIC_NAME = "_min";
public static final String MAX_METRIC_NAME = "_max";
public static final String MEAN_METRIC_NAME = "_mean";
public static final String STD_DEV_METRIC_NAME = "_std_dev";
public static final String MEDIAN_METRIC_NAME = "_median";
public static final String SEVENTY_FIFTH_PERCENTILE_METRIC_NAME = "_75th_percentile";
public static final String NINETY_FIFTH_PERCENTILE_METRIC_NAME = "_95th_percentile";
public static final String NINETY_NINETH_PERCENTILE_METRIC_NAME = "_99th_percentile";
static final String NUM_OPS_METRIC_NAME = "_num_ops";
static final String MIN_METRIC_NAME = "_min";
static final String MAX_METRIC_NAME = "_max";
static final String MEAN_METRIC_NAME = "_mean";
static final String MEDIAN_METRIC_NAME = "_median";
static final String SEVENTY_FIFTH_PERCENTILE_METRIC_NAME = "_75th_percentile";
static final String NINETY_FIFTH_PERCENTILE_METRIC_NAME = "_95th_percentile";
static final String NINETY_NINETH_PERCENTILE_METRIC_NAME = "_99th_percentile";
public void add(long value);
void add(long value);
}

View File

@ -25,8 +25,8 @@ import java.util.concurrent.ScheduledExecutorService;
*/
public interface MetricsExecutor {
public ScheduledExecutorService getExecutor();
ScheduledExecutorService getExecutor();
public void stop();
void stop();
}

View File

@ -79,7 +79,7 @@ public class MasterMetricsSourceImpl
}
public void setRITOldestAge(long ritCount) {
ritCountOverThresholdGauge.set(ritCount);
ritOldestAgeGauge.set(ritCount);
}
@Override

View File

@ -19,35 +19,37 @@
package org.apache.hadoop.hbase.metrics;
import org.apache.hadoop.metrics2.MetricsBuilder;
import org.apache.hadoop.metrics2.MetricsException;
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
import org.apache.hadoop.metrics2.MetricsSource;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry;
import org.apache.hadoop.metrics2.lib.MetricMutable;
import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong;
import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong;
import org.apache.hadoop.metrics2.lib.MetricMutableHistogram;
import org.apache.hadoop.metrics2.lib.MetricMutableQuantiles;
import org.apache.hadoop.metrics2.source.JvmMetricsSource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* Hadoop 1 implementation of BaseMetricsSource (using metrics2 framework)
*/
public class BaseMetricsSourceImpl implements BaseMetricsSource, MetricsSource {
private static enum DefaultMetricsSystemInitializer {
INSTANCE;
private boolean inited = false;
private JvmMetricsSource jvmMetricsSource;
synchronized void init(String name) {
if (inited) return;
inited = true;
DefaultMetricsSystem.initialize(HBASE_METRICS_SYSTEM_NAME);
jvmMetricsSource = JvmMetricsSource.create(name, "");
}
}
private static boolean defaultMetricsSystemInited = false;
public static final String HBASE_METRICS_SYSTEM_NAME = "hbase";
protected final DynamicMetricsRegistry metricsRegistry;
private JvmMetricsSource jvmMetricsSource;
protected final String metricsName;
protected final String metricsDescription;
protected final String metricsContext;
@ -65,15 +67,7 @@ public class BaseMetricsSourceImpl implements BaseMetricsSource, MetricsSource {
this.metricsJmxContext = metricsJmxContext;
metricsRegistry = new DynamicMetricsRegistry(metricsName).setContext(metricsContext);
if (!defaultMetricsSystemInited) {
//Not too worried about mutli-threaded here as all it does is spam the logs.
defaultMetricsSystemInited = true;
DefaultMetricsSystem.initialize(HBASE_METRICS_SYSTEM_NAME);
//If this is the first time through register a jvm source.
jvmMetricsSource = JvmMetricsSource.create(metricsName, "");
}
DefaultMetricsSystemInitializer.INSTANCE.init(metricsName);
//Register this instance.
DefaultMetricsSystem.INSTANCE.registerSource(metricsJmxContext, metricsDescription, this);

View File

@ -70,7 +70,7 @@ public class MetricSampleQuantiles {
private final MetricQuantile quantiles[];
public MetricSampleQuantiles(MetricQuantile[] quantiles) {
this.quantiles = quantiles;
this.quantiles = Arrays.copyOf(quantiles, quantiles.length);
this.samples = new LinkedList<SampleItem>();
}

View File

@ -81,7 +81,7 @@ public class MasterMetricsSourceImpl
}
public void setRITOldestAge(long ritCount) {
ritCountOverThresholdGauge.set(ritCount);
ritOldestAgeGauge.set(ritCount);
}
@Override

View File

@ -33,7 +33,20 @@ import org.apache.hadoop.metrics2.source.JvmMetrics;
*/
public class BaseMetricsSourceImpl implements BaseMetricsSource, MetricsSource {
private static boolean defaultMetricsSystemInited = false;
private static enum DefaultMetricsSystemInitializer {
INSTANCE;
private boolean inited = false;
private JvmMetrics jvmMetricsSource;
synchronized void init(String name) {
if (inited) return;
inited = true;
DefaultMetricsSystem.initialize(HBASE_METRICS_SYSTEM_NAME);
jvmMetricsSource = JvmMetrics.create(name, "", DefaultMetricsSystem.instance());
}
}
public static final String HBASE_METRICS_SYSTEM_NAME = "hbase";
protected final DynamicMetricsRegistry metricsRegistry;
@ -42,8 +55,6 @@ public class BaseMetricsSourceImpl implements BaseMetricsSource, MetricsSource {
protected final String metricsContext;
protected final String metricsJmxContext;
private JvmMetrics jvmMetricsSource;
public BaseMetricsSourceImpl(
String metricsName,
String metricsDescription,
@ -56,15 +67,9 @@ public class BaseMetricsSourceImpl implements BaseMetricsSource, MetricsSource {
this.metricsJmxContext = metricsJmxContext;
metricsRegistry = new DynamicMetricsRegistry(metricsName).setContext(metricsContext);
DefaultMetricsSystemInitializer.INSTANCE.init(metricsName);
if (!defaultMetricsSystemInited) {
//Not too worried about mutlithread here as all it does is spam the logs.
defaultMetricsSystemInited = true;
DefaultMetricsSystem.initialize(HBASE_METRICS_SYSTEM_NAME);
jvmMetricsSource = JvmMetrics.create(metricsName, "", DefaultMetricsSystem.instance());
}
//Register this instance.
DefaultMetricsSystem.instance().register(metricsJmxContext, metricsDescription, this);
init();

View File

@ -72,7 +72,7 @@ public class MetricSampleQuantiles {
private final MetricQuantile quantiles[];
public MetricSampleQuantiles(MetricQuantile[] quantiles) {
this.quantiles = quantiles;
this.quantiles = Arrays.copyOf(quantiles, quantiles.length);
this.samples = new LinkedList<SampleItem>();
}