From: Liu Yuan <tailai.ly at taobao.com> We should continue to read if one read fails, since we have strong consistency Signed-off-by: Liu Yuan <tailai.ly at taobao.com> --- sheep/gateway.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/sheep/gateway.c b/sheep/gateway.c index c89dd2c..ccae1b3 100644 --- a/sheep/gateway.c +++ b/sheep/gateway.c @@ -15,7 +15,11 @@ #include "sheep_priv.h" - +/* + * Try our best to read one copy and read local first. + * + * Return success if any read succeed. + */ int forward_read_obj_req(struct request *req) { int i, fd, ret = SD_RES_SUCCESS; @@ -35,7 +39,6 @@ int forward_read_obj_req(struct request *req) else nr_copies = get_nr_copies(req->vnodes); - /* TODO: we can do better; we need to check this first */ oid_to_vnodes(req->vnodes, oid, nr_copies, obj_vnodes); for (i = 0; i < nr_copies; i++) { v = obj_vnodes[i]; @@ -71,16 +74,21 @@ read_remote: ret = exec_req(fd, &fwd_hdr, req->data, &wlen, &rlen); - if (ret) { /* network errors */ + if (ret) { + dprintf("remote node might be crashed"); sheep_del_fd(v, fd, sock_idx); ret = SD_RES_NETWORK_ERROR; - continue; - } else { - sheep_put_fd(v, fd, sock_idx); - memcpy(&req->rp, rsp, sizeof(*rsp)); - ret = rsp->result; - break; + goto reset; } + sheep_put_fd(v, fd, sock_idx); + memcpy(&req->rp, rsp, sizeof(*rsp)); + ret = rsp->result; + if (ret == SD_RES_SUCCESS) + break; +reset: + /* Reset the hdr for next read */ + memcpy(&fwd_hdr, &req->rq, sizeof(fwd_hdr)); + fwd_hdr.flags |= SD_FLAG_CMD_IO_LOCAL; } return ret; } @@ -163,7 +171,7 @@ again: } finish_one_write(wi, i); } else { - eprintf("unhanlded poll event\n"); + eprintf("unhandled poll event\n"); } } finish_write: -- 1.7.10.2 |