private static ServerName blockUntilAvailable(final ZKWatcher zkw, int replicaId,
    final long timeout) throws InterruptedException {
    if (timeout < 0) {
      throw new IllegalArgumentException();
    }

    if (zkw == null) {
      throw new IllegalArgumentException();
    }

    long startTime = EnvironmentEdgeManager.currentTime();
    ServerName sn = null;
    while (true) {
      sn = getMetaRegionLocation(zkw, replicaId);
      if (
        sn != null || (EnvironmentEdgeManager.currentTime() - startTime)
            > timeout - HConstants.SOCKET_RETRY_WAIT_MS
      ) {
        break;
      }
      Thread.sleep(HConstants.SOCKET_RETRY_WAIT_MS);
    }
    return sn;
  }
Wait until the meta region is available and is not in transition.
@param zkw       reference to the {@link ZKWatcher} which also contains configuration and
                 constants
@param replicaId the ID of the replica
@param timeout   maximum time to wait in millis
@return ServerName or null if we timed out.
@throws InterruptedException if waiting for the socket operation fails
hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java