public static void releaseAllLocks(HiveConf conf) throws Exception { try { int sessionTimeout = conf.getIntVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_SESSION_TIMEOUT); String quorumServers = getQuorumServers(conf); ZooKeeper zkpClient = new ZooKeeper(quorumServers, sessionTimeout, new DummyWatcher()); String parent = conf.getVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_NAMESPACE); List<HiveLock> locks = getLocks(conf, zkpClient, null, parent, false, false); if (locks != null) { for (HiveLock lock : locks) { unlock(conf, zkpClient, lock, parent); } } zkpClient.close(); zkpClient = null; } catch (Exception e) { LOG.error("Failed to release all locks: " + e.getMessage()); throw new Exception(ErrorMsg.ZOOKEEPER_CLIENT_COULD_NOT_BE_INITIALIZED.getMsg()); } }
/** * @param ctx The lock manager context (containing the Hive configuration file) * Start the ZooKeeper client based on the zookeeper cluster specified in the conf. **/ public void setContext(HiveLockManagerCtx ctx) throws LockException { this.ctx = ctx; HiveConf conf = ctx.getConf(); sessionTimeout = conf.getIntVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_SESSION_TIMEOUT); quorumServers = ZooKeeperHiveLockManager.getQuorumServers(conf); try { renewZookeeperInstance(sessionTimeout, quorumServers); parent = conf.getVar(HiveConf.ConfVars.HIVE_ZOOKEEPER_NAMESPACE); try { String par = zooKeeper.create("/" + parent, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (KeeperException e) { // ignore if the parent already exists } } catch (Exception e) { LOG.error("Failed to create ZooKeeper object: " + e); throw new LockException(ErrorMsg.ZOOKEEPER_CLIENT_COULD_NOT_BE_INITIALIZED.getMsg()); } }