From: Liu Yuan <tailai.ly at taobao.com> - rename is_recoverying_oid() -> oid_in_recovery() Signed-off-by: Liu Yuan <tailai.ly at taobao.com> --- sheep/recovery.c | 68 +++++++++++++++++++++++++++++----------------------- sheep/sdnet.c | 4 ++-- sheep/sheep_priv.h | 2 +- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/sheep/recovery.c b/sheep/recovery.c index 7c36af4..c3d1d4d 100644 --- a/sheep/recovery.c +++ b/sheep/recovery.c @@ -271,59 +271,67 @@ int is_recovery_init(void) return rw->state == RW_INIT; } -int is_recoverying_oid(uint64_t oid) +static inline bool schedule_oid(uint64_t oid) { - uint64_t hval = fnv_64a_buf(&oid, sizeof(uint64_t), FNV1A_64_INIT); - uint64_t min_hval; - struct recovery_work *rw = recovering_work; + uint64_t hval, min_hval; int i; + struct recovery_work *rw = recovering_work; - if (oid == 0) - return 0; - - if (!rw) - return 0; /* there is no thread working for object recovery */ - - min_hval = fnv_64a_buf(&rw->oids[rw->done + rw->nr_blocking], sizeof(uint64_t), FNV1A_64_INIT); - - if (before(rw->epoch, sys->epoch)) - return 1; - - if (sd_store->exist(oid)) { - dprintf("the object %" PRIx64 " is already recoverd\n", oid); - return 0; - } - - if (rw->state == RW_INIT) - return 1; - - /* the first 'rw->nr_blocking' objects were already scheduled to be done earlier */ + /* Check if the oid is already scheduled in front */ for (i = 0; i < rw->nr_blocking; i++) if (rw->oids[rw->done + i] == oid) - return 1; + return true; + + min_hval = fnv_64a_buf(&rw->oids[rw->done + rw->nr_blocking], + sizeof(uint64_t), FNV1A_64_INIT); + hval = fnv_64a_buf(&oid, sizeof(uint64_t), FNV1A_64_INIT); if (min_hval <= hval) { uint64_t *p; p = bsearch(&oid, rw->oids + rw->done + rw->nr_blocking, - rw->count - rw->done - rw->nr_blocking, sizeof(oid), obj_cmp); + rw->count - rw->done - rw->nr_blocking, sizeof(oid), + obj_cmp); if (p) { dprintf("recover the object %" PRIx64 " first\n", oid); + /* The first oid may be processed now */ if (rw->nr_blocking == 0) - rw->nr_blocking = 1; /* the first oid may be processed now */ + rw->nr_blocking = 1; + /* This oid should be recovered first */ if (p > rw->oids + rw->done + rw->nr_blocking) { - /* this object should be recovered earlier */ memmove(rw->oids + rw->done + rw->nr_blocking + 1, rw->oids + rw->done + rw->nr_blocking, sizeof(uint64_t) * (p - (rw->oids + rw->done + rw->nr_blocking))); rw->oids[rw->done + rw->nr_blocking] = oid; rw->nr_blocking++; } - return 1; + return true; } } dprintf("the object %" PRIx64 " is not found\n", oid); - return 0; + return false; +} + +bool oid_in_recovery(uint64_t oid) +{ + struct recovery_work *rw = recovering_work; + + if (!node_in_recovery()) + return false; + + if (sd_store->exist(oid)) { + dprintf("the object %" PRIx64 " is already recoverd\n", oid); + return false; + } + + if (before(rw->epoch, sys->epoch)) + return true; + + /* If we are in preparation of object list, oid is not recovered yet */ + if (rw->state == RW_INIT) + return true; + + return schedule_oid(oid); } static void free_recovery_work(struct recovery_work *rw) diff --git a/sheep/sdnet.c b/sheep/sdnet.c index 4eca5f7..6323ee3 100644 --- a/sheep/sdnet.c +++ b/sheep/sdnet.c @@ -216,10 +216,10 @@ static bool request_in_recovery(struct request *req) { /* * Request from recovery should go down the Farm even if - * is_recoverying_oid() returns true because we should also try snap + * oid_in_recovery() returns true because we should also try snap * cache of the Farm and return the error code back if not found. */ - if (is_recoverying_oid(req->local_oid) && + if (oid_in_recovery(req->local_oid) && !(req->rq.flags & SD_FLAG_CMD_RECOVERY)) { /* * Put request on wait queues of local node diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h index 143b893..60432c7 100644 --- a/sheep/sheep_priv.h +++ b/sheep/sheep_priv.h @@ -286,7 +286,7 @@ int get_obj_list(const struct sd_list_req *, struct sd_list_rsp *, void *); int start_recovery(struct vnode_info *cur_vnodes, struct vnode_info *old_vnodes); void resume_recovery_work(void); -int is_recoverying_oid(uint64_t oid); +bool oid_in_recovery(uint64_t oid); int is_recovery_init(void); int node_in_recovery(void); -- 1.7.10.2 |