本文整理汇总了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;
}