You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by sp...@apache.org on 2015/05/07 17:06:20 UTC
hive git commit: HIVE-9365: The Metastore should take port
configuration from hive-site.xml (Reuben Kuhnert, reviewed by Sergio Pena)
Repository: hive
Updated Branches:
refs/heads/master e24662c3d -> d434f6459
HIVE-9365: The Metastore should take port configuration from hive-site.xml (Reuben Kuhnert, reviewed by Sergio Pena)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/d434f645
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/d434f645
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/d434f645
Branch: refs/heads/master
Commit: d434f6459050fbb1b12875b3015474fed2b6b914
Parents: e24662c
Author: Sergio Pena <se...@cloudera.com>
Authored: Thu May 7 10:05:45 2015 -0500
Committer: Sergio Pena <se...@cloudera.com>
Committed: Thu May 7 10:05:45 2015 -0500
----------------------------------------------------------------------
.../org/apache/hadoop/hive/conf/HiveConf.java | 3 +-
.../hadoop/hive/metastore/HiveMetaStore.java | 27 +++++----
.../hive/metastore/TestHiveMetastoreCli.java | 63 ++++++++++++++++++++
3 files changed, 82 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/d434f645/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
----------------------------------------------------------------------
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 85e732f..5d5a928 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 class HiveConf extends Configuration {
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,
@@ -392,7 +393,7 @@ public class HiveConf extends Configuration {
"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"),
http://git-wip-us.apache.org/repos/asf/hive/blob/d434f645/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
----------------------------------------------------------------------
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 3f267ff..986579a 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 @@ public class HiveMetaStore extends ThriftHiveMetastore {
/**
* 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 class HiveMetaStore extends ThriftHiveMetastore {
*
*/
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,26 @@ public class HiveMetaStore extends ThriftHiveMetastore {
"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'));
+ this.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(metastorePort);
}
}
}
+
+ public int getPort() {
+ return this.port;
+ }
}
/**
@@ -5825,7 +5830,9 @@ public class HiveMetaStore extends ThriftHiveMetastore {
*/
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 +5858,6 @@ public class HiveMetaStore extends ThriftHiveMetastore {
System.err.println(msg);
}
- HiveConf conf = new HiveConf(HMSHandler.class);
// set all properties specified on the command line
for (Map.Entry<Object, Object> item : hiveconf.entrySet()) {
@@ -5870,11 +5876,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
}
});
+
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.getPort(), ShimLoader.getHadoopThriftAuthBridge(), conf, startLock,
startCondition, startedServing);
} catch (Throwable t) {
// Catch the exception, log it and rethrow it.
http://git-wip-us.apache.org/repos/asf/hive/blob/d434f645/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetastoreCli.java
----------------------------------------------------------------------
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 0000000..f581c7d
--- /dev/null
+++ b/metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetastoreCli.java
@@ -0,0 +1,63 @@
+/**
+ * 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.hive.metastore;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.junit.Test;
+
+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.getPort() == 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.getPort() == 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.getPort() == 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.getPort() == 9999);
+ }
+}