You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "Henry Robinson (JIRA)" <ji...@apache.org> on 2009/06/08 16:28:07 UTC

[jira] Commented: (ZOOKEEPER-423) Add getFirstChild API

    [ https://issues.apache.org/jira/browse/ZOOKEEPER-423?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12717265#action_12717265 ] 

Henry Robinson commented on ZOOKEEPER-423:
------------------------------------------

(Sorry for the slow reply - didn't get a notification from JIRA for some reason...)

That seems a good API - my only concern is that there's not an obviously neat way to get the xid of an arbitrary child without another server roundtrip. However I haven't been able to come up with any non-pathological use cases where this is an expensive problem. Since we need to return at least one xid with every call, we could consider returning a list. listChildren would of course also need a path parameter. 

If we want to add lots of different orderings, we would need to generalise xid to an abstract Key. I could imagine:

Order.CREATED_XID_ASC/DESC
Order.MODIFIED_XID_ASC/DESC
Order.DATA_SIZE_ASC/DESC
Order.NAME_ASC/DESC

for starters which require different key types. The Key could remain opaque, but then needs to be retrieved from some node. Each order that we add either requires servers to maintain an ordered data structure or potentially spend a lot of CPU on computing the order on the fly.

It seems like watchers can have much the same semantics as for getChildren? 


> Add getFirstChild API
> ---------------------
>
>                 Key: ZOOKEEPER-423
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-423
>             Project: Zookeeper
>          Issue Type: New Feature
>          Components: contrib-bindings, documentation, java client, server
>            Reporter: Henry Robinson
>
> When building the distributed queue for my tutorial blog post, it was pointed out to me that there's a serious inefficiency here. 
> Informally, the items in the queue are created as sequential nodes. For a 'dequeue' call, all items are retrieved and sorted by name by the client in order to find the name of the next item to try and take. This costs O( n ) bandwidth and O(n.log n) sorting time - per dequeue call! Clearly this doesn't scale very well. 
> If the servers were able to maintain a data structure that allowed them to efficiently retrieve the children of a node in order of the zxid that created them this would make successful dequeue operations O( 1 ) at the cost of O( n ) memory on the server (to maintain, e.g. a singly-linked list as a queue). This is a win if it is generally true that clients only want the first child in creation order, rather than the whole set. 
> We could expose this to the client via this API: getFirstChild(handle, path, name_buffer, watcher) which would have much the same semantics as getChildren, but only return one znode name. 
> Sequential nodes would still allow the ordering of znodes to be made explicitly available to the client in one RPC should it need it. Although: since this ordering would now be available cheaply for every set of children, it's not completely clear that there would be that many use cases left for sequential nodes if this API was augmented with a getChildrenInCreationOrder call. However, that's for a different discussion. 
> A halfway-house alternative with more flexibility is to add an 'order' parameter to getFirstChild and have the server compute the first child according to the requested order (creation time, update time, lexicographical order). This saves bandwidth at the expense of increased server load, although servers can be implemented to spend memory on pre-computing commonly requested orders. I am only in favour of this approach if servers maintain a data-structure for every possible order, and then the memory implications need careful consideration.
> [edit - JIRA interprets ( n ) without the spaces as a thumbs-down. cute.]

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.