commit b1e6965a6d9d28f0eee9abf270d14c4c336c05b3 Author: Janaki Lahorani Date: Mon Jan 29 12:36:28 2018 -0800 HIVE-18449: Add configurable policy for choosing the HMS URI from hive.metastore.uris If set to RANDOM, an URI will be picked randomly. If set to SEQUENTIAL, the URIs will be tried sequentially in the order specified in hive.metastore.uris and the first working one will be picked. Change-Id: I737c75bb9edda269321a2a9e004dfec36eb71c34 diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConf.java common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index 13067dfc069150e92d733a3fe71ba6e86e56c52b..74b54a23b8cbca459d4e31308dd38c1644b84a1f 100644 --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -216,6 +216,7 @@ private static URL checkConfigFile(File f) { 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 @@ private static void populateLlapDaemonVarsSet(Set llapDaemonVarsSetLocal "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, diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java index 3a468b108a554e65499e37bc4f0c60592754c752..a3cb17b000ebecb5e541c7bad208dffdf9d95ed3 100644 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java @@ -195,9 +195,11 @@ public HiveMetaStoreClient(Configuration conf, HiveMetaHookLoader hookLoader, Bo } // 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 void reconnect() throws MetaException { " 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 + // 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(); } } diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java index 3c8d005e3cb55739c91c340d2718850cb00747de..dba68ac38f8e8a8a8080fd675059233a2da86e70 100644 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java @@ -718,6 +718,12 @@ public static ConfVars getMetaConf(String name) { "Number of retries upon failure of Thrift metastore calls"), THRIFT_URIS("metastore.thrift.uris", "hive.metastore.uris", "", "Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore."), + THRIFT_URI_SELECTION("metastore.thrift.uri.selection", "hive.metastore.uri.selection", "RANDOM", + new Validator.StringSet("RANDOM", "SEQUENTIAL"), + "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"), TIMEDOUT_TXN_REAPER_START("metastore.timedout.txn.reaper.start", "hive.timedout.txn.reaper.start", 100, TimeUnit.SECONDS, "Time delay of 1st reaper run after metastore start"),