[sheepdog] [PATCH v2 6/8] sheep: try best forward_read_obj_req()

Liu Yuan namei.unix at gmail.com
Mon Jun 25 16:31:48 CEST 2012


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 |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/sheep/gateway.c b/sheep/gateway.c
index c89dd2c..01589cb 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,17 @@ 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;
 		}
+		sheep_put_fd(v, fd, sock_idx);
+		memcpy(&req->rp, rsp, sizeof(*rsp));
+		ret = rsp->result;
+		if (ret == SD_RES_SUCCESS)
+			break;
 	}
 	return ret;
 }
-- 
1.7.10.2




More information about the sheepdog mailing list