Enabling HiveServer2 high availability

To provide high availability or load balancing for HiveServer2, Hive provides a function called dynamic service discovery where multiple HiveServer2 instances can register themselves with Zookeeper. Instead of connecting to a specific HiveServer2 directly, clients connect to Zookeeper which returns a randomly selected registered HiveServer2 instance.

About this task

HiveServer2 instances register themselves with Zookeeper by adding a znode, which contains the actual host name and port of the HiveServer2 instance.

The znode has the following format:
/<hiveserver2_namespace>/serverUri=
  <host:port>;version=<versionInfo>; sequence=<sequence_number>

Enabling dynamic service discovery

Procedure

  1. Click the Hive service and then click Configs > Advanced, and then expand Advanced hive-site. Update the following configuration properties to enable dynamic service discovery and to configure the zookeeper information. Updating the properties in the Ambari web interface updates the hive-site.xml file. :
    Table 1. Configuration properties
    Property Value Description
    hive.server2.support.dynamic.service.discovery true (default is false) Set to true to enable HiveServer2 dynamic service discovery for its clients
    hive.server2.zookeeper.namespace hiveserver2 (default value) The parent node in ZooKeeper used by HiveServer2 when supporting dynamic service discovery.
    hive.zookeeper.quorum abc1209.abc.com:2181,abc1208.abc.com:2181,abc1210.abc.com:2181 List of ZooKeeper servers to talk to. Used in connection string by JDBC/ODBC clients instead of URI of specific HiveServer2 instance.
    hive.zookeeper.client.port 2181 (default value) The port of ZooKeeper servers to talk to. If the list of Zookeeper servers specified in hive.zookeeper.quorum does not contain port numbers, this value is used.
  2. Restart all of the Hive services from the Ambari web interface, after you update the configurations.

Adding new HiveServer2 instances

Procedure

  1. From the Ambari web interface, click Hive, and then click Service Actions > Add HiveServer2.
  2. Select a host and then confirm. Then start the new HiveServer2

Client Connections

Procedure

JDBC/ODBC clients need to use the following connection string to connect to HiveServer2:

jdbc:hive2://<zookeeper_ensemble>/;serviceDiscoveryMode=zooKeeper;
zooKeeperNamespace=<hiveserver2_zookeeper_namespace>
where the following definitions apply:
<zookeeper_ensemble>
A comma-separated list of ZooKeeper servers that form the ensemble, such as zk_host1:zk_port1,zk_host2:zk_port2,zk_host3:zk_port3.
<hiveserver2_zookeeper_namespace>
The namespace on Zookeeper under which HiveServer2 znodes are added. The namespace value is configured in hive.server2.zookeeper.name space.
For example,

jdbc:hive2://abc1209.abc.com:2181,abc1208.abc.com:2181,abc1210.abc.com:2181/;
  serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2
Dynamic service discovery chart
The JDBC/ODBC client connects to Zookeeper, which randomly returns a <host>:<port> for a registered HiveServer2 instance. The client uses the returned value to connect to a particular HiveServer2 instance directly to perform its work.

If the HiveServer2 instance fails while the client is connected, the client session is terminated and there is no automatic fail-over to a new HiveServer2 instance.

Deregistering a HiveServer2 instance from Zookeeper

Procedure

Remove a HiveServer2 instance from Zookeeper by running the following commands to deregister the server:
  1. Get the HiveServer2 znode by running the following command from the Zookeeper command line interface:
    Launch the Zookeeper command line interface:
    /usr/hdp/current/zookeeper-client/bin/zkCli.sh
    Run the following command:
    ls /<hive.server2.zookeeper.namespace>
    The following example of the command uses the default namespace:
    ls /hiveserver2
    The following is the possible output:
    
    [serverUri=abc1209.abc.com:10000;version=1.2.1-IBM-6;sequence=0000000001, 
     serverUri=abc1210.abc.com:10000;version=1.2.1-IBM-6;sequence=0000000002]
  2. To deregister a particular HiveServer2, in the Zookeeper command line interface, run the following command:
    delete /hiveserver2/serverUri=abc1209.abc.com:10000;version=1.2.1-IBM-6;sequence=0000000001
  3. After you deregister the HiverServer2 from Zookeeper, it will not return the deregistered HiveServer2 for new client connections. However, any active client session is not affected by deregistering the HiveServer2 from Zookeeper.
  4. To deregister all HiveServer2 instances of a particular version, run the following command from the command line:
    hive --service hiveserver2 --deregister <version_number>
    For example,
    hive --service hiveserver2 --deregister 1.2.1-IBM-6