in kyuubi-relocated-hive-metastore-client/src/main/java/org/apache/kyuubi/shaded/hive/common/ZooKeeperHiveHelper.java [191:248]
public void addServerInstanceToZooKeeper(
String znodePathPrefix,
String znodeData,
ACLProvider zooKeeperAclProvider,
ZKDeRegisterWatcher watcher)
throws Exception {
// This might be the first server getting added to the ZooKeeper, so the parent node may need
// to be created.
zooKeeperClient = startZookeeperClient(zooKeeperAclProvider, true);
// Create a znode under the rootNamespace parent for the given path prefix for a server. Also
// add a watcher to watch the znode.
try {
String pathPrefix =
ZOOKEEPER_PATH_SEPARATOR + rootNamespace + ZOOKEEPER_PATH_SEPARATOR + znodePathPrefix;
byte[] znodeDataUTF8 = znodeData.getBytes(StandardCharsets.UTF_8);
znode =
new PersistentNode(
zooKeeperClient, CreateMode.EPHEMERAL_SEQUENTIAL, false, pathPrefix, znodeDataUTF8);
znode.start();
// We'll wait for 120s for node creation
long znodeCreationTimeout = 120;
if (!znode.waitForInitialCreate(znodeCreationTimeout, TimeUnit.SECONDS)) {
throw new Exception(
"Max znode creation wait time: " + znodeCreationTimeout + "s exhausted");
}
setDeregisteredWithZooKeeper(false);
final String znodePath = znode.getActualPath();
if (zooKeeperClient.checkExists().usingWatcher(watcher).forPath(znodePath) == null) {
// No node exists, throw exception
throw new Exception(
"Unable to create znode with path prefix "
+ znodePathPrefix
+ " and data "
+ znodeData
+ " on ZooKeeper.");
}
LOG.info(
"Created a znode (actual path "
+ znodePath
+ ") on ZooKeeper with path prefix "
+ znodePathPrefix
+ " and data "
+ znodeData);
} catch (Exception e) {
LOG.error(
"Unable to create znode with path prefix "
+ znodePathPrefix
+ " and data "
+ znodeData
+ " on ZooKeeper.",
e);
if (znode != null) {
znode.close();
}
throw (e);
}
}