private ZooKeeperHiveLock lock (HiveLockObject key, HiveLockMode mode,
      boolean keepAlive, boolean parentCreated) throws LockException {
    LOG.debug("Acquiring lock for {} with mode {} {}", key.getName(), mode,
        key.getData().getLockMode());

    int tryNum = 0;
    ZooKeeperHiveLock ret = null;
    Set<String> conflictingLocks = new HashSet<String>();
    Exception lastException = null;

    do {
      lastException = null;
      tryNum++;
      try {
        if (tryNum > 1) {
          Thread.sleep(sleepTime);
          prepareRetry();
        }
        ret = lockPrimitive(key, mode, keepAlive, parentCreated, conflictingLocks);
        if (ret != null) {
          break;
        }
      } catch (Exception e1) {
        lastException = e1;
        if (e1 instanceof KeeperException) {
          KeeperException e = (KeeperException) e1;
          switch (e.code()) {
          case CONNECTIONLOSS:
          case OPERATIONTIMEOUT:
          case NONODE:
          case NODEEXISTS:
            LOG.debug("Possibly transient ZooKeeper exception: ", e);
            break;
          default:
            LOG.error("Serious Zookeeper exception: ", e);
            break;
          }
        } else {
          LOG.error("Other unexpected exception: ", e1);
        }
      }
    } while (tryNum < numRetriesForLock);

    if (ret == null) {
      console.printError("Unable to acquire " + key.getData().getLockMode()
          + ", " + mode + " lock " + key.getDisplayName() + " after "
          + tryNum + " attempts.");
      printConflictingLocks(key,mode,conflictingLocks);
      if (lastException != null) {
        LOG.error("Exceeds maximum retries with errors: ", lastException);
        throw new LockException(lastException);
      }
    }
    return ret;
  }
@param name
         The name of the zookeeper child
@param data
         The data for the zookeeper child
@param mode
         The mode in which the child needs to be created
@throws KeeperException
@throws InterruptedException
ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/ZooKeeperHiveLockManager.java