[Sheepdog] [PATCH] remove object oids from object list cache when deleting a vdi

Li Wenpeng levin108 at gmail.com
Tue Apr 17 08:51:22 CEST 2012


From: levin li <xingke.lwp at taobao.com>

When deleting a vdi, sheep removes data objects of that vdi, in which
case we need to remove the object ids from the object list cache for
the good of next data recovery.

Signed-off-by: levin li <xingke.lwp at taobao.com>
---
 sheep/store.c |   27 +++++++++++++++++++++++++++
 sheep/vdi.c   |    1 +
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/sheep/store.c b/sheep/store.c
index b50ce22..5b581cd 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -85,6 +85,29 @@ static struct objlist_cache_entry *objlist_cache_rb_insert(struct rb_root *root,
 	return NULL; /* insert successfully */
 }
 
+static int objlist_cache_rb_remove(struct rb_root *root, uint64_t oid)
+{
+	struct rb_node **p = &root->rb_node;
+	struct rb_node *parent = NULL;
+	struct objlist_cache_entry *entry;
+
+	while (*p) {
+		parent = *p;
+		entry = rb_entry(parent, struct objlist_cache_entry, node);
+
+		if (oid < entry->oid)
+			p = &(*p)->rb_left;
+		else if (oid > entry->oid)
+			p = &(*p)->rb_right;
+		else {
+			rb_erase(parent, root);
+			return 0;
+		}
+	}
+
+	return -1; /* fail to remove */
+}
+
 static int check_and_insert_objlist_cache(uint64_t oid)
 {
 	struct objlist_cache_entry *entry, *p;
@@ -600,6 +623,10 @@ int store_remove_obj(const struct sd_req *req, struct sd_rsp *rsp, void *data)
 		eprintf("%m\n");
 		ret =  SD_RES_EIO;
 	}
+	pthread_rwlock_wrlock(&obj_list_cache.lock);
+	if (!objlist_cache_rb_remove(&obj_list_cache.root, hdr->oid))
+		obj_list_cache.cache_size--;
+	pthread_rwlock_unlock(&obj_list_cache.lock);
  out:
 	strbuf_release(&buf);
 	return ret;
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 45e77fe..71912ba 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -473,6 +473,7 @@ static void delete_one(struct work *work)
 			      vid_to_data_oid(inode->data_vdi_id[i], i),
 			      inode->nr_copies);
 	}
+
 out:
 	free_ordered_sd_vnode_list(entries);
 	free(inode);
-- 
1.7.1




More information about the sheepdog mailing list