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 <vih...@cloudera.com>
Authored: Thu Feb 22 17:44:09 2018 -0800
Committer: Vihang Karajgaonkar <vih...@cloudera.com>
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.
+        promoteRandomMetaStoreURI();
+      }
       open();
     }
   }

Reply via email to