hive git commit: HIVE-18449 : Add configurable policy for choosing the HMS URI from hive.metastore.uris (Janaki Lahorani, reviewed by Vihang Karajgaonkar)

2018-02-22 Thread vihangk1
Repository: hive
Updated Branches:
  refs/heads/branch-2 042296fbc -> d72c35e47


HIVE-18449 : Add configurable policy for choosing the HMS URI from 
hive.metastore.uris (Janaki Lahorani, reviewed by Vihang Karajgaonkar)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/d72c35e4
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/d72c35e4
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/d72c35e4

Branch: refs/heads/branch-2
Commit: d72c35e478c68898877b93f7294f178bfcdd0c87
Parents: 042296f
Author: Vihang Karajgaonkar 
Authored: Thu Feb 22 17:44:09 2018 -0800
Committer: Vihang Karajgaonkar 
Committed: Thu Feb 22 17:44:09 2018 -0800

--
 .../org/apache/hadoop/hive/conf/HiveConf.java |  7 +++
 .../hive/metastore/HiveMetaStoreClient.java   | 18 +++---
 2 files changed, 18 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hive/blob/d72c35e4/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 4a92ffc..df2aee8 100644
--- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
+++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
@@ -212,6 +212,7 @@ public class HiveConf extends Configuration {
   HiveConf.ConfVars.METASTOREWAREHOUSE,
   HiveConf.ConfVars.REPLDIR,
   HiveConf.ConfVars.METASTOREURIS,
+  HiveConf.ConfVars.METASTORESELECTION,
   HiveConf.ConfVars.METASTORE_SERVER_PORT,
   HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES,
   HiveConf.ConfVars.METASTORETHRIFTFAILURERETRIES,
@@ -598,6 +599,12 @@ public class HiveConf extends Configuration {
 
 METASTORE_CAPABILITY_CHECK("hive.metastore.client.capability.check", true,
 "Whether to check client capabilities for potentially breaking API 
usage."),
+METASTORESELECTION("hive.metastore.uri.selection", "RANDOM",
+new StringSet("SEQUENTIAL", "RANDOM"),
+"Determines the selection mechanism used by metastore client to 
connect to remote " +
+"metastore.  SEQUENTIAL implies that the first valid metastore from 
the URIs specified " +
+"as part of hive.metastore.uris will be picked.  RANDOM implies that 
the metastore " +
+"will be picked randomly"),
 METASTORE_FASTPATH("hive.metastore.fastpath", false,
 "Used to avoid all of the proxies and object copies in the metastore.  
Note, if this is " +
 "set, you MUST use a local metastore (hive.metastore.uris must be 
empty) otherwise " +

http://git-wip-us.apache.org/repos/asf/hive/blob/d72c35e4/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
--
diff --git 
a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java 
b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
index 7dcd13e..83c2860 100644
--- 
a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
+++ 
b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
@@ -203,9 +203,11 @@ public class HiveMetaStoreClient implements 
IMetaStoreClient {
 
 }
 // make metastore URIS random
-List uriList = Arrays.asList(metastoreUris);
-Collections.shuffle(uriList);
-metastoreUris = (URI[]) uriList.toArray();
+if (HiveConf.getVar(conf, 
ConfVars.METASTORESELECTION).equalsIgnoreCase("RANDOM")) {
+  List uriList = Arrays.asList(metastoreUris);
+  Collections.shuffle(uriList);
+  metastoreUris = (URI[]) uriList.toArray();
+}
   } catch (IllegalArgumentException e) {
 throw (e);
   } catch (Exception e) {
@@ -341,10 +343,12 @@ public class HiveMetaStoreClient implements 
IMetaStoreClient {
   " at the client level.");
 } else {
   close();
-  // Swap the first element of the metastoreUris[] with a random element 
from the rest
-  // of the array. Rationale being that this method will generally be 
called when the default
-  // connection has died and the default connection is likely to be the 
first array element.
-  promoteRandomMetaStoreURI();
+  if (HiveConf.getVar(conf, 
ConfVars.METASTORESELECTION).equalsIgnoreCase("RANDOM")) {
+// Swap the first element of the metastoreUris[] with a random element 
from the rest
+// of the array. Rationale being that this method will generally be 
called when the default
+// connection has died and the default connection is likely to be the 
first array element.
+

hive git commit: HIVE-18449 : Add configurable policy for choosing the HMS URI from hive.metastore.uris (Janaki Lahorani, reviewed by Vihang Karajgaonkar)

2018-02-02 Thread vihangk1
Repository: hive
Updated Branches:
  refs/heads/master fdd8fabdc -> 466f51034


HIVE-18449 : Add configurable policy for choosing the HMS URI from 
hive.metastore.uris (Janaki Lahorani, reviewed by Vihang Karajgaonkar)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/466f5103
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/466f5103
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/466f5103

Branch: refs/heads/master
Commit: 466f51034e18d0fdf8527f1eec5d421cebb41db4
Parents: fdd8fab
Author: Vihang Karajgaonkar 
Authored: Fri Feb 2 10:50:47 2018 -0800
Committer: Vihang Karajgaonkar 
Committed: Fri Feb 2 10:50:47 2018 -0800

--
 .../org/apache/hadoop/hive/conf/HiveConf.java |  8 +++-
 .../hive/metastore/HiveMetaStoreClient.java   | 18 +++---
 .../hadoop/hive/metastore/conf/MetastoreConf.java |  6 ++
 3 files changed, 24 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hive/blob/466f5103/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 b7d3e99..4f2e6d3 100644
--- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
+++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
@@ -216,6 +216,7 @@ public class HiveConf extends Configuration {
   HiveConf.ConfVars.METASTOREWAREHOUSE,
   HiveConf.ConfVars.REPLDIR,
   HiveConf.ConfVars.METASTOREURIS,
+  HiveConf.ConfVars.METASTORESELECTION,
   HiveConf.ConfVars.METASTORE_SERVER_PORT,
   HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES,
   HiveConf.ConfVars.METASTORETHRIFTFAILURERETRIES,
@@ -632,7 +633,12 @@ public class HiveConf extends Configuration {
 "location of default database for the warehouse"),
 METASTOREURIS("hive.metastore.uris", "",
 "Thrift URI for the remote metastore. Used by metastore client to 
connect to remote metastore."),
-
+METASTORESELECTION("hive.metastore.uri.selection", "RANDOM",
+new StringSet("SEQUENTIAL", "RANDOM"),
+"Determines the selection mechanism used by metastore client to 
connect to remote " +
+"metastore.  SEQUENTIAL implies that the first valid metastore 
from the URIs specified " +
+"as part of hive.metastore.uris will be picked.  RANDOM implies 
that the metastore " +
+"will be picked randomly"),
 METASTORE_CAPABILITY_CHECK("hive.metastore.client.capability.check", true,
 "Whether to check client capabilities for potentially breaking API 
usage."),
 METASTORE_FASTPATH("hive.metastore.fastpath", false,

http://git-wip-us.apache.org/repos/asf/hive/blob/466f5103/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
--
diff --git 
a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
 
b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
index 3a468b1..a3cb17b 100644
--- 
a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
+++ 
b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
@@ -195,9 +195,11 @@ public class HiveMetaStoreClient implements 
IMetaStoreClient, AutoCloseable {
 
 }
 // make metastore URIS random
-List uriList = Arrays.asList(metastoreUris);
-Collections.shuffle(uriList);
-metastoreUris = (URI[]) uriList.toArray();
+if (MetastoreConf.getVar(conf, 
ConfVars.THRIFT_URI_SELECTION).equalsIgnoreCase("RANDOM")) {
+  List uriList = Arrays.asList(metastoreUris);
+  Collections.shuffle(uriList);
+  metastoreUris = (URI[]) uriList.toArray();
+}
   } catch (IllegalArgumentException e) {
 throw (e);
   } catch (Exception e) {
@@ -322,10 +324,12 @@ public class HiveMetaStoreClient implements 
IMetaStoreClient, AutoCloseable {
   " at the client level.");
 } else {
   close();
-  // Swap the first element of the metastoreUris[] with a random element 
from the rest
-  // of the array. Rationale being that this method will generally be 
called when the default
-  // connection has died and the default connection is likely to be the 
first array element.
-  promoteRandomMetaStoreURI();
+  if (MetastoreConf.getVar(conf, 
ConfVars.THRIFT_URI_SELECTION).equalsIgnoreCase("RANDOM")) {
+// Swap the first element of the metastoreUris[] with a random element 
from the rest
+