From db9e60fe7d7971ffa9d3be7f68085e7f2ebe212f Mon Sep 17 00:00:00 2001 From: "Apekshit(Appy) Sharma" Date: Tue, 23 Jun 2015 20:47:38 -0700 Subject: [PATCH] HBASE-13957 Changes in this commit: - Adds enum HConfig: Contains configurations with their default values. - ConfigurationManager + Adds new interface to access congiguration value using enum HConfig. get*(HConfig conf) and set*(HConfig conf, value) + Deprecates observer related functions in lieu of oncoming changes to dynamic configuration framework. - Added 26 configurations to HConfig. Deprecated corresponding constants from HConstants (can not be deleted because audience is Public). - Added getConfigurationManager() to HBaseCluster and HBaseTestingUtility, should make switching to ConfigurationManager in tests easier. - Added HConfig as resource in HBaseConfiguration + It'll be safe to delete configurations from hbase-default.xml once added to HConfig (caveat: hbase-default.xml is also used to generate ref guide. Working on fix.) (Apekshit) --- .../org/apache/hadoop/hbase/MetaTableAccessor.java | 5 +- .../hbase/client/ConnectionImplementation.java | 6 +- .../apache/hadoop/hbase/HBaseConfiguration.java | 1 + .../main/java/org/apache/hadoop/hbase/HConfig.java | 349 ++++++++++++ .../java/org/apache/hadoop/hbase/HConstants.java | 102 ++-- .../java/org/apache/hadoop/hbase/TestHConfig.java | 99 ++++ .../org/apache/hadoop/hbase/HealthCheckChore.java | 14 +- .../org/apache/hadoop/hbase/LocalHBaseCluster.java | 6 +- .../hadoop/hbase/conf/ConfigurationManager.java | 207 ++++++- .../coordination/SplitLogWorkerCoordination.java | 4 - .../coordination/ZkSplitLogWorkerCoordination.java | 5 +- .../org/apache/hadoop/hbase/master/HMaster.java | 11 +- .../hadoop/hbase/regionserver/HRegionServer.java | 111 ++-- .../hadoop/hbase/regionserver/StoreScanner.java | 8 +- .../org/apache/hadoop/hbase/util/HBaseFsck.java | 3 +- .../java/org/apache/hadoop/hbase/HBaseCluster.java | 7 + .../apache/hadoop/hbase/HBaseTestingUtility.java | 8 + .../org/apache/hadoop/hbase/TestInfoServers.java | 8 +- .../hadoop/hbase/TestNodeHealthCheckChore.java | 48 +- .../hadoop/hbase/client/TestMetaWithReplicas.java | 9 +- .../hbase/conf/TestConfigurationManager.java | 609 ++++++++++++++++++++- .../hbase/master/TestDistributedLogSplitting.java | 5 +- .../hadoop/hbase/master/TestGetInfoPort.java | 3 +- .../regionserver/TestRegionServerMetrics.java | 2 +- .../hbase/regionserver/TestSplitLogWorker.java | 5 +- .../hbase/util/ProcessBasedLocalHBaseCluster.java | 5 +- .../hbase/util/TestCoprocessorScanPolicy.java | 5 +- .../hadoop/hbase/client/AbstractTestShell.java | 25 +- 28 files changed, 1479 insertions(+), 191 deletions(-) create mode 100644 hbase-common/src/main/java/org/apache/hadoop/hbase/HConfig.java create mode 100644 hbase-common/src/test/java/org/apache/hadoop/hbase/TestHConfig.java diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java index ee42b93..c49b062 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java @@ -551,8 +551,9 @@ public class MetaTableAccessor { int scannerCaching = connection.getConfiguration() .getInt(HConstants.HBASE_META_SCANNER_CACHING, HConstants.DEFAULT_HBASE_META_SCANNER_CACHING); - if (connection.getConfiguration().getBoolean(HConstants.USE_META_REPLICAS, - HConstants.DEFAULT_USE_META_REPLICAS)) { + if (connection.getConfiguration().getBoolean( + HConfig.HBASE_META_REPLICAS_USE.getName(), + HConfig.HBASE_META_REPLICAS_USE.getDefaultValueAsBoolean())) { scan.setConsistency(Consistency.TIMELINE); } if (rowUpperLimit <= scannerCaching) { diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java index 35ff34f..1ae142e 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java @@ -27,6 +27,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.DoNotRetryIOException; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionLocation; @@ -220,8 +221,9 @@ class ConnectionImplementation implements ClusterConnection, Closeable { this.closed = false; this.pause = conf.getLong(HConstants.HBASE_CLIENT_PAUSE, HConstants.DEFAULT_HBASE_CLIENT_PAUSE); - this.useMetaReplicas = conf.getBoolean(HConstants.USE_META_REPLICAS, - HConstants.DEFAULT_USE_META_REPLICAS); + this.useMetaReplicas = conf.getBoolean( + HConfig.HBASE_META_REPLICAS_USE.getName(), + HConfig.HBASE_META_REPLICAS_USE.getDefaultValueAsBoolean()); this.numTries = tableConfig.getRetriesNumber(); this.rpcTimeout = conf.getInt( HConstants.HBASE_RPC_TIMEOUT_KEY, diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java index 1be66a1..1327d82 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java @@ -78,6 +78,7 @@ public class HBaseConfiguration extends Configuration { public static Configuration addHbaseResources(Configuration conf) { conf.addResource("hbase-default.xml"); + conf.addResource(HConfig.getAsConfiguration()); conf.addResource("hbase-site.xml"); checkDefaultsVersion(conf); diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConfig.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConfig.java new file mode 100644 index 0000000..288546e --- /dev/null +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConfig.java @@ -0,0 +1,349 @@ +/** + * 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.hbase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; + +import javax.xml.bind.TypeConstraintException; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Configurations with their default values. + * Value of a configuration can be of one of the following types: + * boolean, int, long, float, double, String + * + * Configurations annotated with 'AddToReference' will be documented in HBase Reference Guide, + * so they *should* have a description. + * + * Naming convention: + * Names should be all caps (default java convention) with '.' in configuration name replaced by + * '_'. + */ + +// TODO (apekshit): Remove duplicated properties (annotated with @AddtoReference) from +// hbase-defaults.xml. This will required some mechanism to propagate these properties from +// HConfig to reference guide (hbase-defaults.adoc). + +@InterfaceAudience.Private +@InterfaceStability.Evolving +public enum HConfig { + // 8 retries take about 23 seconds. + HBASE_LOG_REPLAY_RETRIES_NUMBER( + "hbase.log.replay.retries.number", 8), + + HBASE_LOG_REPLAY_RPC_TIMEOUT("hbase.log.replay.rpc.timeout", 30000), // timeout in ms. + + HBASE_META_REPLICAS_USE("hbase.meta.replicas.use", false, + "If true, meta replication is enabled."), + + HBASE_NODE_HEALTH_FAILURE_THRESHOLD("hbase.node.health.failure.threshold", 3), + + HBASE_NODE_HEALTH_SCRIPT_FREQUENCY("hbase.node.health.script.frequency", + HConstants.DEFAULT_THREAD_WAKE_FREQUENCY), + + HBASE_NODE_HEALTH_SCRIPT_LOCATION("hbase.node.health.script.location", ""), + + HBASE_NODE_HEALTH_SCRIPT_TIMEOUT("hbase.node.health.script.timeout", 60000L), // timeout in ms. + + HBASE_MASTER_INFO_PORT("hbase.master.info.port", 16010, + "The port for the HBase Master web UI. Set to -1 if you do not want a UI instance run."), + + HBASE_MASTER_INFO_PORT_ORIG("hbase.master.info.port.orig", 16010), + + HBASE_REGIONSERVER_CODECS("hbase.regionserver.codecs", "", "Comma separated list of codecs."), + + HBASE_REGIONSERVER_EXECUTOR_CLOSEMETA_THREADS( + "hbase.regionserver.executor.closemeta.threads", 1), + + HBASE_REGIONSERVER_EXECUTOR_CLOSEREGION_THREADS( + "hbase.regionserver.executor.closeregion.threads", 3), + + HBASE_REGIONSERVER_EXECUTOR_OPENMETA_THREADS( + "hbase.regionserver.executor.openmeta.threads", 1), + + HBASE_REGIONSERVER_EXECUTOR_OPENREGION_THREADS( + "hbase.regionserver.executor.openregion.threads", 3), + + @AddToReference + HBASE_REGIONSERVER_INFO_BINDADDRESS("hbase.regionserver.info.bindAddress", "0.0.0.0", + "The address for the HBase RegionServer web UI."), + + @AddToReference + HBASE_REGIONSERVER_INFO_PORT("hbase.regionserver.info.port", 16030, + "The port for the HBase RegionServer web UI. Set to -1 if you do not want the" + + " RegionServer UI to run."), + + HBASE_REGIONSERVER_NONCES_ENABLED("hbase.regionserver.nonces.enabled", true), + + HBASE_REGIONSERVER_NUMREGIONSTOREPORT("hbase.regionserver.numregionstoreport", 10), + + HBASE_REGIONSERVER_REGION_REPLICA_FLUSHER_THREADS( + "hbase.regionserver.region.replica.flusher.threads", -1, ""), + + HBASE_REGIONSERVER_WAL_MAX_SPLITTERS("hbase.regionserver.wal.max.splitters", 2), + + HBASE_REPLICATION("hbase.replication", true), + + HBASE_REPLICATION_SOURCE_SERVICE("hbase.replication.source.service", + "org.apache.hadoop.hbase.replication.regionserver.Replication"), + + HBASE_REPLICATION_SINK_SERVICE("hbase.replication.sink.service", + "org.apache.hadoop.hbase.replication.regionserver.Replication"), + + @AddToReference + HBASE_RPC_SHORTOPERATION_TIMEOUT("hbase.rpc.shortoperation.timeout", 10000, + "This is another version of 'hbase.rpc.timeout'. For those RPC operation within cluster, we" + + " rely on this configuration to set a short timeout limitation for short operation. For" + + " example, short rpc timeout for region server's trying to report to active master can" + + "benefit quicker master failover process."), + + @AddToReference + HBASE_STORESCANNER_PARALLEL_SEEK_ENABLE("hbase.storescanner.parallel.seek.enable", false, + "Enables StoreFileScanner parallel-seeking in StoreScanner, a feature which can reduce" + + "response latency under special conditions."), + + @AddToReference + HBASE_STORESCANNER_PARALLEL_SEEK_THREADS("hbase.storescanner.parallel.seek.threads", 10, + "The default thread pool size if parallel-seeking feature enabled."), + + DUMMY_BOOLEAN_FOR_TEST("dummy.boolean.for.test", false), + DUMMY_INT_FOR_TEST("dummy.int.for.test", 10), + DUMMY_LONG_FOR_TEST("dummy.long.for.test", 999999999L), + DUMMY_FLOAT_FOR_TEST("dummy.float.for.test", 3.333f), + DUMMY_DOUBLE_FOR_TEST("dummy.double.for.test", 5.555), + DUMMY_STRING_FOR_TEST("dummy.string.for.test", "foo"), + DUMMY_EMPTY_STRING_FOR_TEST("dummy.empty.string.for.test", ""), + DUMMY_CSV_STRINGS_FOR_TEST("dummy.csv.strings.for.test", "foo,bar,pikachu"), + @Dynamic + DUMMY_DYNAMIC_FOR_TEST("dummy.dynamic.for.test", ""), + ; + + private static final Log LOG = LogFactory.getLog(HConfig.class); + + HConfig(String name, Object defaultValue) { + this(name, defaultValue, ""); + } + + HConfig(String name, Object defaultValue, String description) { + assert defaultValue != null; + this.name = name; + this.defaultValue = defaultValue; + this.description = description; + } + + private final String name; + private final String description; + private Object defaultValue; + + /** + * @return name of the configuration. + */ + public String getName() { + return name; + } + + /** + * @return description for the configuration. + */ + public String getDescription() { + return description; + } + + /** + * @throws TypeConstraintException if configuration is not of type String. + */ + public void CheckTypeIsString() { + if(!(defaultValue instanceof String)) { + throw new TypeConstraintException("Type of default value is not String."); + } + } + + /** + * Asserts default value is of type String and returns it. + * @return default value as String. + * @throws TypeConstraintException if configuration is not of type String. + */ + public String getDefaultValueAsString() { + CheckTypeIsString(); + return (String) defaultValue; + } + + /** + * @throws TypeConstraintException if configuration is not of type boolean. + */ + public void CheckTypeIsBoolean() { + if(!(defaultValue instanceof Boolean)) { + throw new TypeConstraintException("Type of default value is not Boolean."); + } + } + + /** + * Asserts default value is of type boolean and returns it. + * @return default value as boolean. + * @throws TypeConstraintException if configuration is not of type boolean.. + */ + public boolean getDefaultValueAsBoolean() { + CheckTypeIsBoolean(); + return (Boolean) defaultValue; + } + + /** + * @throws TypeConstraintException if configuration is not of type int. + */ + public void CheckTypeIsInt() { + if(!(defaultValue instanceof Integer)) { + throw new TypeConstraintException("Type of default value is not int."); + } + } + + /** + * Asserts default value is of type int and returns it. + * @return default value as int. + * @throws TypeConstraintException if configuration is not of type int. + */ + public int getDefaultValueAsInt() { + CheckTypeIsInt(); + return (Integer) defaultValue; + } + + /** + * @throws TypeConstraintException if configuration is not of type long. + */ + public void CheckTypeIsLong() { + if(!(defaultValue instanceof Long)) { + throw new TypeConstraintException("Type of default value is not long."); + } + } + + /** + * Asserts default value is of type long and returns it. + * @return default value as long. + * @throws TypeConstraintException if configuration is not of type long. + */ + public long getDefaultValueAsLong() { + CheckTypeIsLong(); + return (Long) defaultValue; + } + + /** + * @throws TypeConstraintException if configuration is not of type float. + */ + public void CheckTypeIsFloat() { + if(!(defaultValue instanceof Float)) { + throw new TypeConstraintException("Type of default value is not float."); + } + } + + /** + * Asserts default value is of type float and returns it. + * @return default value as float. + * @throws TypeConstraintException if configuration is not of type float. + */ + public float getDefaultValueAsFloat() { + CheckTypeIsFloat(); + return (Float) defaultValue; + } + + /** + * @throws TypeConstraintException if configuration is not of type double. + */ + public void CheckTypeIsDouble() { + if(!(defaultValue instanceof Double)) { + throw new TypeConstraintException("Type of default value is not double."); + } + } + + /** + * Asserts default value is of type double and returns it. + * @return default value as double. + * @throws TypeConstraintException if configuration is not of type double. + */ + public double getDefaultValueAsDouble() { + CheckTypeIsDouble(); + return (Double) defaultValue; + } + + /** + * @return true if configuration should be added to reference guide. + */ + public boolean isAddToReference() { + try { + return HConfig.class.getField(this.name()).isAnnotationPresent(AddToReference.class); + } catch (NoSuchFieldException e) { + return false; + } + } + + /** + * @return true if configuration is dynamic, else false. + */ + public boolean isDynamic() { + try { + return HConfig.class.getField(this.name()).isAnnotationPresent(Dynamic.class); + } catch (NoSuchFieldException e) { + return false; + } + } + + /** + * To annotate configurations which should be documented in the reference guide. + */ + @InterfaceAudience.Private + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + private @interface AddToReference {} + + /** + * To annotate dynamic configurations. + */ + @InterfaceAudience.Private + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + private @interface Dynamic{} + + private Object getDefaultValue() { + return defaultValue; + } + + /** + * @return {@link Configuration} object containing properties in HConfig. + */ + public static Configuration getAsConfiguration() { + Configuration configuration = new Configuration(); + for (HConfig conf : HConfig.values()) { + Object defaultValue = conf.getDefaultValue(); + if (defaultValue instanceof Boolean || defaultValue instanceof Integer + || defaultValue instanceof Long || defaultValue instanceof Float + || defaultValue instanceof Double || defaultValue instanceof String) { + configuration.set(conf.getName(), defaultValue.toString(), "HConfig"); + } else { + throw new RuntimeException("Bad configuration default value: conf = " + conf.getName() + + ", default value = " + conf.getDefaultValue().toString()); + } + } + return configuration; + } + +}; diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java index c1316a9..f19071e 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java @@ -150,10 +150,13 @@ public final class HConstants { public static final int DEFAULT_MASTER_PORT = 16000; /** default port for master web api */ - public static final int DEFAULT_MASTER_INFOPORT = 16010; + @Deprecated + public static final int DEFAULT_MASTER_INFOPORT = + HConfig.HBASE_MASTER_INFO_PORT.getDefaultValueAsInt(); /** Configuration key for master web API port */ - public static final String MASTER_INFO_PORT = "hbase.master.info.port"; + @Deprecated + public static final String MASTER_INFO_PORT = HConfig.HBASE_MASTER_INFO_PORT.getName(); /** Parameter name for the master type being backup (waits for primary to go inactive). */ public static final String MASTER_TYPE_BACKUP = "hbase.master.backup"; @@ -234,15 +237,18 @@ public final class HConstants { public static final int DEFAULT_REGIONSERVER_PORT = 16020; /** default port for region server web api */ - public static final int DEFAULT_REGIONSERVER_INFOPORT = 16030; + @Deprecated + public static final int DEFAULT_REGIONSERVER_INFOPORT = + HConfig.HBASE_REGIONSERVER_INFO_PORT.getDefaultValueAsInt(); /** A configuration key for regionserver info port */ + @Deprecated public static final String REGIONSERVER_INFO_PORT = - "hbase.regionserver.info.port"; + HConfig.HBASE_REGIONSERVER_INFO_PORT.getName(); /** A flag that enables automatic selection of regionserver info port */ public static final String REGIONSERVER_INFO_PORT_AUTO = - REGIONSERVER_INFO_PORT + ".auto"; + HConfig.HBASE_REGIONSERVER_INFO_PORT.getName() + ".auto"; /** Parameter name for what region server implementation to use. */ public static final String REGION_SERVER_IMPL= "hbase.regionserver.impl"; @@ -251,7 +257,7 @@ public final class HConstants { public static final String MASTER_IMPL= "hbase.master.impl"; /** Parameter name for what hbase client implementation to use. */ - public static final String HBASECLIENT_IMPL= "hbase.hbaseclient.impl"; + public static final String HBASECLIENT_IMPL = "hbase.hbaseclient.impl"; /** Parameter name for how often threads should wake up */ public static final String THREAD_WAKE_FREQUENCY = "hbase.server.thread.wakefrequency"; @@ -799,35 +805,36 @@ public final class HConstants { */ public static final int DEFAULT_HBASE_RPC_TIMEOUT = 60000; - /** - * timeout for short operation RPC - */ - public static final String HBASE_RPC_SHORTOPERATION_TIMEOUT_KEY = "hbase.rpc.shortoperation.timeout"; + /** timeout for short operation RPC */ + @Deprecated + public static final String HBASE_RPC_SHORTOPERATION_TIMEOUT_KEY = + HConfig.HBASE_RPC_SHORTOPERATION_TIMEOUT.getName(); - /** - * Default value of {@link #HBASE_RPC_SHORTOPERATION_TIMEOUT_KEY} - */ - public static final int DEFAULT_HBASE_RPC_SHORTOPERATION_TIMEOUT = 10000; + /** Default value of {@link #HBASE_RPC_SHORTOPERATION_TIMEOUT_KEY} */ + @Deprecated + public static final int DEFAULT_HBASE_RPC_SHORTOPERATION_TIMEOUT = + HConfig.HBASE_RPC_SHORTOPERATION_TIMEOUT.getDefaultValueAsInt(); /** * Value indicating the server name was saved with no sequence number. */ public static final long NO_SEQNUM = -1; - - /* - * cluster replication constants. - */ - public static final String - REPLICATION_ENABLE_KEY = "hbase.replication"; - public static final boolean - REPLICATION_ENABLE_DEFAULT = true; - public static final String - REPLICATION_SOURCE_SERVICE_CLASSNAME = "hbase.replication.source.service"; - public static final String - REPLICATION_SINK_SERVICE_CLASSNAME = "hbase.replication.sink.service"; + // cluster replication constants. + @Deprecated + public static final String REPLICATION_ENABLE_KEY = HConfig.HBASE_REPLICATION.getName(); + @Deprecated + public static final boolean REPLICATION_ENABLE_DEFAULT = + HConfig.HBASE_REPLICATION.getDefaultValueAsBoolean(); + @Deprecated + public static final String REPLICATION_SOURCE_SERVICE_CLASSNAME = + HConfig.HBASE_REPLICATION_SOURCE_SERVICE.getName(); + @Deprecated + public static final String REPLICATION_SINK_SERVICE_CLASSNAME = + HConfig.HBASE_REPLICATION_SINK_SERVICE.getName(); + @Deprecated public static final String REPLICATION_SERVICE_CLASSNAME_DEFAULT = - "org.apache.hadoop.hbase.replication.regionserver.Replication"; + HConfig.HBASE_REPLICATION_SOURCE_SERVICE.getDefaultValueAsString(); /** HBCK special code name used as server name when manipulating ZK nodes */ public static final String HBCK_CODE_NAME = "HBCKServerName"; @@ -842,7 +849,9 @@ public final class HConstants { "hbase.regionserver.region.split.policy"; /** Whether nonces are enabled; default is true. */ - public static final String HBASE_RS_NONCES_ENABLED = "hbase.regionserver.nonces.enabled"; + @Deprecated + public static final String HBASE_RS_NONCES_ENABLED = + HConfig.HBASE_REGIONSERVER_NONCES_ENABLED.getName(); /** * Configuration key for the size of the block cache @@ -931,8 +940,12 @@ public final class HConstants { "hbase.master.log.replay.wait.region.timeout"; /** Conf key for enabling meta replication */ - public static final String USE_META_REPLICAS = "hbase.meta.replicas.use"; - public static final boolean DEFAULT_USE_META_REPLICAS = false; + @Deprecated + public static final String USE_META_REPLICAS = + HConfig.HBASE_META_REPLICAS_USE.getName(); + @Deprecated + public static final boolean DEFAULT_USE_META_REPLICAS = + HConfig.HBASE_META_REPLICAS_USE.getDefaultValueAsBoolean(); public static final String META_REPLICAS_NUM = "hbase.meta.replica.count"; public static final int DEFAULT_META_REPLICA_NUM = 1; @@ -1029,19 +1042,26 @@ public final class HConstants { new String[] { TableName.META_TABLE_NAME.getNameAsString() }, HBASE_NON_TABLE_DIRS.toArray()))); - /** Health script related settings. */ - public static final String HEALTH_SCRIPT_LOC = "hbase.node.health.script.location"; - public static final String HEALTH_SCRIPT_TIMEOUT = "hbase.node.health.script.timeout"; + // Health script related settings. + @Deprecated + public static final String HEALTH_SCRIPT_LOC = + HConfig.HBASE_NODE_HEALTH_SCRIPT_LOCATION.getName(); + @Deprecated + public static final String HEALTH_SCRIPT_TIMEOUT = + HConfig.HBASE_NODE_HEALTH_SCRIPT_TIMEOUT.getName(); + @Deprecated public static final String HEALTH_CHORE_WAKE_FREQ = - "hbase.node.health.script.frequency"; - public static final long DEFAULT_HEALTH_SCRIPT_TIMEOUT = 60000; - /** - * The maximum number of health check failures a server can encounter consecutively. - */ + HConfig.HBASE_NODE_HEALTH_SCRIPT_FREQUENCY.getName(); + @Deprecated + public static final long DEFAULT_HEALTH_SCRIPT_TIMEOUT = + HConfig.HBASE_NODE_HEALTH_SCRIPT_TIMEOUT.getDefaultValueAsLong(); + /** The maximum number of health check failures a server can encounter consecutively. */ + @Deprecated public static final String HEALTH_FAILURE_THRESHOLD = - "hbase.node.health.failure.threshold"; - public static final int DEFAULT_HEALTH_FAILURE_THRESHOLD = 3; - + HConfig.HBASE_NODE_HEALTH_FAILURE_THRESHOLD.getName(); + @Deprecated + public static final int DEFAULT_HEALTH_FAILURE_THRESHOLD = + HConfig.HBASE_NODE_HEALTH_FAILURE_THRESHOLD.getDefaultValueAsInt(); /** * Setting to activate, or not, the publication of the status by the master. Default diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHConfig.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHConfig.java new file mode 100644 index 0000000..e9d590a --- /dev/null +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestHConfig.java @@ -0,0 +1,99 @@ +/** + * 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.hbase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(SmallTests.class) +public class TestHConfig { + private static final Log LOG = LogFactory.getLog(TestHConfig.class); + + @Test + /** + * Tests that naming convention is followed. i.e. foo.bar.cap should have enum item named + * FOO_BAR_CAP. + */ + public void testNamingConvention() { + boolean success = true; + for (HConfig property : HConfig.values()) { + String propertyName = property.getName(); + String enumItemName = property.name(); + String expectedItemName = propertyName.toUpperCase().replace('.', '_'); + if (!expectedItemName.equals(enumItemName)) { + LOG.error("Bad Naming: Configuration '" + propertyName + "' is named " + enumItemName + + ". Should be named " + expectedItemName); + success = false; + } + } + assertTrue(success); + } + + @Test + /** + * Tests that properties annotated @AddToReference have non-empty description. + */ + public void testNonEmptyDescriptionForAddToReferenceProperties() { + boolean success = true; + for (HConfig property : HConfig.values()) { + if (property.isAddToReference() && property.getDescription().isEmpty()) { + LOG.error("Property '" + property.getName() + "' is annotated with @AddToReference but" + + " has empty description."); + success = false; + } + } + assert success; + } + + @Test + /** + * Test {@link HConfig#isAddToReference()}. + */ + public void testIsAddToReference() { + assertTrue(HConfig.HBASE_REGIONSERVER_INFO_PORT.isAddToReference()); + assertFalse(HConfig.DUMMY_BOOLEAN_FOR_TEST.isAddToReference()); + } + + @Test + /** + * Test {@link HConfig#isDynamic()}. + */ + public void testIsDynamic() { + assertTrue(HConfig.DUMMY_DYNAMIC_FOR_TEST.isDynamic()); + assertFalse(HConfig.DUMMY_BOOLEAN_FOR_TEST.isDynamic()); + } + + @Test + /** + * Test {@link HConfig#getAsConfiguration()} returns a non-null configuration. + */ + public void testGetAsConfiguration() { + Configuration conf = HConfig.getAsConfiguration(); + assertNotNull(conf); + } +} + diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/HealthCheckChore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/HealthCheckChore.java index ff9f94b..72c6252 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/HealthCheckChore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/HealthCheckChore.java @@ -21,8 +21,8 @@ package org.apache.hadoop.hbase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HealthChecker.HealthCheckerExitStatus; +import org.apache.hadoop.hbase.conf.ConfigurationManager; import org.apache.hadoop.util.StringUtils; /** @@ -31,23 +31,19 @@ import org.apache.hadoop.util.StringUtils; public class HealthCheckChore extends ScheduledChore { private static final Log LOG = LogFactory.getLog(HealthCheckChore.class); private HealthChecker healthChecker; - private Configuration config; private int threshold; private int numTimesUnhealthy = 0; private long failureWindow; private long startWindow; - public HealthCheckChore(int sleepTime, Stoppable stopper, Configuration conf) { + public HealthCheckChore(int sleepTime, Stoppable stopper, ConfigurationManager confManager) { super("HealthChecker", stopper, sleepTime); LOG.info("Health Check Chore runs every " + StringUtils.formatTime(sleepTime)); - this.config = conf; - String healthCheckScript = this.config.get(HConstants.HEALTH_SCRIPT_LOC); - long scriptTimeout = this.config.getLong(HConstants.HEALTH_SCRIPT_TIMEOUT, - HConstants.DEFAULT_HEALTH_SCRIPT_TIMEOUT); + String healthCheckScript = confManager.getString(HConfig.HBASE_NODE_HEALTH_SCRIPT_LOCATION); + long scriptTimeout = confManager.getLong(HConfig.HBASE_NODE_HEALTH_SCRIPT_TIMEOUT); healthChecker = new HealthChecker(); healthChecker.init(healthCheckScript, scriptTimeout); - this.threshold = config.getInt(HConstants.HEALTH_FAILURE_THRESHOLD, - HConstants.DEFAULT_HEALTH_FAILURE_THRESHOLD); + this.threshold = confManager.getInt(HConfig.HBASE_NODE_HEALTH_FAILURE_THRESHOLD); this.failureWindow = (long)this.threshold * (long)sleepTime; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java index c865360..d5ce836 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java @@ -143,9 +143,9 @@ public class LocalHBaseCluster { // Always have masters and regionservers come up on port '0' so we don't // clash over default ports. - conf.set(HConstants.MASTER_PORT, "0"); - conf.set(HConstants.REGIONSERVER_PORT, "0"); - conf.set(HConstants.REGIONSERVER_INFO_PORT, "0"); + conf.setInt(HConstants.MASTER_PORT, 0); + conf.setInt(HConstants.REGIONSERVER_PORT, 0); + conf.setInt(HConfig.HBASE_REGIONSERVER_INFO_PORT.getName(), 0); this.masterClass = (Class) conf.getClass(HConstants.MASTER_IMPL, masterClass); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationManager.java index 29b3e8b..d0e3055 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationManager.java @@ -20,18 +20,25 @@ package org.apache.hadoop.hbase.conf; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.classification.InterfaceStability; +import javax.xml.bind.TypeConstraintException; import java.util.Collections; import java.util.Set; import java.util.WeakHashMap; /** - * Maintains the set of all the classes which would like to get notified - * when the Configuration is reloaded from the disk in the Online Configuration - * Change mechanism, which lets you update certain configuration properties - * on-the-fly, without having to restart the cluster. + * ConfigurationManager manages: + * 1) underlying configuration and provides access to properties' values. Moving forward, all + * internal HBase code should move from using Configuration to ConfigurationManager. HBASE-13936 + * 2) dynamic configuration updates: Maintains a set of all the classes which would like + * to get notified when the Configuration is reloaded from the disk in the Online + * Configuration Change mechanism, which lets you update certain configuration + * properties on-the-fly, without having to restart the cluster. + * Note: Functions related to observers have been deprecated in lieu of oncoming changes to + * dynamic configuration framework. HBASE-13936 * * If a class has configuration properties which you would like to be able to * change on-the-fly, do the following: @@ -75,10 +82,198 @@ import java.util.WeakHashMap; public class ConfigurationManager { private static final Log LOG = LogFactory.getLog(ConfigurationManager.class); + public ConfigurationManager(Configuration configuration) { + this.configuration = configuration; + } + + private Configuration configuration; + + // Getters + + /** + * Get the value of the property. If the property is deprecated, it returns + * the value of the first property which replaces the deprecated property and is not null. + * Values are processed for variable expansion before being + * returned. + * + * @return If set, expanded value as a String, else default value from HConfig. + * @throws TypeConstraintException if configuration is not of type String. + */ + public String getString(HConfig property) { + property.CheckTypeIsString(); + return configuration.get(property.getName()); + } + + /** + * Get the value of the property as a boolean. + * If the specified value is not a valid boolean, IllegalArgumentException is thrown. + * + * @return If set, value as a boolean, else default value from HConfig. + * @throws IllegalArgumentException when the value is invalid. + * @throws TypeConstraintException if configuration is not of type boolean. + */ + public boolean getBoolean(HConfig property) { + property.CheckTypeIsBoolean(); + String bool = configuration.get(property.getName()); + assert bool != null; // Even if not explicitly set, we should get the default value. + if ("true".equalsIgnoreCase(bool)) { + return true; + } else if ("false".equalsIgnoreCase(bool)) { + return false; + } else throw new IllegalArgumentException( + "Configuration Error: Boolean configuration " + property.getName() + + " set to bad value '" + bool + "'. Using default value " + + property.getDefaultValueAsBoolean()); + } + + /** + * Get the value of the property as an int. + * If the specified value is not a valid int, NumberFormatException is thrown. + * + * @return If set, value as an int, else default value from HConfig. + * @throws NumberFormatException when the value is invalid. + * @throws TypeConstraintException if configuration is not of type int. + */ + public int getInt(HConfig property) { + property.CheckTypeIsInt(); + return configuration.getInt(property.getName(), property.getDefaultValueAsInt()); + } + + /** + * Get the value of the property as a long. + * If the specified value is not a valid long, NumberFormatException is thrown. + * + * @return If set, value as a long, else default value from HConfig. + * @throws NumberFormatException when the value is invalid. + * @throws TypeConstraintException if configuration is not of type long. + */ + public long getLong(HConfig property) { + property.CheckTypeIsLong(); + return configuration.getLong(property.getName(), property.getDefaultValueAsLong()); + } + + /** + * Get the value of the property as a float. + * If the specified value is not a valid float, NumberFormatException is thrown. + * + * @return If set, value as a float, else default value from HConfig. + * @throws NumberFormatException when the value is invalid. + * @throws TypeConstraintException if configuration is not of type float. + */ + public double getFloat(HConfig property) { + property.CheckTypeIsFloat(); + return configuration.getFloat(property.getName(), property.getDefaultValueAsFloat()); + } + + /** + * Get the value of the property as a double. + * If the specified value is not a valid double, NumberFormatException is thrown. + * + * @return If set, value as a double, else default value from HConfig. + * @throws NumberFormatException when the value is invalid. + * @throws TypeConstraintException if configuration is not of type double. + */ + public double getDouble(HConfig property) { + property.CheckTypeIsDouble(); + return configuration.getDouble(property.getName(), property.getDefaultValueAsDouble()); + } + + /** + * Get the comma delimited values of the property as + * an array of Strings. If the value is empty string, null is returned. + * + * @return If set, value as an array of Strings, else default value from HConfig. + * @throws TypeConstraintException if configuration is not of type string. + */ + public String[] getStrings(HConfig property) { + property.CheckTypeIsString(); + return configuration.getStrings(property.getName()); + } + + // Setters + + /** + * Set value of property to given String value. If + * property is deprecated, it also sets the value to + * the keys that replace the deprecated key. + * + * @throws IllegalArgumentException if the value is null. + * @throws TypeConstraintException if configuration is not of type String. + */ + public void setString(HConfig property, String value) { + property.CheckTypeIsString(); + configuration.set(property.getName(), value, null); + } + + /** + * Set value of property to given boolean value. + * + * @throws TypeConstraintException if configuration is not of type boolean. + */ + public void setBoolean(HConfig property, boolean value) { + property.CheckTypeIsBoolean(); + configuration.setBoolean(property.getName(), value); + } + + /** + * Set value of property to given int value. + * + * @throws TypeConstraintException if configuration is not of type int. + */ + public void setInt(HConfig property, int value) { + property.CheckTypeIsInt(); + configuration.setInt(property.getName(), value); + } + + /** + * Set value of property to given value. + * + * @throws TypeConstraintException if configuration is not of type long. + */ + public void setLong(HConfig property, long value) { + property.CheckTypeIsLong(); + configuration.setLong(property.getName(), value); + } + + /** + * Set value of property to given float value. + * + * @throws TypeConstraintException if configuration is not of type float. + */ + public void setFloat(HConfig property, float value) { + property.CheckTypeIsFloat(); + configuration.setFloat(property.getName(), value); + } + + /** + * Set value of property to given value. + * + * @throws TypeConstraintException if configuration is not of type double. + */ + public void setDouble(HConfig property, double value) { + property.CheckTypeIsDouble(); + configuration.setDouble(property.getName(), value); + } + + /** + * Set value of property to comma delimited string values. + * + * @throws TypeConstraintException if configuration is not of type string. + */ + public void setStrings(HConfig property, String... value) { + property.CheckTypeIsString(); + configuration.setStrings(property.getName(), value); + } + + public Configuration getConfiguration() { + return configuration; + } + // The set of Configuration Observers. These classes would like to get // notified when the configuration is reloaded from disk. This is a set // constructed from a WeakHashMap, whose entries would be removed if the // observer classes go out of scope. + @Deprecated private Set configurationObservers = Collections.newSetFromMap(new WeakHashMap()); @@ -87,6 +282,7 @@ public class ConfigurationManager { * Register an observer class * @param observer */ + @Deprecated public void registerObserver(ConfigurationObserver observer) { synchronized (configurationObservers) { configurationObservers.add(observer); @@ -100,6 +296,7 @@ public class ConfigurationManager { * Deregister an observer class * @param observer */ + @Deprecated public void deregisterObserver(ConfigurationObserver observer) { synchronized (configurationObservers) { configurationObservers.remove(observer); @@ -113,6 +310,7 @@ public class ConfigurationManager { * The conf object has been repopulated from disk, and we have to notify * all the observers that are expressed interest to do that. */ + @Deprecated public void notifyAllObservers(Configuration conf) { synchronized (configurationObservers) { for (ConfigurationObserver observer : configurationObservers) { @@ -131,6 +329,7 @@ public class ConfigurationManager { /** * @return the number of observers. */ + @Deprecated public int getNumObservers() { synchronized (configurationObservers) { return configurationObservers.size(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/SplitLogWorkerCoordination.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/SplitLogWorkerCoordination.java index 82f00b3..c26e02e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/SplitLogWorkerCoordination.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/SplitLogWorkerCoordination.java @@ -49,10 +49,6 @@ import com.google.common.annotations.VisibleForTesting; */ @InterfaceAudience.Private public interface SplitLogWorkerCoordination { - -/* SplitLogWorker part */ - public static final int DEFAULT_MAX_SPLITTERS = 2; - /** * Initialize internal values. This method should be used when corresponding SplitLogWorker * instance is created diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZkSplitLogWorkerCoordination.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZkSplitLogWorkerCoordination.java index b682764..4bc422d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZkSplitLogWorkerCoordination.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZkSplitLogWorkerCoordination.java @@ -33,6 +33,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.SplitLogCounters; @@ -139,7 +140,9 @@ public class ZkSplitLogWorkerCoordination extends ZooKeeperListener implements this.server = server; this.worker = worker; this.splitTaskExecutor = splitExecutor; - maxConcurrentTasks = conf.getInt("hbase.regionserver.wal.max.splitters", DEFAULT_MAX_SPLITTERS); + maxConcurrentTasks = conf.getInt( + HConfig.HBASE_REGIONSERVER_WAL_MAX_SPLITTERS.getName(), + HConfig.HBASE_REGIONSERVER_WAL_MAX_SPLITTERS.getDefaultValueAsInt()); reportPeriod = conf.getInt("hbase.splitlog.report.period", conf.getInt(HConstants.HBASE_SPLITLOG_MANAGER_TIMEOUT, diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 84f981f..2466ad7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -55,6 +55,7 @@ import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HBaseIOException; import org.apache.hadoop.hbase.HBaseInterfaceAudience; import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; @@ -356,7 +357,7 @@ public class HMaster extends HRegionServer implements MasterServices, Server { ", hbase.cluster.distributed=" + this.conf.getBoolean(HConstants.CLUSTER_DISTRIBUTED, false)); // Disable usage of meta replicas in the master - this.conf.setBoolean(HConstants.USE_META_REPLICAS, false); + this.conf.setBoolean(HConfig.HBASE_META_REPLICAS_USE.getName(), false); Replication.decorateMasterConfiguration(this.conf); @@ -412,8 +413,7 @@ public class HMaster extends HRegionServer implements MasterServices, Server { if (!conf.getBoolean("hbase.master.infoserver.redirect", true)) { return -1; } - int infoPort = conf.getInt("hbase.master.info.port.orig", - HConstants.DEFAULT_MASTER_INFOPORT); + int infoPort = confManager.getInt(HConfig.HBASE_MASTER_INFO_PORT_ORIG); // -1 is for disabling info server, so no redirecting if (infoPort < 0 || infoServer == null) { return -1; @@ -769,7 +769,7 @@ public class HMaster extends HRegionServer implements MasterServices, Server { status.markComplete("Initialization successful"); LOG.info("Master has completed initialization"); - configurationManager.registerObserver(this.balancer); + confManager.registerObserver(this.balancer); // Set master as 'initialized'. initialized = true; // assign the meta replicas @@ -1984,8 +1984,7 @@ public class HMaster extends HRegionServer implements MasterServices, Server { public int getRegionServerInfoPort(final ServerName sn) { RegionServerInfo info = this.regionServerTracker.getRegionServerInfo(sn); if (info == null || info.getInfoPort() == 0) { - return conf.getInt(HConstants.REGIONSERVER_INFO_PORT, - HConstants.DEFAULT_REGIONSERVER_INFOPORT); + return confManager.getInt(HConfig.HBASE_REGIONSERVER_INFO_PORT); } return info.getInfoPort(); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index ae739b3..6d50224 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -64,6 +64,7 @@ import org.apache.hadoop.hbase.CoordinatedStateManager; import org.apache.hadoop.hbase.CoordinatedStateManagerFactory; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HealthCheckChore; @@ -83,7 +84,6 @@ import org.apache.hadoop.hbase.client.ConnectionUtils; import org.apache.hadoop.hbase.client.RpcRetryingCallerFactory; import org.apache.hadoop.hbase.conf.ConfigurationManager; import org.apache.hadoop.hbase.coordination.BaseCoordinatedStateManager; -import org.apache.hadoop.hbase.coordination.SplitLogWorkerCoordination; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; import org.apache.hadoop.hbase.exceptions.RegionMovedException; import org.apache.hadoop.hbase.exceptions.RegionOpeningException; @@ -476,7 +476,7 @@ public class HRegionServer extends HasThread implements * Configuration manager is used to register/deregister and notify the configuration observers * when the regionserver is notified that there was a change in the on disk configs. */ - protected final ConfigurationManager configurationManager; + protected final ConfigurationManager confManager; /** * Starts a HRegionServer at the default location. @@ -498,13 +498,14 @@ public class HRegionServer extends HasThread implements throws IOException { this.fsOk = true; this.conf = conf; + confManager = new ConfigurationManager(this.conf); HFile.checkHFileVersion(this.conf); - checkCodecs(this.conf); + checkCodecs(confManager); this.userProvider = UserProvider.instantiate(conf); Superusers.initialize(conf); FSUtils.setupShortCircuitRead(this.conf); // Disable usage of meta replicas in the regionserver - this.conf.setBoolean(HConstants.USE_META_REPLICAS, false); + confManager.setBoolean(HConfig.HBASE_META_REPLICAS_USE, false); // Config'ed params this.numRetries = this.conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, @@ -514,19 +515,16 @@ public class HRegionServer extends HasThread implements this.sleeper = new Sleeper(this.msgInterval, this); - boolean isNoncesEnabled = conf.getBoolean(HConstants.HBASE_RS_NONCES_ENABLED, true); + boolean isNoncesEnabled = confManager.getBoolean(HConfig.HBASE_REGIONSERVER_NONCES_ENABLED); this.nonceManager = isNoncesEnabled ? new ServerNonceManager(this.conf) : null; - this.numRegionsToReport = conf.getInt( - "hbase.regionserver.numregionstoreport", 10); + this.numRegionsToReport = confManager.getInt(HConfig.HBASE_REGIONSERVER_NUMREGIONSTOREPORT); this.operationTimeout = conf.getInt( HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT); - this.shortOperationTimeout = conf.getInt( - HConstants.HBASE_RPC_SHORTOPERATION_TIMEOUT_KEY, - HConstants.DEFAULT_HBASE_RPC_SHORTOPERATION_TIMEOUT); + this.shortOperationTimeout = confManager.getInt(HConfig.HBASE_RPC_SHORTOPERATION_TIMEOUT); this.abortRequested = false; this.stopped = false; @@ -592,7 +590,6 @@ public class HRegionServer extends HasThread implements clusterStatusTracker = new ClusterStatusTracker(zooKeeper, this); clusterStatusTracker.start(); } - this.configurationManager = new ConfigurationManager(); rpcServices.start(); putUpWebUI(); @@ -684,12 +681,11 @@ public class HRegionServer extends HasThread implements /** * Run test on configured codecs to make sure supporting libs are in place. - * @param c * @throws IOException */ - private static void checkCodecs(final Configuration c) throws IOException { + private static void checkCodecs(final ConfigurationManager confManager) throws IOException { // check to see if the codec list is available: - String [] codecs = c.getStrings("hbase.regionserver.codecs", (String[])null); + String [] codecs = confManager.getStrings(HConfig.HBASE_REGIONSERVER_CODECS); if (codecs == null) return; for (String codec : codecs) { if (!CompressionTest.testCompression(codec)) { @@ -726,9 +722,8 @@ public class HRegionServer extends HasThread implements // Health checker thread. if (isHealthCheckerConfigured()) { - int sleepTime = this.conf.getInt(HConstants.HEALTH_CHORE_WAKE_FREQ, - HConstants.DEFAULT_THREAD_WAKE_FREQUENCY); - healthCheckChore = new HealthCheckChore(sleepTime, this, getConfiguration()); + int sleepTime = confManager.getInt(HConfig.HBASE_NODE_HEALTH_SCRIPT_FREQUENCY); + healthCheckChore = new HealthCheckChore(sleepTime, this, confManager); } this.pauseMonitor = new JvmPauseMonitor(conf); pauseMonitor.start(); @@ -867,7 +862,7 @@ public class HRegionServer extends HasThread implements private void registerConfigurationObservers() { // Registering the compactSplitThread object with the ConfigurationManager. - configurationManager.registerObserver(this.compactSplitThread); + confManager.registerObserver(this.compactSplitThread); } /** @@ -1608,7 +1603,7 @@ public class HRegionServer extends HasThread implements // Instantiate replication manager if replication enabled. Pass it the // log directories. - createNewReplicationInstance(conf, this, this.fs, logdir, oldLogDir); + createNewReplicationInstance(confManager, this, this.fs, logdir, oldLogDir); // listeners the wal factory will add to wals it creates. final List listeners = new ArrayList(); @@ -1676,24 +1671,26 @@ public class HRegionServer extends HasThread implements private void startServiceThreads() throws IOException { // Start executor services this.service.startExecutorService(ExecutorType.RS_OPEN_REGION, - conf.getInt("hbase.regionserver.executor.openregion.threads", 3)); + confManager.getInt(HConfig.HBASE_REGIONSERVER_EXECUTOR_OPENREGION_THREADS)); this.service.startExecutorService(ExecutorType.RS_OPEN_META, - conf.getInt("hbase.regionserver.executor.openmeta.threads", 1)); + confManager.getInt(HConfig.HBASE_REGIONSERVER_EXECUTOR_OPENMETA_THREADS)); this.service.startExecutorService(ExecutorType.RS_CLOSE_REGION, - conf.getInt("hbase.regionserver.executor.closeregion.threads", 3)); + confManager.getInt(HConfig.HBASE_REGIONSERVER_EXECUTOR_CLOSEREGION_THREADS)); this.service.startExecutorService(ExecutorType.RS_CLOSE_META, - conf.getInt("hbase.regionserver.executor.closemeta.threads", 1)); - if (conf.getBoolean(StoreScanner.STORESCANNER_PARALLEL_SEEK_ENABLE, false)) { + confManager.getInt(HConfig.HBASE_REGIONSERVER_EXECUTOR_CLOSEMETA_THREADS)); + if (confManager.getBoolean(HConfig.HBASE_STORESCANNER_PARALLEL_SEEK_ENABLE)) { this.service.startExecutorService(ExecutorType.RS_PARALLEL_SEEK, - conf.getInt("hbase.storescanner.parallel.seek.threads", 10)); + confManager.getInt(HConfig.HBASE_STORESCANNER_PARALLEL_SEEK_THREADS)); } - this.service.startExecutorService(ExecutorType.RS_LOG_REPLAY_OPS, conf.getInt( - "hbase.regionserver.wal.max.splitters", SplitLogWorkerCoordination.DEFAULT_MAX_SPLITTERS)); + this.service.startExecutorService(ExecutorType.RS_LOG_REPLAY_OPS, + confManager.getInt(HConfig.HBASE_REGIONSERVER_WAL_MAX_SPLITTERS)); if (ServerRegionReplicaUtil.isRegionReplicaWaitForPrimaryFlushEnabled(conf)) { - this.service.startExecutorService(ExecutorType.RS_REGION_REPLICA_FLUSH_OPS, - conf.getInt("hbase.regionserver.region.replica.flusher.threads", - conf.getInt("hbase.regionserver.executor.openregion.threads", 3))); + int flusherThreads = confManager.getInt( + HConfig.HBASE_REGIONSERVER_REGION_REPLICA_FLUSHER_THREADS); + flusherThreads = (flusherThreads != -1) ? flusherThreads : + confManager.getInt(HConfig.HBASE_REGIONSERVER_EXECUTOR_OPENREGION_THREADS); + this.service.startExecutorService(ExecutorType.RS_REGION_REPLICA_FLUSH_OPS, flusherThreads); } Threads.setDaemonThreadRunning(this.walRoller.getThread(), getName() + ".logRoller", @@ -1730,9 +1727,9 @@ public class HRegionServer extends HasThread implements // tasks even after current task is preempted after a split task times out. Configuration sinkConf = HBaseConfiguration.create(conf); sinkConf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, - conf.getInt("hbase.log.replay.retries.number", 8)); // 8 retries take about 23 seconds + confManager.getInt(HConfig.HBASE_LOG_REPLAY_RETRIES_NUMBER)); sinkConf.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, - conf.getInt("hbase.log.replay.rpc.timeout", 30000)); // default 30 seconds + confManager.getInt(HConfig.HBASE_LOG_REPLAY_RPC_TIMEOUT)); sinkConf.setInt("hbase.client.serverside.retries.multiplier", 1); this.splitLogWorker = new SplitLogWorker(this, sinkConf, this, this, walFactory); splitLogWorker.start(); @@ -1744,13 +1741,11 @@ public class HRegionServer extends HasThread implements * @throws IOException */ private int putUpWebUI() throws IOException { - int port = this.conf.getInt(HConstants.REGIONSERVER_INFO_PORT, - HConstants.DEFAULT_REGIONSERVER_INFOPORT); - String addr = this.conf.get("hbase.regionserver.info.bindAddress", "0.0.0.0"); + int port = confManager.getInt(HConfig.HBASE_REGIONSERVER_INFO_PORT); + String addr = confManager.getString(HConfig.HBASE_REGIONSERVER_INFO_BINDADDRESS); if(this instanceof HMaster) { - port = conf.getInt(HConstants.MASTER_INFO_PORT, - HConstants.DEFAULT_MASTER_INFOPORT); + port = confManager.getInt(HConfig.HBASE_MASTER_INFO_PORT); addr = this.conf.get("hbase.master.info.bindAddress", "0.0.0.0"); } // -1 is for disabling info server @@ -1785,12 +1780,11 @@ public class HRegionServer extends HasThread implements port++; } } - port = this.infoServer.getPort(); - conf.setInt(HConstants.REGIONSERVER_INFO_PORT, port); - int masterInfoPort = conf.getInt(HConstants.MASTER_INFO_PORT, - HConstants.DEFAULT_MASTER_INFOPORT); - conf.setInt("hbase.master.info.port.orig", masterInfoPort); - conf.setInt(HConstants.MASTER_INFO_PORT, port); + port = infoServer.getPort(); + confManager.setInt(HConfig.HBASE_REGIONSERVER_INFO_PORT, port); + int masterInfoPort = confManager.getInt(HConfig.HBASE_MASTER_INFO_PORT); + confManager.setInt(HConfig.HBASE_MASTER_INFO_PORT_ORIG, masterInfoPort); + confManager.setInt(HConfig.HBASE_MASTER_INFO_PORT, port); return port; } @@ -2438,7 +2432,7 @@ public class HRegionServer extends HasThread implements @Override public void addToOnlineRegions(Region region) { this.onlineRegions.put(region.getRegionInfo().getEncodedName(), region); - configurationManager.registerObserver(region); + confManager.registerObserver(region); } /** @@ -2581,43 +2575,40 @@ public class HRegionServer extends HasThread implements /** * Load the replication service objects, if any */ - static private void createNewReplicationInstance(Configuration conf, + static private void createNewReplicationInstance(ConfigurationManager confManager, HRegionServer server, FileSystem fs, Path logDir, Path oldLogDir) throws IOException{ // If replication is not enabled, then return immediately. - if (!conf.getBoolean(HConstants.REPLICATION_ENABLE_KEY, - HConstants.REPLICATION_ENABLE_DEFAULT)) { + if (!confManager.getBoolean(HConfig.HBASE_REPLICATION)) { return; } // read in the name of the source replication class from the config file. - String sourceClassname = conf.get(HConstants.REPLICATION_SOURCE_SERVICE_CLASSNAME, - HConstants.REPLICATION_SERVICE_CLASSNAME_DEFAULT); + String sourceClassname = confManager.getString(HConfig.HBASE_REPLICATION_SOURCE_SERVICE); // read in the name of the sink replication class from the config file. - String sinkClassname = conf.get(HConstants.REPLICATION_SINK_SERVICE_CLASSNAME, - HConstants.REPLICATION_SERVICE_CLASSNAME_DEFAULT); + String sinkClassname = confManager.getString(HConfig.HBASE_REPLICATION_SINK_SERVICE); // If both the sink and the source class names are the same, then instantiate // only one object. if (sourceClassname.equals(sinkClassname)) { server.replicationSourceHandler = (ReplicationSourceService) newReplicationInstance(sourceClassname, - conf, server, fs, logDir, oldLogDir); + confManager, server, fs, logDir, oldLogDir); server.replicationSinkHandler = (ReplicationSinkService) server.replicationSourceHandler; } else { server.replicationSourceHandler = (ReplicationSourceService) newReplicationInstance(sourceClassname, - conf, server, fs, logDir, oldLogDir); + confManager, server, fs, logDir, oldLogDir); server.replicationSinkHandler = (ReplicationSinkService) newReplicationInstance(sinkClassname, - conf, server, fs, logDir, oldLogDir); + confManager, server, fs, logDir, oldLogDir); } } static private ReplicationService newReplicationInstance(String classname, - Configuration conf, HRegionServer server, FileSystem fs, Path logDir, + ConfigurationManager confManager, HRegionServer server, FileSystem fs, Path logDir, Path oldLogDir) throws IOException{ Class clazz = null; @@ -2629,8 +2620,8 @@ public class HRegionServer extends HasThread implements } // create an instance of the replication object. - ReplicationService service = (ReplicationService) - ReflectionUtils.newInstance(clazz, conf); + ReplicationService service = + (ReplicationService) ReflectionUtils.newInstance(clazz, confManager.getConfiguration()); service.initialize(server, fs, logDir, oldLogDir); return service; } @@ -3120,7 +3111,7 @@ public class HRegionServer extends HasThread implements } private boolean isHealthCheckerConfigured() { - String healthScriptLocation = this.conf.get(HConstants.HEALTH_SCRIPT_LOC); + String healthScriptLocation = confManager.getString(HConfig.HBASE_NODE_HEALTH_SCRIPT_LOCATION); return org.apache.commons.lang.StringUtils.isNotBlank(healthScriptLocation); } @@ -3276,7 +3267,7 @@ public class HRegionServer extends HasThread implements * @return : Returns the ConfigurationManager object for testing purposes. */ protected ConfigurationManager getConfigurationManager() { - return configurationManager; + return confManager; } /** @@ -3293,7 +3284,7 @@ public class HRegionServer extends HasThread implements LOG.info("Reloading the configuration from disk."); // Reload the configuration from disk. conf.reloadConfiguration(); - configurationManager.notifyAllObservers(conf); + confManager.notifyAllObservers(conf); } @Override diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java index d60087b..a37ec75 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java @@ -36,6 +36,7 @@ import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.DoNotRetryIOException; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValueUtil; @@ -97,8 +98,6 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner /** We don't ever expect to change this, the constant is just for clarity. */ static final boolean LAZY_SEEK_ENABLED_BY_DEFAULT = true; - public static final String STORESCANNER_PARALLEL_SEEK_ENABLE = - "hbase.storescanner.parallel.seek.enable"; /** Used during unit testing to ensure that lazy seek does save seek ops */ protected static boolean lazySeekEnabledGlobally = @@ -180,7 +179,10 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner && store.getStorefilesCount() > 1) { RegionServerServices rsService = ((HStore)store).getHRegion().getRegionServerServices(); if (rsService == null || !rsService.getConfiguration().getBoolean( - STORESCANNER_PARALLEL_SEEK_ENABLE, false)) return; + HConfig.HBASE_STORESCANNER_PARALLEL_SEEK_ENABLE.getName(), + HConfig.HBASE_STORESCANNER_PARALLEL_SEEK_ENABLE.getDefaultValueAsBoolean())) { + return; + } isParallelSeekEnabled = true; executor = rsService.getExecutorService(); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java index cc87f64..c35ee9f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java @@ -81,6 +81,7 @@ import org.apache.hadoop.hbase.ClusterStatus; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseInterfaceAudience; import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionLocation; @@ -317,7 +318,7 @@ public class HBaseFsck extends Configured implements Closeable { // disable blockcache for tool invocation, see HBASE-10500 getConf().setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0); // Disable usage of meta replicas in hbck - getConf().setBoolean(HConstants.USE_META_REPLICAS, false); + getConf().setBoolean(HConfig.HBASE_META_REPLICAS_USE.getName(), false); errors = getErrorReporter(conf); int numThreads = conf.getInt("hbasefsck.numthreads", MAX_NUM_THREADS); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseCluster.java index e6f181b..5d10ce7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseCluster.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.conf.ConfigurationManager; import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService; import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ClientService; import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.MasterService; @@ -59,6 +60,7 @@ public abstract class HBaseCluster implements Closeable, Configurable { // Log is being used in DistributedHBaseCluster class, hence keeping it as package scope static final Log LOG = LogFactory.getLog(HBaseCluster.class.getName()); protected Configuration conf; + protected ConfigurationManager confManager; /** the status of the cluster before we begin */ protected ClusterStatus initialClusterStatus; @@ -69,6 +71,7 @@ public abstract class HBaseCluster implements Closeable, Configurable { */ public HBaseCluster(Configuration conf) { setConf(conf); + confManager = new ConfigurationManager(conf); } @Override @@ -81,6 +84,10 @@ public abstract class HBaseCluster implements Closeable, Configurable { return conf; } + public ConfigurationManager getConfigurationManager() { + return confManager; + } + /** * Returns a ClusterStatus for this HBase cluster. * @see #getInitialClusterStatus() diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index a6d4d77..c36b132 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -72,6 +72,7 @@ import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.TableState; +import org.apache.hadoop.hbase.conf.ConfigurationManager; import org.apache.hadoop.hbase.fs.HFileSystem; import org.apache.hadoop.hbase.io.compress.Compression; import org.apache.hadoop.hbase.io.compress.Compression.Algorithm; @@ -256,6 +257,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { public HBaseTestingUtility(Configuration conf) { super(conf); + confManager = new ConfigurationManager(conf); // a hbase checksum verification failure will cause unit tests to fail ChecksumUtil.generateExceptionForChecksumFailureForTest(true); @@ -320,6 +322,12 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { return super.getConfiguration(); } + protected final ConfigurationManager confManager; + + public ConfigurationManager getConfigurationManager() { + return confManager; + } + public void setHBaseCluster(HBaseCluster hbaseCluster) { this.hbaseCluster = hbaseCluster; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java index ea7f18d..edd6fcb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java @@ -28,6 +28,7 @@ import java.net.URL; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.util.Bytes; @@ -49,11 +50,12 @@ public class TestInfoServers { public static void beforeClass() throws Exception { // The info servers do not run in tests by default. // Set them to ephemeral ports so they will start - UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, 0); - UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, 0); + Configuration conf = UTIL.getConfiguration(); + conf.setInt(HConfig.HBASE_MASTER_INFO_PORT.getName(), 0); + conf.setInt(HConfig.HBASE_REGIONSERVER_INFO_PORT.getName(), 0); //We need to make sure that the server can be started as read only. - UTIL.getConfiguration().setBoolean("hbase.master.ui.readonly", true); + conf.setBoolean("hbase.master.ui.readonly", true); UTIL.startMiniCluster(); if (!UTIL.getHBaseCluster().waitForActiveAndReadyMaster(30000)) { throw new RuntimeException("Active master not ready"); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNodeHealthCheckChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNodeHealthCheckChore.java index 9360b1f..669190f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNodeHealthCheckChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestNodeHealthCheckChore.java @@ -29,14 +29,15 @@ import java.util.UUID; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HealthChecker.HealthCheckerExitStatus; +import org.apache.hadoop.hbase.conf.ConfigurationManager; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.util.Shell; import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -49,6 +50,19 @@ public class TestNodeHealthCheckChore { private File healthScriptFile; private String eol = System.getProperty("line.separator"); + @Before + public void setup() throws IOException { + File tempDir = new File(UTIL.getDataTestDir().toString()); + if (!tempDir.exists()) { + if (!tempDir.mkdirs()) { + throw new IOException("Failed mkdirs " + tempDir); + } + } + String scriptName = "HealthScript" + UUID.randomUUID().toString() + + (Shell.WINDOWS ? ".cmd" : ".sh"); + healthScriptFile = new File(tempDir.getAbsolutePath(), scriptName); + } + @After public void cleanUp() throws IOException { // delete and recreate the test directory, ensuring a clean test dir between tests @@ -78,10 +92,10 @@ public class TestNodeHealthCheckChore { public void healthCheckerTest(String script, HealthCheckerExitStatus expectedStatus) throws Exception { - Configuration config = getConfForNodeHealthScript(); - config.addResource(healthScriptFile.getName()); + ConfigurationManager confManager = getConfManagerForNodeHealthScript(); + confManager.getConfiguration().addResource(healthScriptFile.getName()); String location = healthScriptFile.getAbsolutePath(); - long timeout = config.getLong(HConstants.HEALTH_SCRIPT_TIMEOUT, SCRIPT_TIMEOUT); + long timeout = confManager.getLong(HConfig.HBASE_NODE_HEALTH_SCRIPT_TIMEOUT); HealthChecker checker = new HealthChecker(); checker.init(location, timeout); @@ -98,10 +112,10 @@ public class TestNodeHealthCheckChore { @Test(timeout=60000) public void testRSHealthChore() throws Exception{ Stoppable stop = new StoppableImplementation(); - Configuration conf = getConfForNodeHealthScript(); String errorScript = "echo ERROR" + eol + " echo \"Server not healthy\""; createScript(errorScript, true); - HealthCheckChore rsChore = new HealthCheckChore(100, stop, conf); + HealthCheckChore rsChore = new HealthCheckChore( + 100, stop, getConfManagerForNodeHealthScript()); try { //Default threshold is three. rsChore.chore(); @@ -132,21 +146,13 @@ public class TestNodeHealthCheckChore { LOG.info("Created " + this.healthScriptFile + ", executable=" + setExecutable); } - private Configuration getConfForNodeHealthScript() throws IOException { - Configuration conf = UTIL.getConfiguration(); - File tempDir = new File(UTIL.getDataTestDir().toString()); - if (!tempDir.exists()) { - if (!tempDir.mkdirs()) { - throw new IOException("Failed mkdirs " + tempDir); - } - } - String scriptName = "HealthScript" + UUID.randomUUID().toString() - + (Shell.WINDOWS ? ".cmd" : ".sh"); - healthScriptFile = new File(tempDir.getAbsolutePath(), scriptName); - conf.set(HConstants.HEALTH_SCRIPT_LOC, healthScriptFile.getAbsolutePath()); - conf.setLong(HConstants.HEALTH_FAILURE_THRESHOLD, 3); - conf.setLong(HConstants.HEALTH_SCRIPT_TIMEOUT, SCRIPT_TIMEOUT); - return conf; + private ConfigurationManager getConfManagerForNodeHealthScript() throws IOException { + ConfigurationManager confManager = new ConfigurationManager(UTIL.getConfiguration()); + confManager.setString(HConfig.HBASE_NODE_HEALTH_SCRIPT_LOCATION, + healthScriptFile.getAbsolutePath()); + confManager.setInt(HConfig.HBASE_NODE_HEALTH_FAILURE_THRESHOLD, 3); + confManager.setLong(HConfig.HBASE_NODE_HEALTH_SCRIPT_TIMEOUT, SCRIPT_TIMEOUT); + return confManager; } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaWithReplicas.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaWithReplicas.java index b145109..80038cb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaWithReplicas.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaWithReplicas.java @@ -31,6 +31,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Abortable; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionLocation; @@ -40,6 +41,7 @@ import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.Waiter; +import org.apache.hadoop.hbase.conf.ConfigurationManager; import org.apache.hadoop.hbase.regionserver.StorefileRefresherChore; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; @@ -148,7 +150,8 @@ public class TestMetaWithReplicas { // location of the test table's region ZooKeeperWatcher zkw = util.getZooKeeperWatcher(); Configuration conf = util.getConfiguration(); - conf.setBoolean(HConstants.USE_META_REPLICAS, true); + ConfigurationManager confManager = util.getConfigurationManager(); + confManager.setBoolean(HConfig.HBASE_META_REPLICAS_USE, true); String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT); @@ -216,7 +219,7 @@ public class TestMetaWithReplicas { util.getHBaseClusterInterface().waitForActiveAndReadyMaster(); ((ClusterConnection)c).clearRegionCache(); htable.close(); - conf.setBoolean(HConstants.USE_META_REPLICAS, false); + confManager.setBoolean(HConfig.HBASE_META_REPLICAS_USE, false); htable = c.getTable(TableName.valueOf(TABLE)); r = htable.get(get); assertTrue(Arrays.equals(r.getRow(), row)); @@ -354,8 +357,6 @@ public class TestMetaWithReplicas { @Test public void testAccessingUnknownTables() throws Exception { - Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); - conf.setBoolean(HConstants.USE_META_REPLICAS, true); Table table = TEST_UTIL.getConnection().getTable(TableName.valueOf("RandomTable")); Get get = new Get(Bytes.toBytes("foo")); try { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java index ab4ebc5..4e61243 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java @@ -18,27 +18,622 @@ package org.apache.hadoop.hbase.conf; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.rules.ExpectedException; + +import javax.xml.bind.TypeConstraintException; @Category({SmallTests.class, ClientTests.class}) public class TestConfigurationManager { private static final Log LOG = LogFactory.getLog(TestConfigurationManager.class); + Configuration conf; + ConfigurationManager cm; + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Before + public void setup() { + conf = HConfig.getAsConfiguration(); + cm = new ConfigurationManager(conf); + } + + @Test + /** + * Tests {@link ConfigurationManager#getString(HConfig)}. + * Check default value is returned when value is not set explicitly. + */ + public void testGetString_WhenNotSet_ReturnsDefault() { + assertEquals(HConfig.DUMMY_STRING_FOR_TEST.getDefaultValueAsString(), + cm.getString(HConfig.DUMMY_STRING_FOR_TEST)); + } + + @Test + /** + * Tests {@link ConfigurationManager#getString(HConfig)}. + * Check empty string default value is returned when value is not set explicitly. + */ + public void testGetString_WhenNotSet_ReturnsDefaultEmptyString() { + assertTrue(cm.getString(HConfig.DUMMY_EMPTY_STRING_FOR_TEST).isEmpty()); + } + + @Test + /** + * Tests {@link ConfigurationManager#getString(HConfig)} and {@link ConfigurationManager#setString + * (HConfig, String)}. + * Check same value is returned when it is set explicitly. + */ + public void testSetStringAndGetString() { + String nonDefaultValue = HConfig.DUMMY_STRING_FOR_TEST.getDefaultValueAsString() + "bar"; + cm.setString(HConfig.DUMMY_STRING_FOR_TEST, nonDefaultValue); + + assertEquals(nonDefaultValue, cm.getString(HConfig.DUMMY_STRING_FOR_TEST)); + } + + @Test + /** + * Tests {@link ConfigurationManager#getBoolean(HConfig)}. + * Check default value is returned when value is not set explicitly. + */ + public void testGetBoolean_WhenNotSet_ReturnsDefault() { + assertEquals(HConfig.DUMMY_BOOLEAN_FOR_TEST.getDefaultValueAsBoolean(), + cm.getBoolean(HConfig.DUMMY_BOOLEAN_FOR_TEST)); + } + + @Test + /** + * Tests {@link ConfigurationManager#getBoolean(HConfig)} and {@link + * ConfigurationManager#setBoolean(HConfig, boolean)}. + * Check same value is returned when it is set explicitly. + */ + public void testSetBooleanAndGetBoolean() { + boolean nonDefaultValue = !HConfig.DUMMY_BOOLEAN_FOR_TEST.getDefaultValueAsBoolean(); + cm.setBoolean(HConfig.DUMMY_BOOLEAN_FOR_TEST, nonDefaultValue); + + assertEquals(nonDefaultValue, cm.getBoolean(HConfig.DUMMY_BOOLEAN_FOR_TEST)); + } + + @Test + /** + * Tests {@link ConfigurationManager#getBoolean(HConfig)}. + * When set to invalid value, should return {@link IllegalArgumentException}. + */ + public void testGetBoolean_WhenInvalidValue_ReturnsException() { + conf.set(HConfig.DUMMY_BOOLEAN_FOR_TEST.getName(), "tru"); + + exception.expect(IllegalArgumentException.class); + cm.getBoolean(HConfig.DUMMY_BOOLEAN_FOR_TEST); + } + + @Test + /** + * Tests {@link ConfigurationManager#getInt(HConfig)}. + * Check default value is returned when value is not set explicitly. + */ + public void testGetInt_WhenNotSet_ReturnsDefault() { + assertEquals(HConfig.DUMMY_INT_FOR_TEST.getDefaultValueAsInt(), + cm.getInt(HConfig.DUMMY_INT_FOR_TEST)); + } + + @Test + /** + * Tests {@link ConfigurationManager#getInt(HConfig)} and {@link ConfigurationManager#setInt + * (HConfig, int)}. + * Check same value is returned when it is set explicitly. + */ + public void testSetIntAndGetInt() { + int nonDefaultValue = HConfig.DUMMY_INT_FOR_TEST.getDefaultValueAsInt() + 10; + cm.setInt(HConfig.DUMMY_INT_FOR_TEST, nonDefaultValue); + + assertEquals(nonDefaultValue, cm.getInt(HConfig.DUMMY_INT_FOR_TEST)); + } + + @Test + /** + * Tests {@link ConfigurationManager#getInt(HConfig)}. + * When set to invalid value, should return {@link NumberFormatException}. + */ + public void testGetInt_WhenInvalidValue_ReturnsException() { + conf.set(HConfig.DUMMY_INT_FOR_TEST.getName(), "abc"); + + exception.expect(NumberFormatException.class); + cm.getInt(HConfig.DUMMY_INT_FOR_TEST); + } + + @Test + /** + * Tests {@link ConfigurationManager#getLong(HConfig)}. + * Check default value is returned when value is not set explicitly. + */ + public void testGetLong_WhenNotSet_ReturnsDefault() { + assertEquals(HConfig.DUMMY_LONG_FOR_TEST.getDefaultValueAsLong(), + cm.getLong(HConfig.DUMMY_LONG_FOR_TEST)); + } + + @Test + /** + * Tests {@link ConfigurationManager#getLong(HConfig)} and {@link ConfigurationManager#setLong + * (HConfig, long)}. + * Check same value is returned when it is set explicitly. + */ + public void testSetLongAndGetLong() { + long nonDefaultValue = HConfig.DUMMY_LONG_FOR_TEST.getDefaultValueAsLong() + 10; + cm.setLong(HConfig.DUMMY_LONG_FOR_TEST, nonDefaultValue); + + assertEquals(nonDefaultValue, cm.getLong(HConfig.DUMMY_LONG_FOR_TEST)); + } + + @Test + /** + * Tests {@link ConfigurationManager#getLong(HConfig)}. + * When set to invalid value, should return {@link NumberFormatException}. + */ + public void testGetLong_WhenInvalidValue_ReturnsException() { + conf.set(HConfig.DUMMY_LONG_FOR_TEST.getName(), "abc"); + + exception.expect(NumberFormatException.class); + cm.getLong(HConfig.DUMMY_LONG_FOR_TEST); + } + + @Test + /** + * Tests {@link ConfigurationManager#getFloat(HConfig)}. + * Check default value is returned when value is not set explicitly. + */ + public void testGetFloat_WhenNotSet_ReturnsDefault() { + assertEquals(HConfig.DUMMY_FLOAT_FOR_TEST.getDefaultValueAsFloat(), + cm.getFloat(HConfig.DUMMY_FLOAT_FOR_TEST), 0.001); + } + + @Test + /** + * Tests {@link ConfigurationManager#getFloat(HConfig)} and {@link ConfigurationManager#setFloat + * (HConfig, float)}. + * Check same value is returned when it is set explicitly. + */ + public void testSetFloatAndGetFloat() { + float nonDefaultValue = HConfig.DUMMY_FLOAT_FOR_TEST.getDefaultValueAsFloat() + 8.88f; + cm.setFloat(HConfig.DUMMY_FLOAT_FOR_TEST, nonDefaultValue); + + assertEquals(nonDefaultValue, cm.getFloat(HConfig.DUMMY_FLOAT_FOR_TEST), 0.001); + } + + @Test + /** + * Tests {@link ConfigurationManager#getFloat(HConfig)}. + * When set to invalid value, should return {@link NumberFormatException}. + */ + public void testGetFloat_WhenInvalidValue_ReturnsException() { + conf.set(HConfig.DUMMY_FLOAT_FOR_TEST.getName(), "abc"); + + exception.expect(NumberFormatException.class); + cm.getFloat(HConfig.DUMMY_FLOAT_FOR_TEST); + } + + @Test + /** + * Tests {@link ConfigurationManager#getDouble(HConfig)}. + * Check default value is returned when value is not set explicitly. + */ + public void testGetDouble_WhenNotSet_ReturnsDefault() { + assertEquals(HConfig.DUMMY_DOUBLE_FOR_TEST.getDefaultValueAsDouble(), + cm.getDouble(HConfig.DUMMY_DOUBLE_FOR_TEST), 0.001); + } + + @Test + /** + * Tests {@link ConfigurationManager#getDouble(HConfig)} and {@link ConfigurationManager#setDouble + * (HConfig, double)}. + * Check same value is returned when it is set explicitly. + */ + public void testSetDoubleGetDouble() { + double nonDefaultValue = HConfig.DUMMY_DOUBLE_FOR_TEST.getDefaultValueAsDouble() + 8.88; + cm.setDouble(HConfig.DUMMY_DOUBLE_FOR_TEST, nonDefaultValue); + + assertEquals(nonDefaultValue, cm.getDouble(HConfig.DUMMY_DOUBLE_FOR_TEST), 0.001); + } + + @Test + /** + * Tests {@link ConfigurationManager#getDouble(HConfig)}. + * When set to invalid value, should return {@link NumberFormatException}. + */ + public void testGetDouble_WhenInvalidValue_ReturnsException() { + conf.set(HConfig.DUMMY_DOUBLE_FOR_TEST.getName(), "abc"); + + exception.expect(NumberFormatException.class); + cm.getDouble(HConfig.DUMMY_DOUBLE_FOR_TEST); + } + + @Test + /** + * Tests {@link ConfigurationManager#getStrings(HConfig)}. + * Check default value is returned when value is not set explicitly. + */ + public void testGetStrings_WhenNotSet_ReturnsDefault() { + String[] expectedValue = new String[]{"foo", "bar", "pikachu"}; + assertArrayEquals(expectedValue, cm.getStrings(HConfig.DUMMY_CSV_STRINGS_FOR_TEST)); + } + + @Test + /** + * Tests {@link ConfigurationManager#getStrings(HConfig)}. + * Check null is returned when value is empty string. + */ + public void testGetStrings_WhenEmptyString_ReturnsNull() { + assertNull(cm.getStrings(HConfig.DUMMY_EMPTY_STRING_FOR_TEST)); + } + + @Test + /** + * Tests {@link ConfigurationManager#getStrings(HConfig)} and {@link + * ConfigurationManager#setStrings(HConfig, String)}. + * Check same value is returned when it is set explicitly. + */ + public void testSetStringsAndGetStrings() { + String[] expectedValue = new String[]{"mario", "luigi"}; + cm.setStrings(HConfig.DUMMY_CSV_STRINGS_FOR_TEST, expectedValue); + + assertArrayEquals(expectedValue, cm.getStrings(HConfig.DUMMY_CSV_STRINGS_FOR_TEST)); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#setString(HConfig, String)}. + */ + public void testSetStringAssertions() { + // no assertion error. + cm.setString(HConfig.DUMMY_STRING_FOR_TEST, "foo"); + + exception.expect(TypeConstraintException.class); + cm.setString(HConfig.DUMMY_BOOLEAN_FOR_TEST, "foo"); + + exception.expect(TypeConstraintException.class); + cm.setString(HConfig.DUMMY_INT_FOR_TEST, "foo"); + + exception.expect(TypeConstraintException.class); + cm.setString(HConfig.DUMMY_LONG_FOR_TEST, "foo"); + + exception.expect(TypeConstraintException.class); + cm.setString(HConfig.DUMMY_FLOAT_FOR_TEST, "foo"); + + exception.expect(TypeConstraintException.class); + cm.setString(HConfig.DUMMY_DOUBLE_FOR_TEST, "foo"); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#getString(HConfig)}. + */ + public void testGetStringAssertions() { + // no assertion error. + cm.getString(HConfig.DUMMY_STRING_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getString(HConfig.DUMMY_BOOLEAN_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getString(HConfig.DUMMY_INT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getString(HConfig.DUMMY_LONG_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getString(HConfig.DUMMY_FLOAT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getString(HConfig.DUMMY_DOUBLE_FOR_TEST); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#setBoolean(HConfig, boolean)}. + */ + public void testSetBooleanAssertions() { + // no assertion error. + cm.setBoolean(HConfig.DUMMY_BOOLEAN_FOR_TEST, true); + + exception.expect(TypeConstraintException.class); + cm.setBoolean(HConfig.DUMMY_STRING_FOR_TEST, true); + + exception.expect(TypeConstraintException.class); + cm.setBoolean(HConfig.DUMMY_INT_FOR_TEST, true); + + exception.expect(TypeConstraintException.class); + cm.setBoolean(HConfig.DUMMY_LONG_FOR_TEST, true); + + exception.expect(TypeConstraintException.class); + cm.setBoolean(HConfig.DUMMY_FLOAT_FOR_TEST, true); + + exception.expect(TypeConstraintException.class); + cm.setBoolean(HConfig.DUMMY_DOUBLE_FOR_TEST, true); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#getBoolean(HConfig)}. + */ + public void testGetBooleanAssertions() { + // no assertion error. + cm.getBoolean(HConfig.DUMMY_BOOLEAN_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getBoolean(HConfig.DUMMY_STRING_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getBoolean(HConfig.DUMMY_INT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getBoolean(HConfig.DUMMY_LONG_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getBoolean(HConfig.DUMMY_FLOAT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getBoolean(HConfig.DUMMY_DOUBLE_FOR_TEST); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#setInt(HConfig, int)}. + */ + public void testSetIntAssertions() { + // no assertion error. + cm.setInt(HConfig.DUMMY_INT_FOR_TEST, 1); + + exception.expect(TypeConstraintException.class); + cm.setInt(HConfig.DUMMY_BOOLEAN_FOR_TEST, 1); + + exception.expect(TypeConstraintException.class); + cm.setInt(HConfig.DUMMY_STRING_FOR_TEST, 1); + + exception.expect(TypeConstraintException.class); + cm.setInt(HConfig.DUMMY_LONG_FOR_TEST, 1); + + exception.expect(TypeConstraintException.class); + cm.setInt(HConfig.DUMMY_FLOAT_FOR_TEST, 1); + + exception.expect(TypeConstraintException.class); + cm.setInt(HConfig.DUMMY_DOUBLE_FOR_TEST, 1); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#getInt(HConfig)}. + */ + public void testGetIntAssertions() { + // no assertion error. + cm.getInt(HConfig.DUMMY_INT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getInt(HConfig.DUMMY_BOOLEAN_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getInt(HConfig.DUMMY_STRING_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getInt(HConfig.DUMMY_LONG_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getInt(HConfig.DUMMY_FLOAT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getInt(HConfig.DUMMY_DOUBLE_FOR_TEST); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#setLong(HConfig, long)}. + */ + public void testSetLongAssertions() { + // no assertion error. + cm.setLong(HConfig.DUMMY_LONG_FOR_TEST, 1L); + + exception.expect(TypeConstraintException.class); + cm.setLong(HConfig.DUMMY_BOOLEAN_FOR_TEST, 1L); + + exception.expect(TypeConstraintException.class); + cm.setLong(HConfig.DUMMY_INT_FOR_TEST, 1L); + + exception.expect(TypeConstraintException.class); + cm.setLong(HConfig.DUMMY_STRING_FOR_TEST, 1L); + + exception.expect(TypeConstraintException.class); + cm.setLong(HConfig.DUMMY_FLOAT_FOR_TEST, 1L); + + exception.expect(TypeConstraintException.class); + cm.setLong(HConfig.DUMMY_DOUBLE_FOR_TEST, 1L); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#getLong(HConfig)}. + */ + public void testGetLongAssertions() { + // no assertion error. + cm.getLong(HConfig.DUMMY_LONG_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getLong(HConfig.DUMMY_BOOLEAN_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getLong(HConfig.DUMMY_INT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getLong(HConfig.DUMMY_STRING_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getLong(HConfig.DUMMY_FLOAT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getLong(HConfig.DUMMY_DOUBLE_FOR_TEST); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#setFloat(HConfig, float)}. + */ + public void testSetFloatAssertions() { + // no assertion error. + cm.setFloat(HConfig.DUMMY_FLOAT_FOR_TEST, 1.0f); + + exception.expect(TypeConstraintException.class); + cm.setFloat(HConfig.DUMMY_BOOLEAN_FOR_TEST, 1.0f); + + exception.expect(TypeConstraintException.class); + cm.setFloat(HConfig.DUMMY_INT_FOR_TEST, 1.0f); + + exception.expect(TypeConstraintException.class); + cm.setFloat(HConfig.DUMMY_LONG_FOR_TEST, 1.0f); + + exception.expect(TypeConstraintException.class); + cm.setFloat(HConfig.DUMMY_STRING_FOR_TEST, 1.0f); + + exception.expect(TypeConstraintException.class); + cm.setFloat(HConfig.DUMMY_DOUBLE_FOR_TEST, 1.0f); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#getFloat(HConfig)}. + */ + public void testGetFloatAssertions() { + // no assertion error. + cm.getFloat(HConfig.DUMMY_FLOAT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getFloat(HConfig.DUMMY_BOOLEAN_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getFloat(HConfig.DUMMY_INT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getFloat(HConfig.DUMMY_LONG_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getFloat(HConfig.DUMMY_STRING_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getFloat(HConfig.DUMMY_DOUBLE_FOR_TEST); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#setDouble(HConfig, double)}. + */ + public void testSetDoubleAssertions() { + // no assertion error. + cm.setDouble(HConfig.DUMMY_DOUBLE_FOR_TEST, 1.0); + + exception.expect(TypeConstraintException.class); + cm.setDouble(HConfig.DUMMY_BOOLEAN_FOR_TEST, 1.0); + + exception.expect(TypeConstraintException.class); + cm.setDouble(HConfig.DUMMY_INT_FOR_TEST, 1.0); + + exception.expect(TypeConstraintException.class); + cm.setDouble(HConfig.DUMMY_LONG_FOR_TEST, 1.0); + + exception.expect(TypeConstraintException.class); + cm.setDouble(HConfig.DUMMY_FLOAT_FOR_TEST, 1.0); + + exception.expect(TypeConstraintException.class); + cm.setDouble(HConfig.DUMMY_STRING_FOR_TEST, 1.0); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#getDouble(HConfig)}. + */ + public void testGetDoubleAssertions() { + // no assertion error. + cm.getDouble(HConfig.DUMMY_DOUBLE_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getDouble(HConfig.DUMMY_BOOLEAN_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getDouble(HConfig.DUMMY_INT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getDouble(HConfig.DUMMY_LONG_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getDouble(HConfig.DUMMY_FLOAT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getDouble(HConfig.DUMMY_STRING_FOR_TEST); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#setStrings(HConfig, String...)} + */ + public void testExceptionInSetStrings() { + // no assertion error. + cm.setStrings(HConfig.DUMMY_STRING_FOR_TEST, "foo", "bar"); + + exception.expect(TypeConstraintException.class); + cm.setStrings(HConfig.DUMMY_BOOLEAN_FOR_TEST, "foo", "bar"); + + exception.expect(TypeConstraintException.class); + cm.setStrings(HConfig.DUMMY_INT_FOR_TEST, "foo", "bar"); + + exception.expect(TypeConstraintException.class); + cm.setStrings(HConfig.DUMMY_LONG_FOR_TEST, "foo", "bar"); + + exception.expect(TypeConstraintException.class); + cm.setStrings(HConfig.DUMMY_FLOAT_FOR_TEST, "foo", "bar"); + + exception.expect(TypeConstraintException.class); + cm.setStrings(HConfig.DUMMY_DOUBLE_FOR_TEST, "foo", "bar"); + } + + @Test + /** + * Tests assertions in {@link ConfigurationManager#getStrings(HConfig)}. + */ + public void testGetStringsAssertions() { + // no assertion error. + cm.getStrings(HConfig.DUMMY_STRING_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getStrings(HConfig.DUMMY_BOOLEAN_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getStrings(HConfig.DUMMY_INT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getStrings(HConfig.DUMMY_LONG_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getStrings(HConfig.DUMMY_FLOAT_FOR_TEST); + + exception.expect(TypeConstraintException.class); + cm.getStrings(HConfig.DUMMY_DOUBLE_FOR_TEST); + } + class DummyConfigurationObserver implements ConfigurationObserver { private boolean notifiedOnChange = false; - private ConfigurationManager cm; + private ConfigurationManager confManager; - public DummyConfigurationObserver(ConfigurationManager cm) { - this.cm = cm; + public DummyConfigurationObserver(ConfigurationManager confManager) { + this.confManager = confManager; register(); } @@ -56,11 +651,11 @@ public class TestConfigurationManager { } public void register() { - this.cm.registerObserver(this); + this.confManager.registerObserver(this); } public void deregister() { - this.cm.deregisterObserver(this); + this.confManager.deregisterObserver(this); } } @@ -71,7 +666,7 @@ public class TestConfigurationManager { @Test public void testCheckIfObserversNotified() { Configuration conf = new Configuration(); - ConfigurationManager cm = new ConfigurationManager(); + ConfigurationManager cm = new ConfigurationManager(conf); DummyConfigurationObserver d1 = new DummyConfigurationObserver(cm); // Check if we get notified. @@ -107,7 +702,7 @@ public class TestConfigurationManager { @Test public void testDeregisterOnOutOfScope() { Configuration conf = new Configuration(); - ConfigurationManager cm = new ConfigurationManager(); + ConfigurationManager cm = new ConfigurationManager(conf); boolean outOfScopeObserversDeregistered = false; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDistributedLogSplitting.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDistributedLogSplitting.java index bc437fc..832c5a1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDistributedLogSplitting.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDistributedLogSplitting.java @@ -57,6 +57,7 @@ import org.apache.hadoop.fs.PathFilter; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; @@ -165,9 +166,9 @@ public class TestDistributedLogSplitting { conf.getLong("hbase.splitlog.max.resubmit", 0); // Make the failure test faster conf.setInt("zookeeper.recovery.retry", 0); - conf.setInt(HConstants.REGIONSERVER_INFO_PORT, -1); + conf.setInt(HConfig.HBASE_REGIONSERVER_INFO_PORT.getName(), -1); conf.setFloat(HConstants.LOAD_BALANCER_SLOP_KEY, (float) 100.0); // no load balancing - conf.setInt("hbase.regionserver.wal.max.splitters", 3); + conf.setInt(HConfig.HBASE_REGIONSERVER_WAL_MAX_SPLITTERS.getName(), 3); conf.setInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, 40); TEST_UTIL.shutdownMiniHBaseCluster(); TEST_UTIL = new HBaseTestingUtility(conf); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java index 418bddc..94a19ed 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.master; import static org.junit.Assert.assertTrue; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; @@ -38,7 +39,7 @@ public class TestGetInfoPort { @Before public void setUp() throws Exception { - testUtil.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, 0); + testUtil.getConfigurationManager().setInt(HConfig.HBASE_MASTER_INFO_PORT, 0); testUtil.startMiniCluster(1, 1); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java index 5498d66..47ab5c8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java @@ -64,7 +64,7 @@ public class TestRegionServerMetrics { conf.getLong("hbase.splitlog.max.resubmit", 0); // Make the failure test faster conf.setInt("zookeeper.recovery.retry", 0); - conf.setInt(HConstants.REGIONSERVER_INFO_PORT, -1); + TEST_UTIL.getConfigurationManager().setInt(HConfig.HBASE_REGIONSERVER_INFO_PORT, -1); TEST_UTIL.startMiniCluster(1, 1); cluster = TEST_UTIL.getHBaseCluster(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitLogWorker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitLogWorker.java index d62ccde..7490d95 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitLogWorker.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitLogWorker.java @@ -37,6 +37,7 @@ import org.apache.hadoop.hbase.CoordinatedStateManager; import org.apache.hadoop.hbase.CoordinatedStateManagerFactory; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.ServerName; @@ -434,7 +435,7 @@ public class TestSplitLogWorker { final ServerName RS = ServerName.valueOf("rs,1,1"); final int maxTasks = 3; Configuration testConf = HBaseConfiguration.create(TEST_UTIL.getConfiguration()); - testConf.setInt("hbase.regionserver.wal.max.splitters", maxTasks); + testConf.setInt(HConfig.HBASE_REGIONSERVER_WAL_MAX_SPLITTERS.getName(), maxTasks); RegionServerServices mockedRS = getRegionServer(RS); for (int i = 0; i < maxTasks; i++) { zkw.getRecoverableZooKeeper().create(ZKSplitLog.getEncodedNodeName(zkw, TATAS + i), @@ -470,7 +471,7 @@ public class TestSplitLogWorker { final ServerName RS2 = ServerName.valueOf("rs,1,2"); final int maxTasks = 3; Configuration testConf = HBaseConfiguration.create(TEST_UTIL.getConfiguration()); - testConf.setInt("hbase.regionserver.wal.max.splitters", maxTasks); + testConf.setInt(HConfig.HBASE_REGIONSERVER_WAL_MAX_SPLITTERS.getName(), maxTasks); RegionServerServices mockedRS = getRegionServer(RS); // create two RS nodes diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/ProcessBasedLocalHBaseCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/ProcessBasedLocalHBaseCluster.java index 9f98624..7eac985 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/ProcessBasedLocalHBaseCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/ProcessBasedLocalHBaseCluster.java @@ -43,6 +43,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.TableName; @@ -388,13 +389,13 @@ public class ProcessBasedLocalHBaseCluster { int masterInfoPort = HBaseTestingUtility.randomFreePort(); reportWebUIPort("master", masterInfoPort); - confMap.put(HConstants.MASTER_INFO_PORT, masterInfoPort); + confMap.put(HConfig.HBASE_MASTER_INFO_PORT.getName(), masterInfoPort); } else if (serverType == ServerType.RS) { confMap.put(HConstants.REGIONSERVER_PORT, rpcPort); int rsInfoPort = HBaseTestingUtility.randomFreePort(); reportWebUIPort("region server", rsInfoPort); - confMap.put(HConstants.REGIONSERVER_INFO_PORT, rsInfoPort); + confMap.put(HConfig.HBASE_REGIONSERVER_INFO_PORT.getName(), rsInfoPort); } else { confMap.put(HConstants.ZOOKEEPER_DATA_DIR, daemonDir); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java index 866382d..f597c6d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java @@ -33,6 +33,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; @@ -99,8 +100,8 @@ public class TestCoprocessorScanPolicy { } public TestCoprocessorScanPolicy(boolean parallelSeekEnable) { - TEST_UTIL.getMiniHBaseCluster().getConf() - .setBoolean(StoreScanner.STORESCANNER_PARALLEL_SEEK_ENABLE, parallelSeekEnable); + TEST_UTIL.getMiniHBaseCluster().getConfigurationManager() + .setBoolean(HConfig.HBASE_STORESCANNER_PARALLEL_SEEK_ENABLE, parallelSeekEnable); } @Test diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/AbstractTestShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/AbstractTestShell.java index 24d07ed..2fa79ea 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/AbstractTestShell.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/AbstractTestShell.java @@ -20,8 +20,11 @@ package org.apache.hadoop.hbase.client; import java.util.ArrayList; import java.util.List; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConfig; import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.conf.ConfigurationManager; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; import org.apache.hadoop.hbase.security.access.SecureTestUtil; import org.apache.hadoop.hbase.security.visibility.VisibilityTestUtil; @@ -37,17 +40,19 @@ public abstract class AbstractTestShell { @BeforeClass public static void setUpBeforeClass() throws Exception { // Start mini cluster - TEST_UTIL.getConfiguration().setBoolean("hbase.online.schema.update.enable", true); - TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100); - TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250); - TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6); - TEST_UTIL.getConfiguration().setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false); - TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3); - TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, -1); - TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, -1); + Configuration conf = TEST_UTIL.getConfiguration(); + conf.setBoolean("hbase.online.schema.update.enable", true); + conf.setInt("hbase.regionserver.msginterval", 100); + conf.setInt("hbase.client.pause", 250); + conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6); + conf.setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false); + conf.setInt("hfile.format.version", 3); + ConfigurationManager confManager = TEST_UTIL.getConfigurationManager(); + confManager.setInt(HConfig.HBASE_MASTER_INFO_PORT, -1); + confManager.setInt(HConfig.HBASE_REGIONSERVER_INFO_PORT, -1); // Security setup configuration - SecureTestUtil.enableSecurity(TEST_UTIL.getConfiguration()); - VisibilityTestUtil.enableVisiblityLabels(TEST_UTIL.getConfiguration()); + SecureTestUtil.enableSecurity(conf); + VisibilityTestUtil.enableVisiblityLabels(conf); TEST_UTIL.startMiniCluster(); -- 2.3.2 (Apple Git-55)