当前位置: 首页>>代码示例>>Java>>正文


Java EventType.M_ZK_REGION_OFFLINE属性代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.executor.EventType.M_ZK_REGION_OFFLINE属性的典型用法代码示例。如果您正苦于以下问题:Java EventType.M_ZK_REGION_OFFLINE属性的具体用法?Java EventType.M_ZK_REGION_OFFLINE怎么用?Java EventType.M_ZK_REGION_OFFLINE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.hadoop.hbase.executor.EventType的用法示例。


在下文中一共展示了EventType.M_ZK_REGION_OFFLINE属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createOrForceNodeOffline

/**
 * Creates or force updates an unassigned node to the OFFLINE state for the
 * specified region.
 * <p>
 * Attempts to create the node but if it exists will force it to transition to
 * and OFFLINE state.
 *
 * <p>Sets a watcher on the unassigned region node if the method is
 * successful.
 *
 * <p>This method should be used when assigning a region.
 *
 * @param zkw zk reference
 * @param region region to be created as offline
 * @param serverName server transition will happen on
 * @return the version of the znode created in OFFLINE state, -1 if
 *         unsuccessful.
 * @throws KeeperException if unexpected zookeeper exception
 * @throws KeeperException.NodeExistsException if node already exists
 */
public static int createOrForceNodeOffline(ZooKeeperWatcher zkw,
    HRegionInfo region, ServerName serverName) throws KeeperException {
  LOG.debug(zkw.prefix("Creating (or updating) unassigned node " +
    region.getEncodedName() + " with OFFLINE state"));
  RegionTransition rt = RegionTransition.createRegionTransition(EventType.M_ZK_REGION_OFFLINE,
    region.getRegionName(), serverName, HConstants.EMPTY_BYTE_ARRAY);
  byte [] data = rt.toByteArray();
  String node = getNodeName(zkw, region.getEncodedName());
  zkw.sync(node);
  int version = ZKUtil.checkExists(zkw, node);
  if (version == -1) {
    return ZKUtil.createAndWatch(zkw, node, data);
  } else {
    boolean setData = false;
    try {
      setData = ZKUtil.setData(zkw, node, data, version);
      // Setdata throws KeeperException which aborts the Master. So we are
      // catching it here.
      // If just before setting the znode to OFFLINE if the RS has made any
      // change to the
      // znode state then we need to return -1.
    } catch (KeeperException kpe) {
      LOG.info("Version mismatch while setting the node to OFFLINE state.");
      return -1;
    }
    if (!setData) {
      return -1;
    } else {
      // We successfully forced to OFFLINE, reset watch and handle if
      // the state changed in between our set and the watch
      byte [] bytes = ZKAssign.getData(zkw, region.getEncodedName());
      rt = getRegionTransition(bytes);
      if (rt.getEventType() != EventType.M_ZK_REGION_OFFLINE) {
        // state changed, need to process
        return -1;
      }
    }
  }
  return version + 1;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:60,代码来源:ZKAssign.java


注:本文中的org.apache.hadoop.hbase.executor.EventType.M_ZK_REGION_OFFLINE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。