您的位置:首页 > 其它

zookeeper错误:KeeperErrorCode = NoChildrenForEphemerals的原因

2015-02-12 11:18 1101 查看
zookeeper错误:zookeeper.KeeperException$NoChildrenForEphemera: KeeperErrorCode = NoChildrenForEphemerals

我在构建父节点的时候zookeeper.create(ZK_PATH, ZK_PATH.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL),报出来这个错误。

因为我没有仔细研究create的参数,如果主节点是临时的话,就不能构建其子节点。

在http://zookeeper.apache.org/doc/r3.2.2/api/org/apache/zookeeper/ZooKeeper.html中有说明,粘贴如下。

create

public String create(String path,
byte[] data,
List<ACL> acl,
CreateMode createMode)
throws KeeperException,
InterruptedException

Create a node with the given path. The node data will be the given data, and node acl will be the given acl.
The flags argument specifies whether the created node will be ephemeral or not.

An ephemeral node will be removed by the ZooKeeper automatically when the session associated with the creation of the node expires.

The flags argument can also specify to create a sequential node. The actual path name of a sequential node will be the given path plus a suffix "_i" where i is the current sequential number of the node. Once such a node is created, the sequential number
will be incremented by one.

If a node with the same actual path already exists in the ZooKeeper, a KeeperException with error code KeeperException.NodeExists will be thrown. Note that since a different actual path is used for each invocation of creating sequential node with the same
path argument, the call will never throw "file exists" KeeperException.

If the parent node does not exist in the ZooKeeper, a KeeperException with error code KeeperException.NoNode will be thrown.

An ephemeral node cannot have children. If the parent node of the given path is ephemeral, a KeeperException with error code KeeperException.NoChildrenForEphemerals will be thrown.

This operation, if successful, will trigger all the watches left on the node of the given path by exists and getData API calls, and the watches left on the parent node by getChildren API calls.

If a node is created successfully, the ZooKeeper server will trigger the watches on the path left by exists calls, and the watches on the parent of the node by getChildren calls.

The maximum allowable size of the data array is 1 MB (1,048,576 bytes). Arrays larger than this will cause a KeeperExecption to be thrown.

Parameters:
path
- the path for the node
data
- the initial data for the node
acl
- the acl for the node
createMode
- specifying whether the node to be created is ephemeral and/or sequentialReturns:the actual path of the created nodeThrows:
KeeperException
- if the server returns a non-zero error code
KeeperException.InvalidACLException
- if the ACL is invalid
InterruptedException
- if the transaction is interrupted
IllegalArgumentException
- if an invalid path is specified
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐