Search code examples
erlangapache-zookeeperznodes

Get all subnode keys and values from zookeeper


I am attempting to implement zookeeper as a shared state engine for an application I am creating in erlang. The structure for the state would be like the following:

/appRoot
        /parent1:{json}
                      /child1:{json}
                      /child2:{json}
        /parent2:{json}
                      /child1:{json}
                      /child2:{json}

I would like to be able to have a single method that returned all parent nodes when provided /appRoot along with it's data. Say in a list of tuples [{parent1,{json}}, {parent2:{json}}]. Or, if provided /appRoot/parent1 a list of it's subnodes with the data. So far, all I see is a way to get the keys (getChildren) then recursively retrieve the data with the key. It seems like I should be able to just make one call to do this.

I am currently using the ezk erlang client library. If anybody knows a better solution, that would be appreciated as well.

TIA


Solution

  • AFAIK there is no way to atomically list node children along with its data in zookeeper wire protocol. Seems, there is only way to do this is following:

    1. List all node children and monitor children changes.
    2. For each child node read it data and monitor data changes.
    3. Update corresponding values on each children change happened after you started traversal.

    This can be easily done over ezk, but I've not provided any example code because it heavily depends on guarantees of atomicity that your app logic demanded.