in kyuubi-relocated-hive-metastore-client/src/main/java/org/apache/kyuubi/shaded/hive/metastore/HiveMetaStoreClient.java [134:195]
private void resolveUris() throws MetaException {
String thriftUris = MetastoreConf.getVar(conf, ConfVars.THRIFT_URIS);
String serviceDiscoveryMode =
MetastoreConf.getVar(conf, ConfVars.THRIFT_SERVICE_DISCOVERY_MODE);
List<String> metastoreUrisString = null;
// The metastore URIs can come from THRIFT_URIS directly or need to be fetched from the
// Zookeeper
try {
if (serviceDiscoveryMode == null || serviceDiscoveryMode.trim().isEmpty()) {
metastoreUrisString = Arrays.asList(thriftUris.split(","));
} else if (serviceDiscoveryMode.equalsIgnoreCase("zookeeper")) {
metastoreUrisString = new ArrayList<String>();
// Add scheme to the bare URI we get.
for (String s : MetastoreConf.getZKConfig(conf).getServerUris()) {
metastoreUrisString.add("thrift://" + s);
}
} else {
throw new IllegalArgumentException(
"Invalid metastore dynamic service discovery mode " + serviceDiscoveryMode);
}
} catch (Exception e) {
MetaStoreUtils.throwMetaException(e);
}
if (metastoreUrisString.isEmpty() && "zookeeper".equalsIgnoreCase(serviceDiscoveryMode)) {
throw new MetaException(
"No metastore service discovered in ZooKeeper. "
+ "Please ensure that at least one metastore server is online");
}
LOG.info("Resolved metastore uris: {}", metastoreUrisString);
List<URI> metastoreURIArray = new ArrayList<URI>();
try {
for (String s : metastoreUrisString) {
URI tmpUri = new URI(s);
if (tmpUri.getScheme() == null) {
throw new IllegalArgumentException("URI: " + s + " does not have a scheme");
}
if (uriResolverHook != null) {
metastoreURIArray.addAll(uriResolverHook.resolveURI(tmpUri));
} else {
metastoreURIArray.add(tmpUri);
}
}
metastoreUris = new URI[metastoreURIArray.size()];
for (int j = 0; j < metastoreURIArray.size(); j++) {
metastoreUris[j] = metastoreURIArray.get(j);
}
if (MetastoreConf.getVar(conf, ConfVars.THRIFT_URI_SELECTION).equalsIgnoreCase("RANDOM")) {
List<URI> uriList = Arrays.asList(metastoreUris);
Collections.shuffle(uriList);
metastoreUris = uriList.toArray(new URI[uriList.size()]);
}
} catch (IllegalArgumentException e) {
throw (e);
} catch (Exception e) {
MetaStoreUtils.throwMetaException(e);
}
}