diff --git a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index c9ee423cf73706feb2774dacca9fc7b94fe80617..1946a466e31c851a2c51655baea558bcd8227cf3 100644 --- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -115,6 +115,7 @@ public void setSparkConfigUpdated(boolean isSparkConfigUpdated) { public static final HiveConf.ConfVars[] metaVars = { HiveConf.ConfVars.METASTOREWAREHOUSE, HiveConf.ConfVars.METASTOREURIS, + HiveConf.ConfVars.METASTORE_SERVER_PORT, HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, HiveConf.ConfVars.METASTORETHRIFTFAILURERETRIES, HiveConf.ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY, @@ -381,7 +382,7 @@ public void setSparkConfigUpdated(boolean isSparkConfigUpdated) { "Number of retries while opening a connection to metastore"), METASTORETHRIFTFAILURERETRIES("hive.metastore.failure.retries", 1, "Number of retries upon failure of Thrift metastore calls"), - + METASTORE_SERVER_PORT("hive.metastore.port", 9083, "Hive Metastore listener port"), METASTORE_CLIENT_CONNECT_RETRY_DELAY("hive.metastore.client.connect.retry.delay", "1s", new TimeValidator(TimeUnit.SECONDS), "Number of seconds for the client to wait between consecutive connection attempts"), diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 3f267ff0eb20560c36a19b74353f9d6749c8b333..5f40fe62939a8c1d1b1f81c0d1082a63a2497d76 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -259,7 +259,6 @@ protected DateFormat initialValue() { /** * default port on which to start the Hive server */ - private static final int DEFAULT_HIVE_METASTORE_PORT = 9083; public static final String ADMIN = "admin"; public static final String PUBLIC = "public"; @@ -5775,18 +5774,19 @@ public static long renewDelegationToken(String tokenStrForm * */ static public class HiveMetastoreCli extends CommonCliOptions { - int port = DEFAULT_HIVE_METASTORE_PORT; + private int port; @SuppressWarnings("static-access") - public HiveMetastoreCli() { + public HiveMetastoreCli(Configuration configuration) { super("hivemetastore", true); + this.port = HiveConf.getIntVar(configuration, HiveConf.ConfVars.METASTORE_SERVER_PORT); // -p port OPTIONS.addOption(OptionBuilder .hasArg() .withArgName("port") .withDescription("Hive Metastore port number, default:" - + DEFAULT_HIVE_METASTORE_PORT) + + this.port) .create('p')); } @@ -5803,21 +5803,19 @@ public void parse(String[] args) { "This usage has been deprecated, consider using the new command " + "line syntax (run with -h to see usage information)"); - port = new Integer(args[0]); + this.port = new Integer(args[0]); } // notice that command line options take precedence over the // deprecated (old style) naked args... if (commandLine.hasOption('p')) { - port = Integer.parseInt(commandLine.getOptionValue('p')); - } else { - // legacy handling - String metastorePort = System.getenv("METASTORE_PORT"); - if (metastorePort != null) { - port = Integer.parseInt(metastorePort); - } + this.port = Integer.parseInt(commandLine.getOptionValue('p')); } } + + public int port() { + return this.port; + } } /** @@ -5825,7 +5823,9 @@ public void parse(String[] args) { */ public static void main(String[] args) throws Throwable { HiveConf.setLoadMetastoreConfig(true); - HiveMetastoreCli cli = new HiveMetastoreCli(); + HiveConf conf = new HiveConf(HMSHandler.class); + + HiveMetastoreCli cli = new HiveMetastoreCli(conf); cli.parse(args); final boolean isCliVerbose = cli.isVerbose(); // NOTE: It is critical to do this prior to initializing log4j, otherwise @@ -5851,7 +5851,6 @@ public static void main(String[] args) throws Throwable { System.err.println(msg); } - HiveConf conf = new HiveConf(HMSHandler.class); // set all properties specified on the command line for (Map.Entry item : hiveconf.entrySet()) { @@ -5870,11 +5869,12 @@ public void run() { } }); + Lock startLock = new ReentrantLock(); Condition startCondition = startLock.newCondition(); AtomicBoolean startedServing = new AtomicBoolean(); startMetaStoreThreads(conf, startLock, startCondition, startedServing); - startMetaStore(cli.port, ShimLoader.getHadoopThriftAuthBridge(), conf, startLock, + startMetaStore(cli.port(), ShimLoader.getHadoopThriftAuthBridge(), conf, startLock, startCondition, startedServing); } catch (Throwable t) { // Catch the exception, log it and rethrow it. diff --git a/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetastoreCli.java b/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetastoreCli.java new file mode 100644 index 0000000000000000000000000000000000000000..12812eae76f4539f33bcb759b93c7df2def410ac --- /dev/null +++ b/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetastoreCli.java @@ -0,0 +1,48 @@ +package org.apache.hadoop.hive.metastore; + +import org.apache.hadoop.hive.conf.HiveConf; +import org.junit.Test; + +/** + * Created by sircodesalot on 4/28/15. + */ +public class TestHiveMetastoreCli { + private static final String[] CLI_ARGUMENTS = { "9999" }; + + @Test + public void testDefaultCliPortValue() { + HiveConf configuration = new HiveConf(); + HiveMetaStore.HiveMetastoreCli cli = new HiveMetaStore.HiveMetastoreCli(configuration); + assert (cli.port() == HiveConf.getIntVar(configuration, HiveConf.ConfVars.METASTORE_SERVER_PORT)); + } + + @Test + public void testOverriddenCliPortValue() { + HiveConf configuration = new HiveConf(); + HiveMetaStore.HiveMetastoreCli cli = new HiveMetaStore.HiveMetastoreCli(configuration); + cli.parse(TestHiveMetastoreCli.CLI_ARGUMENTS); + + assert (cli.port() == 9999); + } + + @Test + public void testOverriddenMetastoreServerPortValue() { + HiveConf configuration = new HiveConf(); + HiveConf.setIntVar(configuration, HiveConf.ConfVars.METASTORE_SERVER_PORT, 12345); + + HiveMetaStore.HiveMetastoreCli cli = new HiveMetaStore.HiveMetastoreCli(configuration); + + assert (cli.port() == 12345); + } + + @Test + public void testCliOverridesConfiguration() { + HiveConf configuration = new HiveConf(); + HiveConf.setIntVar(configuration, HiveConf.ConfVars.METASTORE_SERVER_PORT, 12345); + + HiveMetaStore.HiveMetastoreCli cli = new HiveMetaStore.HiveMetastoreCli(configuration); + cli.parse(CLI_ARGUMENTS); + + assert (cli.port() == 9999); + } +}