On 04/26/2012 10:45 AM, Li Wenpeng wrote: > From: levin li <xingke.lwp at taobao.com> > > when deleting data objects, we need to remove their oid > from all the nodes' objlist cache, so we record which objects > are deleted, and notify a deletion list to all the nodes, > every node removes the oids in the list from its cache. > > Signed-off-by: levin li <xingke.lwp at taobao.com> > --- > include/sheep.h | 1 + > sheep/ops.c | 17 +++++++++++++++++ > sheep/sheep_priv.h | 1 + > sheep/store.c | 16 ++++++++++++++++ > sheep/vdi.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- > 5 files changed, 81 insertions(+), 4 deletions(-) > > diff --git a/include/sheep.h b/include/sheep.h > index fc2ac58..b80bc01 100644 > --- a/include/sheep.h > +++ b/include/sheep.h > @@ -45,6 +45,7 @@ > #define SD_OP_CLEANUP 0x94 > #define SD_OP_TRACE 0x95 > #define SD_OP_TRACE_CAT 0x96 > +#define SD_OP_NOTIFY_VDI_DEL 0x97 > > #define SD_FLAG_CMD_IO_LOCAL 0x0010 > #define SD_FLAG_CMD_RECOVERY 0x0020 > diff --git a/sheep/ops.c b/sheep/ops.c > index 54e866c..b90c16b 100644 > --- a/sheep/ops.c > +++ b/sheep/ops.c > @@ -452,6 +452,17 @@ static int cluster_cleanup(const struct sd_req *req, struct sd_rsp *rsp, > return ret; > } > > +static int cluster_notify_vdi_deletion(const struct sd_req *req, struct sd_rsp *rsp, > + void *data) > +{ > + int count = req->data_length / sizeof(uint64_t); > + uint64_t *oids = data; > + > + del_vdi_from_objlist_cache(oids, count); > + > + return SD_RES_SUCCESS; > +} > + > static int cluster_restore(const struct sd_req *req, struct sd_rsp *rsp, > void *data) > { > @@ -607,6 +618,12 @@ static struct sd_op_template sd_ops[] = { > .process_main = cluster_cleanup, > }, > > + [SD_OP_NOTIFY_VDI_DEL] = { > + .type = SD_OP_TYPE_CLUSTER, > + .force = 1, > + .process_main = cluster_notify_vdi_deletion, > + }, > + > /* local operations */ > [SD_OP_GET_STORE_LIST] = { > .type = SD_OP_TYPE_LOCAL, > diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h > index 1c27808..4330a62 100644 > --- a/sheep/sheep_priv.h > +++ b/sheep/sheep_priv.h > @@ -292,6 +292,7 @@ void resume_recovery_work(void); > int is_recoverying_oid(uint64_t oid); > int node_in_recovery(void); > > +int del_vdi_from_objlist_cache(uint64_t *oids, int count); > int write_object(struct sd_vnode *e, > int vnodes, int zones, uint32_t node_version, > uint64_t oid, char *data, unsigned int datalen, > diff --git a/sheep/store.c b/sheep/store.c > index dac0bff..350c5af 100644 > --- a/sheep/store.c > +++ b/sheep/store.c > @@ -133,6 +133,22 @@ static int check_and_insert_objlist_cache(uint64_t oid) > return 0; > } > > +int del_vdi_from_objlist_cache(uint64_t *oids, int count) > +{ > + int i; > + dprintf("%d\n", count); > + > + for (i = 0; i < count; i++) { > + dprintf("remove oid %" PRIx64 " from objlist cache\n", oids[i]); > + pthread_rwlock_wrlock(&obj_list_cache.lock); > + if (!objlist_cache_rb_remove(&obj_list_cache.root, oids[i])) > + obj_list_cache.cache_size--; > + pthread_rwlock_unlock(&obj_list_cache.lock); > + } > + > + return 0; > +} > + We shouldn't call it in main thread, we'd better put it in notify worker thread. And I guess you have to write down in the commit why you need this operation. Thanks, Yuan |