You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "xiaozhongcheng (Jira)" <ji...@apache.org> on 2021/05/07 08:46:00 UTC
[jira] [Updated] (HIVE-25096) beeline can't get the correct
hiveserver2 using the zoopkeeper with serviceDiscoveryMode=zooKeeper.
[ https://issues.apache.org/jira/browse/HIVE-25096?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
xiaozhongcheng updated HIVE-25096:
----------------------------------
Description:
beeline can't get the correct hiveserver2 using the zoopkeeper with serviceDiscoveryMode=zooKeeper.
You know, HiveServer2#startPrivilegeSynchronizer will create the namespace of /hiveserver2/leader in the zookeeper,
however, if you want to connect to the hiveserver2 using beeline with the command like "jdbc:hive2://vhost-120-26:2181,vhost-120-27:2181,vhost-120-28:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2", the beeline will randomly chose the sub-namespace under /hiveserver2.
That arises a problem that the beeline will not find the hiveserver2 information in the namespace of /hiveserver2/leader, it's impossible to detect the hiveserver2 connection information.
That's to say, the sub-namespace of /hiveserver2 is like this:
[zk: vhost-120-28:2181,vhost-120-27:2181,vhost-120-26:2181(CONNECTED) 1] ls /hiveserver2
[leader, serverUri=vhost-120-26:10000;version=3.1.2;sequence=0000000010, serverUri=vhost-120-28:10000;version=3.1.2;sequence=0000000011]
Codes list bellow show {color:#222222}HiveServer2#startPrivilegeSynchronizer and beeline how to connect the hiveserver2.{color}
{color:#222222}HiveServer2#startPrivilegeSynchronizer:{color}
{color:#222222} public void startPrivilegeSynchronizer(HiveConf hiveConf) throws Exception {{color}
{color:#222222} {color}
{color:#222222} if (!HiveConf.getBoolVar(hiveConf, ConfVars.HIVE_PRIVILEGE_SYNCHRONIZER)) {{color}
{color:#222222} return;{color}
{color:#222222} }{color}
{color:#222222} PolicyProviderContainer policyContainer = new PolicyProviderContainer();{color}
{color:#222222} HiveAuthorizer authorizer = SessionState.get().getAuthorizerV2();{color}
{color:#222222} if (authorizer.getHivePolicyProvider() != null) {{color}
{color:#222222} policyContainer.addAuthorizer(authorizer);{color}
{color:#222222} }{color}
{color:#222222} if (MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.PRE_EVENT_LISTENERS) != null &&{color}
{color:#222222} MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.PRE_EVENT_LISTENERS).contains({color}
{color:#222222} "org.apache.hadoop.hive.ql.security.authorization.AuthorizationPreEventListener") &&{color}
{color:#222222} MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.HIVE_AUTHORIZATION_MANAGER)!= null) {{color}
{color:#222222} List<HiveMetastoreAuthorizationProvider> providers = HiveUtils.getMetaStoreAuthorizeProviderManagers({color}
{color:#222222} hiveConf, HiveConf.ConfVars.HIVE_METASTORE_AUTHORIZATION_MANAGER, SessionState.get().getAuthenticator());{color}
{color:#222222} for (HiveMetastoreAuthorizationProvider provider : providers) {{color}
{color:#222222} if (provider.getHivePolicyProvider() != null) {{color}
{color:#222222} policyContainer.addAuthorizationProvider(provider);{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222} {color}
{color:#222222} if (policyContainer.size() > 0) {{color}
{color:#222222} setUpZooKeeperAuth(hiveConf);{color}
{color:#222222} zKClientForPrivSync = hiveConf.getZKConfig().startZookeeperClient(zooKeeperAclProvider, true);{color}
{color:#222222} String rootNamespace = hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_ZOOKEEPER_NAMESPACE);{color}
{color:#172b4d} *String path = ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace*{color}
*{color:#172b4d} + ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + "leader";{color}*
{color:#222222} LeaderLatch privilegeSynchronizerLatch = new LeaderLatch(zKClientForPrivSync, path);{color}
{color:#222222} privilegeSynchronizerLatch.start();{color}
{color:#222222} LOG.info("Find " + policyContainer.size() + " policy to synchronize, start PrivilegeSynchronizer");{color}
{color:#222222} Thread privilegeSynchronizerThread = new Thread({color}
{color:#222222} new PrivilegeSynchronizer(privilegeSynchronizerLatch, policyContainer, hiveConf), "PrivilegeSynchronizer");{color}
{color:#222222} privilegeSynchronizerThread.setDaemon(true);{color}
{color:#222222} privilegeSynchronizerThread.start();{color}
{color:#222222} } else {{color}
{color:#222222} LOG.warn({color}
{color:#222222} "No policy provider found, skip creating PrivilegeSynchronizer");{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222}ZooKeeperHiveClientHelper#configureConnParams{color}
{color:#222222} static void configureConnParams(JdbcConnectionParams connParams) throws ZooKeeperHiveClientException {{color}
{color:#222222} if (isZkHADynamicDiscoveryMode(connParams.getSessionVars())) {{color}
{color:#222222} configureConnParamsHA(connParams);{color}
{color:#222222} } else {{color}
{color:#222222} CuratorFramework zooKeeperClient = null;{color}
{color:#222222} try {{color}
{color:#222222} zooKeeperClient = getZkClient(connParams);{color}
{color:#222222} {color}
{color:#222222} final List<String> serverHosts = getServerHosts(connParams, zooKeeperClient);{color}
{color:#222222} {color}
{color:#222222} if (serverHosts.isEmpty()) {{color}
{color:#222222} throw new ZooKeeperHiveClientException("No more HiveServer2 URIs from ZooKeeper to attempt");{color}
{color:#222222} }{color}
{color:#222222} {color}
{color:#222222} // Pick a server node randomly{color}
{color:#de350b}{color:#222222} *final String serverNode = serverHosts.get(ThreadLocalRandom.current().nextInt(serverHosts.size()));*{color}{color}
{color:#222222} {color}
{color:#222222} updateParamsWithZKServerNode(connParams, zooKeeperClient, serverNode);{color}
{color:#222222} } catch (ZooKeeperHiveClientException zkhce) {{color}
{color:#222222} throw zkhce;{color}
{color:#222222} } catch (Exception e) {{color}
{color:#222222} throw new ZooKeeperHiveClientException("Unable to read HiveServer2 configs from ZooKeeper", e);{color}
{color:#222222} } finally {{color}
{color:#222222} if (zooKeeperClient != null) {{color}
{color:#222222} zooKeeperClient.close();{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222}I wonder if it's ok to use /hiveserver2-leader to replace /hiveserver2/leader?{color}
was:
beeline can't get the correct hiveserver2 using the zoopkeeper with serviceDiscoveryMode=zooKeeper.
You know, HiveServer2#startPrivilegeSynchronizer will create the namespace of /hiveserver2/leader in the zookeeper,
however, if you want to connect to the hiveserver2 using beeline with the command like "jdbc:hive2://vhost-120-26:2181,vhost-120-27:2181,vhost-120-28:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2", the beeline will randomly chose the sub-namespace under /hiveserver2.
That arises a problem that the beeline will find the hiveserver2 information in the namespace of /hiveserver2/leader, it's impossible to detect the hiveserver2 connection information.
That's to say, the sub-namespace of /hiveserver2 is like this:
[zk: vhost-120-28:2181,vhost-120-27:2181,vhost-120-26:2181(CONNECTED) 1] ls /hiveserver2
[leader, serverUri=vhost-120-26:10000;version=3.1.2;sequence=0000000010, serverUri=vhost-120-28:10000;version=3.1.2;sequence=0000000011]
Codes list bellow show {color:#222222}HiveServer2#startPrivilegeSynchronizer and beeline how to connect the hiveserver2.{color}
{color:#222222}HiveServer2#startPrivilegeSynchronizer:{color}
{color:#222222} public void startPrivilegeSynchronizer(HiveConf hiveConf) throws Exception {{color}
{color:#222222} {color}
{color:#222222} if (!HiveConf.getBoolVar(hiveConf, ConfVars.HIVE_PRIVILEGE_SYNCHRONIZER)) {{color}
{color:#222222} return;{color}
{color:#222222} }{color}
{color:#222222} PolicyProviderContainer policyContainer = new PolicyProviderContainer();{color}
{color:#222222} HiveAuthorizer authorizer = SessionState.get().getAuthorizerV2();{color}
{color:#222222} if (authorizer.getHivePolicyProvider() != null) {{color}
{color:#222222} policyContainer.addAuthorizer(authorizer);{color}
{color:#222222} }{color}
{color:#222222} if (MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.PRE_EVENT_LISTENERS) != null &&{color}
{color:#222222} MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.PRE_EVENT_LISTENERS).contains({color}
{color:#222222} "org.apache.hadoop.hive.ql.security.authorization.AuthorizationPreEventListener") &&{color}
{color:#222222} MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.HIVE_AUTHORIZATION_MANAGER)!= null) {{color}
{color:#222222} List<HiveMetastoreAuthorizationProvider> providers = HiveUtils.getMetaStoreAuthorizeProviderManagers({color}
{color:#222222} hiveConf, HiveConf.ConfVars.HIVE_METASTORE_AUTHORIZATION_MANAGER, SessionState.get().getAuthenticator());{color}
{color:#222222} for (HiveMetastoreAuthorizationProvider provider : providers) {{color}
{color:#222222} if (provider.getHivePolicyProvider() != null) {{color}
{color:#222222} policyContainer.addAuthorizationProvider(provider);{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222} {color}
{color:#222222} if (policyContainer.size() > 0) {{color}
{color:#222222} setUpZooKeeperAuth(hiveConf);{color}
{color:#222222} zKClientForPrivSync = hiveConf.getZKConfig().startZookeeperClient(zooKeeperAclProvider, true);{color}
{color:#222222} String rootNamespace = hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_ZOOKEEPER_NAMESPACE);{color}
{color:#222222} String path = ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace{color}
{color:#222222} + ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + "leader";{color}
{color:#222222} LeaderLatch privilegeSynchronizerLatch = new LeaderLatch(zKClientForPrivSync, path);{color}
{color:#222222} privilegeSynchronizerLatch.start();{color}
{color:#222222} LOG.info("Find " + policyContainer.size() + " policy to synchronize, start PrivilegeSynchronizer");{color}
{color:#222222} Thread privilegeSynchronizerThread = new Thread({color}
{color:#222222} new PrivilegeSynchronizer(privilegeSynchronizerLatch, policyContainer, hiveConf), "PrivilegeSynchronizer");{color}
{color:#222222} privilegeSynchronizerThread.setDaemon(true);{color}
{color:#222222} privilegeSynchronizerThread.start();{color}
{color:#222222} } else {{color}
{color:#222222} LOG.warn({color}
{color:#222222} "No policy provider found, skip creating PrivilegeSynchronizer");{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222}ZooKeeperHiveClientHelper#configureConnParams{color}
{color:#222222} static void configureConnParams(JdbcConnectionParams connParams) throws ZooKeeperHiveClientException {{color}
{color:#222222} if (isZkHADynamicDiscoveryMode(connParams.getSessionVars())) {{color}
{color:#222222} configureConnParamsHA(connParams);{color}
{color:#222222} } else {{color}
{color:#222222} CuratorFramework zooKeeperClient = null;{color}
{color:#222222} try {{color}
{color:#222222} zooKeeperClient = getZkClient(connParams);{color}
{color:#222222} {color}
{color:#222222} final List<String> serverHosts = getServerHosts(connParams, zooKeeperClient);{color}
{color:#222222} {color}
{color:#222222} if (serverHosts.isEmpty()) {{color}
{color:#222222} throw new ZooKeeperHiveClientException("No more HiveServer2 URIs from ZooKeeper to attempt");{color}
{color:#222222} }{color}
{color:#222222} {color}
{color:#222222} // Pick a server node randomly{color}
{color:#222222} final String serverNode = serverHosts.get(ThreadLocalRandom.current().nextInt(serverHosts.size()));{color}
{color:#222222} {color}
{color:#222222} updateParamsWithZKServerNode(connParams, zooKeeperClient, serverNode);{color}
{color:#222222} } catch (ZooKeeperHiveClientException zkhce) {{color}
{color:#222222} throw zkhce;{color}
{color:#222222} } catch (Exception e) {{color}
{color:#222222} throw new ZooKeeperHiveClientException("Unable to read HiveServer2 configs from ZooKeeper", e);{color}
{color:#222222} } finally {{color}
{color:#222222} if (zooKeeperClient != null) {{color}
{color:#222222} zooKeeperClient.close();{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222} }{color}
{color:#222222}I wonder if it's ok to use /hiveserver2-leader to replace /hiveserver2/leader?{color}
> beeline can't get the correct hiveserver2 using the zoopkeeper with serviceDiscoveryMode=zooKeeper.
> ---------------------------------------------------------------------------------------------------
>
> Key: HIVE-25096
> URL: https://issues.apache.org/jira/browse/HIVE-25096
> Project: Hive
> Issue Type: Bug
> Components: Beeline
> Affects Versions: 3.1.2
> Environment: centos7.4
> x86_64
> Reporter: xiaozhongcheng
> Priority: Major
> Fix For: 4.0.0
>
>
> beeline can't get the correct hiveserver2 using the zoopkeeper with serviceDiscoveryMode=zooKeeper.
>
> You know, HiveServer2#startPrivilegeSynchronizer will create the namespace of /hiveserver2/leader in the zookeeper,
> however, if you want to connect to the hiveserver2 using beeline with the command like "jdbc:hive2://vhost-120-26:2181,vhost-120-27:2181,vhost-120-28:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2", the beeline will randomly chose the sub-namespace under /hiveserver2.
> That arises a problem that the beeline will not find the hiveserver2 information in the namespace of /hiveserver2/leader, it's impossible to detect the hiveserver2 connection information.
>
>
> That's to say, the sub-namespace of /hiveserver2 is like this:
>
> [zk: vhost-120-28:2181,vhost-120-27:2181,vhost-120-26:2181(CONNECTED) 1] ls /hiveserver2
> [leader, serverUri=vhost-120-26:10000;version=3.1.2;sequence=0000000010, serverUri=vhost-120-28:10000;version=3.1.2;sequence=0000000011]
>
> Codes list bellow show {color:#222222}HiveServer2#startPrivilegeSynchronizer and beeline how to connect the hiveserver2.{color}
>
> {color:#222222}HiveServer2#startPrivilegeSynchronizer:{color}
>
> {color:#222222} public void startPrivilegeSynchronizer(HiveConf hiveConf) throws Exception {{color}
> {color:#222222} {color}
> {color:#222222} if (!HiveConf.getBoolVar(hiveConf, ConfVars.HIVE_PRIVILEGE_SYNCHRONIZER)) {{color}
> {color:#222222} return;{color}
> {color:#222222} }{color}
> {color:#222222} PolicyProviderContainer policyContainer = new PolicyProviderContainer();{color}
> {color:#222222} HiveAuthorizer authorizer = SessionState.get().getAuthorizerV2();{color}
> {color:#222222} if (authorizer.getHivePolicyProvider() != null) {{color}
> {color:#222222} policyContainer.addAuthorizer(authorizer);{color}
> {color:#222222} }{color}
> {color:#222222} if (MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.PRE_EVENT_LISTENERS) != null &&{color}
> {color:#222222} MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.PRE_EVENT_LISTENERS).contains({color}
> {color:#222222} "org.apache.hadoop.hive.ql.security.authorization.AuthorizationPreEventListener") &&{color}
> {color:#222222} MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.HIVE_AUTHORIZATION_MANAGER)!= null) {{color}
> {color:#222222} List<HiveMetastoreAuthorizationProvider> providers = HiveUtils.getMetaStoreAuthorizeProviderManagers({color}
> {color:#222222} hiveConf, HiveConf.ConfVars.HIVE_METASTORE_AUTHORIZATION_MANAGER, SessionState.get().getAuthenticator());{color}
> {color:#222222} for (HiveMetastoreAuthorizationProvider provider : providers) {{color}
> {color:#222222} if (provider.getHivePolicyProvider() != null) {{color}
> {color:#222222} policyContainer.addAuthorizationProvider(provider);{color}
> {color:#222222} }{color}
> {color:#222222} }{color}
> {color:#222222} }{color}
> {color:#222222} {color}
> {color:#222222} if (policyContainer.size() > 0) {{color}
> {color:#222222} setUpZooKeeperAuth(hiveConf);{color}
> {color:#222222} zKClientForPrivSync = hiveConf.getZKConfig().startZookeeperClient(zooKeeperAclProvider, true);{color}
> {color:#222222} String rootNamespace = hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_ZOOKEEPER_NAMESPACE);{color}
> {color:#172b4d} *String path = ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + rootNamespace*{color}
> *{color:#172b4d} + ZooKeeperHiveHelper.ZOOKEEPER_PATH_SEPARATOR + "leader";{color}*
> {color:#222222} LeaderLatch privilegeSynchronizerLatch = new LeaderLatch(zKClientForPrivSync, path);{color}
> {color:#222222} privilegeSynchronizerLatch.start();{color}
> {color:#222222} LOG.info("Find " + policyContainer.size() + " policy to synchronize, start PrivilegeSynchronizer");{color}
> {color:#222222} Thread privilegeSynchronizerThread = new Thread({color}
> {color:#222222} new PrivilegeSynchronizer(privilegeSynchronizerLatch, policyContainer, hiveConf), "PrivilegeSynchronizer");{color}
> {color:#222222} privilegeSynchronizerThread.setDaemon(true);{color}
> {color:#222222} privilegeSynchronizerThread.start();{color}
> {color:#222222} } else {{color}
> {color:#222222} LOG.warn({color}
> {color:#222222} "No policy provider found, skip creating PrivilegeSynchronizer");{color}
> {color:#222222} }{color}
> {color:#222222} }{color}
>
>
> {color:#222222}ZooKeeperHiveClientHelper#configureConnParams{color}
>
> {color:#222222} static void configureConnParams(JdbcConnectionParams connParams) throws ZooKeeperHiveClientException {{color}
> {color:#222222} if (isZkHADynamicDiscoveryMode(connParams.getSessionVars())) {{color}
> {color:#222222} configureConnParamsHA(connParams);{color}
> {color:#222222} } else {{color}
> {color:#222222} CuratorFramework zooKeeperClient = null;{color}
> {color:#222222} try {{color}
> {color:#222222} zooKeeperClient = getZkClient(connParams);{color}
> {color:#222222} {color}
> {color:#222222} final List<String> serverHosts = getServerHosts(connParams, zooKeeperClient);{color}
> {color:#222222} {color}
> {color:#222222} if (serverHosts.isEmpty()) {{color}
> {color:#222222} throw new ZooKeeperHiveClientException("No more HiveServer2 URIs from ZooKeeper to attempt");{color}
> {color:#222222} }{color}
> {color:#222222} {color}
> {color:#222222} // Pick a server node randomly{color}
> {color:#de350b}{color:#222222} *final String serverNode = serverHosts.get(ThreadLocalRandom.current().nextInt(serverHosts.size()));*{color}{color}
> {color:#222222} {color}
> {color:#222222} updateParamsWithZKServerNode(connParams, zooKeeperClient, serverNode);{color}
> {color:#222222} } catch (ZooKeeperHiveClientException zkhce) {{color}
> {color:#222222} throw zkhce;{color}
> {color:#222222} } catch (Exception e) {{color}
> {color:#222222} throw new ZooKeeperHiveClientException("Unable to read HiveServer2 configs from ZooKeeper", e);{color}
> {color:#222222} } finally {{color}
> {color:#222222} if (zooKeeperClient != null) {{color}
> {color:#222222} zooKeeperClient.close();{color}
> {color:#222222} }{color}
> {color:#222222} }{color}
> {color:#222222} }{color}
> {color:#222222} }{color}
>
> {color:#222222}I wonder if it's ok to use /hiveserver2-leader to replace /hiveserver2/leader?{color}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)