public void syncOrTimeout(String path) throws KeeperException {
    final CountDownLatch latch = new CountDownLatch(1);
    long startTime = EnvironmentEdgeManager.currentTime();
    this.recoverableZooKeeper.sync(path, (i, s, o) -> latch.countDown(), null);
    try {
      if (!latch.await(zkSyncTimeout, TimeUnit.MILLISECONDS)) {
        LOG.warn("sync() operation to ZK timed out. Configured timeout: {}ms. This usually points "
          + "to a ZK side issue. Check ZK server logs and metrics.", zkSyncTimeout);
        throw new KeeperException.RequestTimeoutException();
      }
    } catch (InterruptedException e) {
      LOG.warn("Interrupted waiting for ZK sync() to finish.", e);
      Thread.currentThread().interrupt();
      return;
    }
    if (LOG.isDebugEnabled()) {
      // TODO: Switch to a metric once server side ZK watcher metrics are implemented. This is a
      // useful metric to have since the latency of sync() impacts the callers.
      LOG.debug("ZK sync() operation took {}ms", EnvironmentEdgeManager.currentTime() - startTime);
    }
  }
Forces a synchronization of this ZooKeeper client connection within a timeout. Enforcing a
timeout lets the callers fail-fast rather than wait forever for the sync to finish.
<p>
Executing this method before running other methods will ensure that the subsequent operations
are up-to-date and consistent as of the time that the sync is complete.
<p>
This is used for compareAndSwap type operations where we need to read the data of an existing
node and delete or transition that node, utilizing the previously read version and data. We
want to ensure that the version read is up-to-date from when we begin the operation.
<p>
hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKWatcher.java