treeriakmaterialized-path-pattern

Riak store a tree structure


I'm developing a distributed file system with riak for a project.I want to store a tree structure in the riak database and , I want to get the node id When the path is given(A Path like /root/dev/bin)

I thought to use materialized paths to store the tree, in which a tree is stored by using the node id and the path from the root

 A
 / \
B  C
/ \   \
D E  F

Node Id | Path
A            _
B            A
C            A
D            A,B
F            A,C

So to get the id for a path, one solution is to store path as the key and node id as the value and then use riak key filters to get node id for the path, another solution is to store the path as a value and use riak search to get the node id. If i use riak search should i store the path as a json array or store it as a plain string?

Additionally i want to do operations like,

1. Get childrens of a node(all files in a directory)
2. Add new children(add files or folders)
3. Traverse the tree

So what do you think about above solutions or do you guys have any other suggestions?

Thank You


Solution

  • i implemented a simple tree structure with operations such as inserting and removing nodes. I have implemented my system using both of the materialized paths and adjacency list. To store a tree with adjacency lists, it needs to use both of the Links and Secondary Indexes. But the drawback of adjacency lists is its really inefficient when it need to retrieve children of a particular node. But if you use materialized paths to store a tree, inserting and deleting nodes are really easy. Riak key filters and map reduce functions can use to implement this.