[Sheepdog] [PATCH 1/2] try to read object from backup nodes when locally read failed.

Li Wenpeng levin108 at gmail.com
Tue Feb 21 05:15:49 CET 2012


From: levin li <levin108 at gmail.com>

---
 sheep/store.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/sheep/store.c b/sheep/store.c
index 56e3cd2..59eba86 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -222,7 +222,7 @@ static int forward_read_obj_req(struct request *req)
 	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
 	struct sd_vnode *e;
 	uint64_t oid = hdr.oid;
-	int copies;
+	int copies, copies_index = 0;
 
 	e = req->entry;
 	nr = req->nr_vnodes;
@@ -243,11 +243,21 @@ static int forward_read_obj_req(struct request *req)
 
 		if (is_myself(e[n].addr, e[n].port)) {
 			ret = do_local_io(req, hdr.epoch);
+
+			if (SD_RES_SUCCESS != ret && 
+		    	!(SD_RES_NO_OBJ == ret && hdr.flags & SD_FLAG_CMD_RECOVERY)) {
+
+				dprintf("%x, read object %" PRIx64" locally failed.\n",
+						hdr.opcode, oid);
+				break;
+			}
+            
 			goto out;
 		}
 	}
 
-	n = obj_to_sheep(e, nr, oid, 0);
+fetch_again:
+	n = obj_to_sheep(e, nr, oid, copies_index);
 
 	fd = get_sheep_fd(e[n].addr, e[n].port, e[n].node_idx, hdr.epoch);
 	if (fd < 0) {
@@ -262,6 +272,12 @@ static int forward_read_obj_req(struct request *req)
 
 	if (ret) { /* network errors */
 		del_sheep_fd(fd);
+
+		copies_index ++;
+		if (copies_index < copies) {
+			goto fetch_again;
+		}
+
 		ret = SD_RES_NETWORK_ERROR;
 	} else {
 		memcpy(&req->rp, rsp, sizeof(*rsp));
-- 
1.7.1




More information about the sheepdog mailing list