[sheepdog] [PATCH v4 08/18] collie/farm: implement object_rb_tree

Liu Yuan namei.unix at gmail.com
Fri May 17 10:34:13 CEST 2013


On 05/17/2013 02:27 PM, Kai Zhang wrote:
> object_rb_tree is a red black tree which is used to de-duplicate oid.
> So that objects with the same oid in the cluster will be read only once when doing cluster snapshot.
> 

I'd like a more concise file name as 'object_tree.c'.

> When user sends cluster snapshot command, collie will:
> 1. parse vdis
> 2. save readonly object's id into object_rb_tree, duplicate id will be saved only once
> 3. for each oid in object_rb_tree, read the object and save to farm
> 
> object_rb_tree has 5 public interfaces:
> 1. get_obj_nr()
>    returns current object number in the tree
> 2. obj_tree_insert()
>    insert a object id into the tree
> 3. free_obj_tree()
>    free memory
> 4. print_obj_tree()
>    print each node of tree for debug
> 5. parse_obj()
>    foreach node in the tree, read object from cluster and call the function.
>    just like parse_vdi() in common.c

I'd like a more complete component name 'object' instead of 'obj', we
are not in the old days that we need to use short abbreviation to save
memory or disk space.

These helpers are called by other files, so I'd suggest prefix
'object_tree_' to all these helpers.

We are not parsing the objects, but reading the objects and calling a
func against it, so 'for_each_object_in_tree' would be a better name
than 'parse_obj'.

> +	while (p) {
> +		entry = rb_entry(p, struct obj_rb_entry, node);
> +		oid = entry->oid;
> +		if (entry->type == OBJECT) {
> +			buf = obj_buf;
> +			size = SD_DATA_OBJ_SIZE;
> +		} else if (entry->type == VDI) {
> +			buf = vdi_buf;
> +			size = SD_INODE_SIZE;

Use get_objsize(oid) to get the size, then you don't need obj_type at
all. We can tell its type from oid.

Thanks,
Yuan




More information about the sheepdog mailing list