[Sheepdog] [PATCH v4 4/8] sheep: teach sheep to use object cache

Liu Yuan namei.unix at gmail.com
Mon Mar 19 10:39:24 CET 2012


From: Liu Yuan <tailai.ly at taobao.com>

We only intrude IO code for gateway requests. Object IO path from
recovery logic is intact.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/store.c |   42 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/sheep/store.c b/sheep/store.c
index dfec235..ba2dc02 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -749,6 +749,28 @@ out:
 	return ret;
 }
 
+static int handle_gateway_request(struct request *req)
+{
+	struct sd_obj_req *hdr = (struct sd_obj_req *)&req->rq;
+	uint64_t oid = hdr->oid;
+	uint32_t vid = oid_to_vid(oid);
+	uint32_t idx = data_oid_to_idx(oid);
+	struct object_cache *cache;
+	int ret;
+
+	if (is_vdi_obj(oid))
+		idx |= 1 << CACHE_VDI_SHIFT;
+
+	cache = find_object_cache(vid);
+	cache->oid = oid;
+	if (object_cache_lookup(cache, idx) < 0) {
+		ret = object_cache_pull(cache, idx);
+		if (ret != SD_RES_SUCCESS)
+			return ret;
+	}
+	return object_cache_rw(cache, idx, req);
+}
+
 void do_io_request(struct work *work)
 {
 	struct request *req = container_of(work, struct request, work);
@@ -773,11 +795,19 @@ void do_io_request(struct work *work)
 			if (ret != SD_RES_SUCCESS)
 				goto out;
 		}
+		if (opcode == SD_OP_CREATE_AND_WRITE_OBJ || is_vmstate_obj(oid)
+		    || is_vdi_attr_obj(oid) || hdr->flags & SD_FLAG_CMD_WEAK_CONSISTENCY) {
+			/* For create, we skip the cache because of consistency check.
+			 * For vmstate && vdi_attr object && vdi operation, we don't do caching
+			 */
+			if (hdr->flags & SD_FLAG_CMD_WRITE)
+				ret = forward_write_obj_req(req);
+			else
+				ret = forward_read_obj_req(req);
+			goto out;
+		}
 
-		if (hdr->flags & SD_FLAG_CMD_WRITE)
-			ret = forward_write_obj_req(req);
-		else
-			ret = forward_read_obj_req(req);
+		ret = handle_gateway_request(req);
 	}
 out:
 	if (ret != SD_RES_SUCCESS)
@@ -2000,6 +2030,10 @@ int init_store(const char *d)
 			return ret;
 	} else
 		dprintf("no store found\n");
+
+	ret = object_cache_init(d);
+	if (ret)
+		return 1;
 	return ret;
 }
 
-- 
1.7.8.2




More information about the sheepdog mailing list