Java Code Examples for org.apache.hadoop.hbase.zookeeper.ZKUtil#createEphemeralNodeAndWatch()

The following examples show how to use org.apache.hadoop.hbase.zookeeper.ZKUtil#createEphemeralNodeAndWatch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexSplitTransaction.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ephemeral node in the PENDING_SPLIT state for the specified region.
 * Create it ephemeral in case regionserver dies mid-split.
 *
 * <p>Does not transition nodes from other states.  If a node already exists
 * for this region, a {@link NodeExistsException} will be thrown.
 *
 * @param zkw zk reference
 * @param region region to be created as offline
 * @param serverName server event originates from
 * @throws KeeperException
 * @throws IOException
 */
public static void createNodeSplitting(final ZooKeeperWatcher zkw, final HRegionInfo region,
    final ServerName serverName, final HRegionInfo a,
    final HRegionInfo b) throws KeeperException, IOException {
  LOG.debug(zkw.prefix("Creating ephemeral node for " +
    region.getEncodedName() + " in PENDING_SPLIT state"));
  byte [] payload = HRegionInfo.toDelimitedByteArray(a, b);
  RegionTransition rt = RegionTransition.createRegionTransition(
    RS_ZK_REQUEST_REGION_SPLIT, region.getRegionName(), serverName, payload);
  String node = ZKAssign.getNodeName(zkw, region.getEncodedName());
  if (!ZKUtil.createEphemeralNodeAndWatch(zkw, node, rt.toByteArray())) {
    throw new IOException("Failed create of ephemeral " + node);
  }
}
 
Example 2
Source File: HBaseFsck.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * This method maintains an ephemeral znode. If the creation fails we return false or throw
 * exception
 *
 * @return true if creating znode succeeds; false otherwise
 * @throws IOException if IO failure occurs
 */
private boolean setMasterInMaintenanceMode() throws IOException {
  RetryCounter retryCounter = createZNodeRetryCounterFactory.create();
  hbckEphemeralNodePath = ZNodePaths.joinZNode(
    zkw.getZNodePaths().masterMaintZNode,
    "hbck-" + Long.toString(EnvironmentEdgeManager.currentTime()));
  do {
    try {
      hbckZodeCreated = ZKUtil.createEphemeralNodeAndWatch(zkw, hbckEphemeralNodePath, null);
      if (hbckZodeCreated) {
        break;
      }
    } catch (KeeperException e) {
      if (retryCounter.getAttemptTimes() >= retryCounter.getMaxAttempts()) {
         throw new IOException("Can't create znode " + hbckEphemeralNodePath, e);
      }
      // fall through and retry
    }

    LOG.warn("Fail to create znode " + hbckEphemeralNodePath + ", try=" +
        (retryCounter.getAttemptTimes() + 1) + " of " + retryCounter.getMaxAttempts());

    try {
      retryCounter.sleepUntilNextRetry();
    } catch (InterruptedException ie) {
      throw (InterruptedIOException) new InterruptedIOException(
            "Can't create znode " + hbckEphemeralNodePath).initCause(ie);
    }
  } while (retryCounter.shouldRetry());
  return hbckZodeCreated;
}
 
Example 3
Source File: HRegionServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void createMyEphemeralNode() throws KeeperException {
  RegionServerInfo.Builder rsInfo = RegionServerInfo.newBuilder();
  rsInfo.setInfoPort(infoServer != null ? infoServer.getPort() : -1);
  rsInfo.setVersionInfo(ProtobufUtil.getVersionInfo());
  byte[] data = ProtobufUtil.prependPBMagic(rsInfo.build().toByteArray());
  ZKUtil.createEphemeralNodeAndWatch(this.zooKeeper, getMyEphemeralNodePath(), data);
}