Create an empty normal (persistent) Znode.

@param zookeeper ZooKeeper instance to work with.
@param znode     Znode to create.
@throws KeeperException
@throws InterruptedException
429984
static void create(ZooKeeper zookeeper, String znode) throws KeeperException, InterruptedException {
        zookeeper.create(znode, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    }
786501
function initZookeeper(client, connectionString) {
  var zk = zookeeper.createClient(connectionString, client.options.zookeeper)
  var error = false
  var connected = false

  client.ready = false
  client.zk = zk

  zk.connect()
  zk.on('connected', onconnected)
  zk.on('expired', setError)
  zk.on('authenticationFailed', setError)
  zk.on('disconnected', ondisconnected)
  zk.on('error', onerror)

  function onconnected() {
    if (!connected) {
      connected = true;

      client.updateBrokerList()
    }

    error = false;
  }

  function setError() {
    error = true;
  }

  function ondisconnected() {
    if (client.closed) {
      return
    }

    debug('Lost connection with ZooKeeper. Reconnecting...');

    if (error) {
      zk.removeListener('error', onerror)
      zk.removeListener('disconnected', ondisconnected)
      zk.removeListener('expired', setError)
      zk.removeListener('authenticationFailed', setError)
      zk.close()

      initZookeeper(client, connectionString);
    }
  }

  function onerror(err) {
    client.emit('error', err)
  }
}
1129629
@Override
  protected void initZnode() { 
    try {
      ZooKeeperUtil.createAndFailSilent(this, "/chronos");
      super.initZnode();
      ZooKeeperUtil.createAndFailSilent(this, baseZnode + "/persistent-timestamp");
    } catch (Exception e) {
      LOG.fatal("Error to create znode of chronos, exit immediately");
      System.exit(0);
    }
  }
281788
@Override
  public ZKData<String> getZKStringData(String path, Watcher watcher)
    throws InterruptedException, KeeperException

  {
    ZKData<byte[]> zkData = getZKByteData(path, watcher);

    return new ZKData<String>(toStringData(zkData.getData()), zkData.getStat());
  }
1334275
function create(con, p, cb) {
  var data = 'created by zk-mkdir-p'; // just want a dir, so store something
  var flags = 0; // none
  con.a_create(p, data, flags, function(rc, error, zkPath) {
    // already exists, cool.
    if(rc == ZooKeeper.ZNODEEXISTS) {
      return cb();
    }
    if(rc != 0) {
      return cb(new Error('Zookeeper Error: code='+rc+'   '+error));
    }
    // sucessfully created!
    return cb();
  });
}
738579
void ensureRequiredZnodesExist(ZooKeeper zookeeper, String znode) throws KeeperException, InterruptedException {
        mkdirp(zookeeper, znode);
        createIfNotThere(zookeeper, QUEUE_NODE);
        createIfNotThere(zookeeper, POOL_NODE);
    }
98461
@Override
    public SimpleZooKeeperClient doConnect() throws IOException, InterruptedException {
        LOG.info("Connecting to zookeeper server - " + zooConf.getOfflineServerList());
        return new SimpleZooKeeperClient(zooConf.getOfflineServerList(),
                zooConf.getOfflineDigestAuth(), new ServerServiceWatcher(),
                zooConf.getSessionTimeout(), zooConf.getConnTimeout());
    }
924457
private void connect(ZooKeeperClient injectedClient) throws InterruptedException {
        if (!initialized.get()) {
            if (injectedClient == null) {
                List<InetSocketAddress> hosts = new ArrayList<InetSocketAddress>();
                for (String host : config.hosts.split(",")) {
                    String[] parts = host.split(":");
                    try {
                        hosts.add(new InetSocketAddress(parts[0], Integer.parseInt(parts[1])));
                    } catch (Exception e) {
                        LOG.error("Invalid ZK host '"+host+"', need to skip, problem: "+e.getMessage());
                    }
                }
                // TODO: What about empty hosts at this point?
                LOG.info("Connecting to hosts: {}", hosts.toString());
                injectedClient = new ZooKeeperClient(Amount.of((int) config.zkTimeout, Time.MILLISECONDS),
                        hosts);
            }
            zk = injectedClient;
            claimer.start();
            LOG.info("Registering connection watcher.");
            zk.register(connectionWatcher);
        }
        // and then see that we can actually get the client without problems
        try {
            zk.get();
        } catch (ZooKeeperConnectionException e) {
            throw ZKException.from(e);
        }
    }
1152247
private void setNodeRecrusively(ZooNode zooNode, int depth) {
        try {
            int currDepth = depth + 1;
            List<String> children = zkClient.getChildren(zooNode.getPath());
            if (CollectionUtils.isEmpty(children)) {
                zooNode.setLeaf(true);
                return;
            }
            for (String name : children) {
                ZooNode node = new ZooNode(ZkPathUtil.buildPath(zooNode.getPath(), name), name);
                if (currDepth < 2) {
                    node.setOpen(true);
                }
                zooNode.getChildren().add(node);
                setNodeRecrusively(node, currDepth);
            }
        } catch (NoNodeException e) {
            LOG.warn("Zookeeper path not found" + e.getMessage(), e);
        } catch (Exception e) {
            LOG.error("Zookeeper get children error" + e.getMessage(), e);
        }
    }
1243439
private ZooKeeper connect(String quorumAddresses) throws IOException {
        final CountDownLatch latch = new CountDownLatch(1);
        ZooKeeper zookeeper;

        // Connect to the quorum and wait for the successful connection callback.;
        zookeeper = new ZooKeeper(quorumAddresses, (int) SECONDS.toMillis(10), watchedEvent -> {
            if (watchedEvent.getState() == Watcher.Event.KeeperState.SyncConnected) {
                // Signal that the Zookeeper connection is established.
                latch.countDown();
            }
        });

        boolean successfullyConnected = false;
        try {
            successfullyConnected = latch.await(11, SECONDS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        if (!successfullyConnected) {
            throw new IOException(String.format(
                    "Connection to ZooKeeper quorum timed out after %d seconds.", CONNECTION_TIMEOUT));
        }

        return zookeeper;
    }
922863
@Override
    public void put(int partitionId, String HSIdStr) throws KeeperException, InterruptedException {
        try {
            m_zk.create(ZKUtil.joinZKPath(m_rootNode, Integer.toString(partitionId)),
                    HSIdStr.getBytes(Charsets.UTF_8),
                    Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
        catch (KeeperException.NodeExistsException e) {
            m_zk.setData(ZKUtil.joinZKPath(m_rootNode, Integer.toString(partitionId)),
                    HSIdStr.getBytes(Charsets.UTF_8), -1);
        }
    }
844907
public synchronized long get() throws IOException {
    try {
      lastZNodeStat = zooKeeper.exists(fullyQualifiedZNode, false);
      if (lastZNodeStat == null) {
        return -1;
      }
      byte[] data =
          zooKeeper.getData(fullyQualifiedZNode, false, lastZNodeStat);
      WritableUtil.readWritableFromByteArray(data, maxTxIdWritable);
      return maxTxIdWritable.get();
    } catch (KeeperException e) {
      keeperException("Unrecoverable ZooKeeper error reading " +
          fullyQualifiedZNode, e);
      return -1; // This is never reached
    } catch (InterruptedException e) {
      interruptedException("Interrupted reading " +
          fullyQualifiedZNode, e);
      return -1; // This is never reached
    }
  }
1249856
private ZooKeeper createZooKeeperClient() throws IOException {
        ZooClientConfig config = getZookeeperClientConfig();
        return new ZooKeeper(config.getUrl(), config.getTimeout(), getConnectionWatcher());
    }
1121407
@Override
    public SimpleZooKeeperClient doConnect() throws IOException, InterruptedException {
        LOG.info("Connecting to zookeeper server - " + zooConf.getOnlineServerList());
        return new SimpleZooKeeperClient(zooConf.getOnlineServerList(),
                zooConf.getOnlineDigestAuth(), new ServerServiceWatcher(),
                zooConf.getSessionTimeout(), zooConf.getConnTimeout());
    }
901693
public static void createPersistentZKNodes(ZooKeeper zk) {
        LinkedList<ZKUtil.StringCallback> callbacks = new LinkedList<ZKUtil.StringCallback>();
        for (int i=0; i < VoltZK.ZK_HIERARCHY.length; i++) {
            ZKUtil.StringCallback cb = new ZKUtil.StringCallback();
            callbacks.add(cb);
            zk.create(VoltZK.ZK_HIERARCHY[i], null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, cb, null);
        }
        for (ZKUtil.StringCallback cb : callbacks) {
            try {
                cb.get();
            } catch (org.apache.zookeeper_voltpatches.KeeperException.NodeExistsException e) {
                // this is an expected race.
            } catch (Exception e) {
                VoltDB.crashLocalVoltDB(e.getMessage(), true, e);
            }
        }
    }
431644
public static ResourceClaim claimExpiring(ZooKeeperConnection zooKeeperConnection, int poolSize, String znode)
            throws IOException {
        return claimExpiring(zooKeeperConnection, poolSize, znode, DEFAULT_TIMEOUT);
    }
1146331
static void releaseTicket(ZooKeeper zookeeper, String lockNode, String ticket)
            throws KeeperException, InterruptedException {

        logger.debug("Releasing ticket {}.", ticket);
        try {
            zookeeper.delete(lockNode + "/" + ticket, -1);
        } catch (KeeperException e) {
            if (e.code() != KeeperException.Code.NONODE) {
                // If it the node is already gone, than that is fine, otherwise:
                throw e;
            }
        }
    }