本文整理汇总了Java中org.apache.zookeeper.KeeperException.NodeExistsException类的典型用法代码示例。如果您正苦于以下问题:Java NodeExistsException类的具体用法?Java NodeExistsException怎么用?Java NodeExistsException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NodeExistsException类属于org.apache.zookeeper.KeeperException包,在下文中一共展示了NodeExistsException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: asyncSetOfflineInZooKeeper
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
/**
* Set region as OFFLINED up in zookeeper asynchronously.
* @param state
* @return True if we succeeded, false otherwise (State was incorrect or failed
* updating zk).
*/
private boolean asyncSetOfflineInZooKeeper(final RegionState state,
final AsyncCallback.StringCallback cb, final ServerName destination) {
if (!state.isClosed() && !state.isOffline()) {
this.server.abort("Unexpected state trying to OFFLINE; " + state,
new IllegalStateException());
return false;
}
regionStates.updateRegionState(state.getRegion(), State.OFFLINE);
try {
ZKAssign.asyncCreateNodeOffline(watcher, state.getRegion(),
destination, cb, state);
} catch (KeeperException e) {
if (e instanceof NodeExistsException) {
LOG.warn("Node for " + state.getRegion() + " already exists");
} else {
server.abort("Unexpected ZK exception creating/setting node OFFLINE", e);
}
return false;
}
return true;
}
示例2: OpenRegion
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
private void OpenRegion(Server server, RegionServerServices rss,
HTableDescriptor htd, HRegionInfo hri, OpenRegionCoordination coordination)
throws IOException, NodeExistsException, KeeperException, DeserializationException {
// Create it OFFLINE node, which is what Master set before sending OPEN RPC
ZKAssign.createNodeOffline(server.getZooKeeper(), hri, server.getServerName());
OpenRegionCoordination.OpenRegionDetails ord =
coordination.getDetailsForNonCoordinatedOpening();
OpenRegionHandler openHandler =
new OpenRegionHandler(server, rss, hri, htd, -1, coordination, ord);
rss.getRegionsInTransitionInRS().put(hri.getEncodedNameAsBytes(), Boolean.TRUE);
openHandler.process();
// This parse is not used?
RegionTransition.parseFrom(ZKAssign.getData(server.getZooKeeper(), hri.getEncodedName()));
// delete the node, which is what Master do after the region is opened
ZKAssign.deleteNode(server.getZooKeeper(), hri.getEncodedName(),
EventType.RS_ZK_REGION_OPENED, server.getServerName());
}
示例3: createIfAbsent
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
public static String createIfAbsent(ZooKeeper zk, String path, byte[] data, CreateMode createMode, boolean gc)
throws KeeperException, InterruptedException {
String pathCreated = null;
try {
pathCreated = zk.create(path, data, Ids.OPEN_ACL_UNSAFE, createMode);
} catch (NodeExistsException e) {
// OK
LOG.debug("Create skipped for existing znode: path={}", path);
}
// reset if what exists is the ephemeral garbage.
if (gc && (pathCreated == null) && CreateMode.EPHEMERAL.equals(createMode)) {
Stat stat = zk.exists(path, false);
if (stat != null && zk.getSessionId() != stat.getEphemeralOwner()) {
deleteIfExists(zk, path, -1);
pathCreated = zk.create(path, data, Ids.OPEN_ACL_UNSAFE, createMode);
}
}
return pathCreated;
}
示例4: createEphemeralNode
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
private void createEphemeralNode(String fullPath, byte[] data) throws KeeperException, InterruptedException {
try {
zk.create(fullPath, data, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
} catch (NodeExistsException nee) {
// this sometimes happens after a ZooKeeper node dies and the ephemeral node
// that belonged to the old session was not yet deleted. We need to make our
// session the owner of the node so it won't get deleted automatically -
// we do this by deleting and recreating it ourselves.
LOG.info("node for endpoint already exists, recreating: {}", fullPath);
try {
zk.delete(fullPath, -1);
} catch (NoNodeException nne) {
// it's a race condition, but as long as it got deleted - it's ok
}
zk.create(fullPath, data, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
}
}
示例5: asyncSetOfflineInZooKeeper
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
/**
* Set region as OFFLINED up in zookeeper asynchronously.
* @param state
* @return True if we succeeded, false otherwise (State was incorrect or failed
* updating zk).
*/
boolean asyncSetOfflineInZooKeeper(final RegionState state,
final AsyncCallback.StringCallback cb, final Object ctx) {
if (!state.isClosed() && !state.isOffline()) {
new RuntimeException("Unexpected state trying to OFFLINE; " + state);
this.master.abort("Unexpected state trying to OFFLINE; " + state,
new IllegalStateException());
return false;
}
state.update(RegionState.State.OFFLINE);
try {
ZKAssign.asyncCreateNodeOffline(master.getZooKeeper(), state.getRegion(),
this.master.getServerName(), cb, ctx);
} catch (KeeperException e) {
// TODO: this error handling will never execute, as the callback is async.
if (e instanceof NodeExistsException) {
LOG.warn("Node for " + state.getRegion() + " already exists");
} else {
master.abort("Unexpected ZK exception creating/setting node OFFLINE", e);
}
return false;
}
return true;
}
示例6: OpenRegion
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
private void OpenRegion(Server server, RegionServerServices rss,
HTableDescriptor htd, HRegionInfo hri)
throws IOException, NodeExistsException, KeeperException {
// Create it OFFLINE node, which is what Master set before sending OPEN RPC
ZKAssign.createNodeOffline(server.getZooKeeper(), hri, server.getServerName());
int version = ZKAssign.transitionNodeOpening(server.getZooKeeper(), hri, server.getServerName());
OpenRegionHandler openHandler = new OpenRegionHandler(server, rss, hri, htd, version);
openHandler.process();
RegionTransitionData data = ZKAssign.getData(server.getZooKeeper(), hri.getEncodedName());
// delete the node, which is what Master do after the region is opened
ZKAssign.deleteNode(server.getZooKeeper(), hri.getEncodedName(),
EventType.RS_ZK_REGION_OPENED);
}
示例7: OpenRegion
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
private void OpenRegion(Server server, RegionServerServices rss,
HTableDescriptor htd, HRegionInfo hri, OpenRegionCoordination coordination)
throws IOException, NodeExistsException, KeeperException, DeserializationException {
// Create it OFFLINE node, which is what Master set before sending OPEN RPC
ZKAssign.createNodeOffline(server.getZooKeeper(), hri, server.getServerName());
OpenRegionCoordination.OpenRegionDetails ord =
coordination.getDetailsForNonCoordinatedOpening();
OpenRegionHandler openHandler =
new OpenRegionHandler(server, rss, hri, htd, coordination, ord);
rss.getRegionsInTransitionInRS().put(hri.getEncodedNameAsBytes(), Boolean.TRUE);
openHandler.process();
// This parse is not used?
RegionTransition.parseFrom(ZKAssign.getData(server.getZooKeeper(), hri.getEncodedName()));
// delete the node, which is what Master do after the region is opened
ZKAssign.deleteNode(server.getZooKeeper(), hri.getEncodedName(),
EventType.RS_ZK_REGION_OPENED, server.getServerName());
}
示例8: createOrUpdatePath
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
protected void createOrUpdatePath(final String pPath, final byte[] pData) {
//CuratorFramework namespacedClient = client.usingNamespace(NAMESPACE);
String path = pPath;
if (!StringUtils.startsWith(path, "/")) {
path = "/" + path;
}
try {
try {
client.create().creatingParentsIfNeeded().forPath(path, pData);
} catch (NodeExistsException nee) {
client.setData().forPath(path, pData);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: asyncSetOfflineInZooKeeper
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
/**
* Set region as OFFLINED up in zookeeper asynchronously.
* @param state
* @return True if we succeeded, false otherwise (State was incorrect or failed
* updating zk).
*/
private boolean asyncSetOfflineInZooKeeper(final RegionState state,
final AsyncCallback.StringCallback cb, final ServerName destination) {
if (!state.isClosed() && !state.isOffline()) {
this.server.abort("Unexpected state trying to OFFLINE; " + state,
new IllegalStateException());
return false;
}
regionStates.updateRegionState(
state.getRegion(), RegionState.State.OFFLINE);
try {
ZKAssign.asyncCreateNodeOffline(watcher, state.getRegion(),
destination, cb, state);
} catch (KeeperException e) {
if (e instanceof NodeExistsException) {
LOG.warn("Node for " + state.getRegion() + " already exists");
} else {
server.abort("Unexpected ZK exception creating/setting node OFFLINE", e);
}
return false;
}
return true;
}
示例10: verifyZooKeeperStructure
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
private void verifyZooKeeperStructure(ZooKeeper zk) throws KeeperException, InterruptedException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Verifying ZooKeeper structure...");
}
for (String path : new String[] { rootNode, groupNode, dataNode }) {
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ensuring {} exists", path);
}
if (zk.exists(path, true) == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} doesn't exist, creating", path);
}
zk.create(path, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
} catch (NodeExistsException ex) {
// do nothing
}
}
}
示例11: createEphemeralNode
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
private void createEphemeralNode(long session, final DataTree dataTree,
int count) throws NoNodeException, NodeExistsException {
for (int i = 0; i < count; i++) {
dataTree.createNode("/test" + i, new byte[0], null, session + i,
dataTree.getNode("/").stat.getCversion() + 1, 1, 1);
}
}
示例12: startInternal
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
private String startInternal(ClusteredTask clusteredTask, String taskId)
{
ClusteredTaskWithArgs withArgs;
if( clusteredTask.isTransient() )
{
String argsId = UUID.randomUUID().toString();
Serializable[] args = clusteredTask.getArgs();
taskArgs.put(argsId, args);
withArgs = new ClusteredTaskWithArgs(clusteredTask, null, argsId, ourNodeId);
}
else
{
withArgs = new ClusteredTaskWithArgs(clusteredTask, clusteredTask.getArgs(), null, null);
}
byte[] taskBytes = PluginAwareObjectOutputStream.toBytes(withArgs);
try
{
if( LOGGER.isTraceEnabled() )
{
LOGGER.trace("Serialized ClusteredTask size is " + taskBytes.length);
}
curator.create().creatingParentsIfNeeded().forPath(zookeeperService.getFullPath(ZK_TASKPATH, taskId),
taskBytes);
}
catch( NodeExistsException nee )
{
LOGGER.debug("Task " + taskId + " already exists in ZK.");
}
catch( Exception e )
{
throw Throwables.propagate(e);
}
return taskId;
}
示例13: getGlobalTask
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
@Override
public GlobalTaskStartInfo getGlobalTask(ClusteredTask globalTask, long millis)
{
if( !globalTask.isGlobal() )
throw new Error("Isn't a global task");
String globalId = globalTask.getGlobalId();
String existingTaskId = getRunningGlobalTask(globalId);
if( existingTaskId != null )
{
ensureGlobalTaskRunner(existingTaskId, globalTask);
return new GlobalTaskStartInfo(existingTaskId, true);
}
String globalPath = zookeeperService.getFullPath(ZK_GLOBALTASKPATH, globalId);
try
{
String taskId = UUID.randomUUID().toString();
try
{
curator.create().creatingParentsIfNeeded().forPath(globalPath, taskId.getBytes());
return new GlobalTaskStartInfo(startInternal(globalTask, taskId), false);
}
catch( NodeExistsException nee )
{
final String taskFromZk = new String(curator.getData().forPath(globalPath));
//ensure there *is* a task for this
ensureGlobalTaskRunner(taskFromZk, globalTask);
return new GlobalTaskStartInfo(taskFromZk, false);
}
}
catch( Exception e )
{
throw Throwables.propagate(e);
}
}
示例14: createAndForceNodeToOpenedState
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
/**
* Creates a znode with OPENED state.
* @param TEST_UTIL
* @param region
* @param serverName
* @return
* @throws IOException
* @throws org.apache.hadoop.hbase.ZooKeeperConnectionException
* @throws KeeperException
* @throws NodeExistsException
*/
public static ZooKeeperWatcher createAndForceNodeToOpenedState(
HBaseTestingUtility TEST_UTIL, HRegion region,
ServerName serverName) throws ZooKeeperConnectionException,
IOException, KeeperException, NodeExistsException {
ZooKeeperWatcher zkw = getZooKeeperWatcher(TEST_UTIL);
ZKAssign.createNodeOffline(zkw, region.getRegionInfo(), serverName);
int version = ZKAssign.transitionNodeOpening(zkw, region
.getRegionInfo(), serverName);
ZKAssign.transitionNodeOpened(zkw, region.getRegionInfo(), serverName,
version);
return zkw;
}
示例15: stopMasterAndAssignMeta
import org.apache.zookeeper.KeeperException.NodeExistsException; //导入依赖的package包/类
public static void stopMasterAndAssignMeta(HBaseTestingUtility HTU)
throws NodeExistsException, KeeperException, IOException, InterruptedException {
// Stop master
HMaster master = HTU.getHBaseCluster().getMaster();
Thread masterThread = HTU.getHBaseCluster().getMasterThread();
ServerName masterAddr = master.getServerName();
master.stopMaster();
LOG.info("Waiting until master thread exits");
while (masterThread != null && masterThread.isAlive()) {
Threads.sleep(100);
}
}