You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "Dong Qiu (Jira)" <ji...@apache.org> on 2022/06/23 16:15:00 UTC

[jira] [Commented] (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:comment-tabpanel&focusedCommentId=17558155#comment-17558155 ] 

Dong Qiu commented on HIVE-25096:
---------------------------------

[~heiheizhang] tested the patch, it fixed the beeline issue. will this be merged ?

another Jira for the same issue. patch in HIVE-19825 should fix that as well.

https://issues.apache.org/jira/browse/HIVE-19825

> 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
>            Assignee: hezhang
>            Priority: Major
>             Fix For: 4.0.0
>
>         Attachments: HIVE-25096.patch
>
>
> beeline can't get the correct hiveserver2 using the zoopkeeper with serviceDiscoveryMode=zooKeeper.
>  
> {code:java}
> // code placeholder
> [root@vhost-120-28 hive]# beeline -u "jdbc:hive2://vhost-120-26:2181,vhost-120-27:2181,vhost-120-28:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2" --verbose=true
> SLF4J: Class path contains multiple SLF4J bindings.
> SLF4J: Found binding in [jar:file:/usr/wdp/1.0/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
> SLF4J: Found binding in [jar:file:/usr/wdp/1.0/hadoop/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
> SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
> SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
> !connect jdbc:hive2://vhost-120-26:2181,vhost-120-27:2181,vhost-120-28:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2 '' [passwd stripped] 
> Connecting to jdbc:hive2://vhost-120-26:2181,vhost-120-27:2181,vhost-120-28:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2
> Error: org.apache.hive.jdbc.ZooKeeperHiveClientException: Unable to read HiveServer2 configs from ZooKeeper (state=,code=0)
> java.sql.SQLException: org.apache.hive.jdbc.ZooKeeperHiveClientException: Unable to read HiveServer2 configs from ZooKeeper
>         at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:170)
>         at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107)
>         at java.sql.DriverManager.getConnection(DriverManager.java:664)
>         at java.sql.DriverManager.getConnection(DriverManager.java:208)
>         at org.apache.hive.beeline.DatabaseConnection.connect(DatabaseConnection.java:145)
>         at org.apache.hive.beeline.DatabaseConnection.getConnection(DatabaseConnection.java:209)
>         at org.apache.hive.beeline.Commands.connect(Commands.java:1641)
>         at org.apache.hive.beeline.Commands.connect(Commands.java:1536)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:498)
>         at org.apache.hive.beeline.ReflectiveCommandHandler.execute(ReflectiveCommandHandler.java:56)
>         at org.apache.hive.beeline.BeeLine.execCommandWithPrefix(BeeLine.java:1384)
>         at org.apache.hive.beeline.BeeLine.dispatch(BeeLine.java:1423)
>         at org.apache.hive.beeline.BeeLine.connectUsingArgs(BeeLine.java:900)
>         at org.apache.hive.beeline.BeeLine.initArgs(BeeLine.java:795)
>         at org.apache.hive.beeline.BeeLine.begin(BeeLine.java:1048)
>         at org.apache.hive.beeline.BeeLine.mainWithInputRedirection(BeeLine.java:538)
>         at org.apache.hive.beeline.BeeLine.main(BeeLine.java:520)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:498)
>         at org.apache.hadoop.util.RunJar.run(RunJar.java:323)
>         at org.apache.hadoop.util.RunJar.main(RunJar.java:236)
> Caused by: org.apache.hive.jdbc.ZooKeeperHiveClientException: Unable to read HiveServer2 configs from ZooKeeper
>         at org.apache.hive.jdbc.ZooKeeperHiveClientHelper.configureConnParams(ZooKeeperHiveClientHelper.java:147)
>         at org.apache.hive.jdbc.Utils.configureConnParamsFromZooKeeper(Utils.java:511)
>         at org.apache.hive.jdbc.Utils.parseURL(Utils.java:334)
>         at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:168)
>         ... 25 more
> {code}
>   
>  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}        *final String serverNode = serverHosts.get(ThreadLocalRandom.current().nextInt(serverHosts.size()));*{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.20.7#820007)