[Sheepdog] [PATCH v4 7/8] collie: flush the vdi before searching the object

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


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

'collie vdi object' need to read latest vdi object from backend
store to assist it to locate the object. Since the vdi object
is also cached in object cache, we need to flush it beforehand to
cluster.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 collie/vdi.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/collie/vdi.c b/collie/vdi.c
index 8260eba..6d516a4 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -248,8 +248,10 @@ static void get_data_oid(char *sheep, uint64_t oid, struct sd_obj_rsp *rsp,
 
 static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigned size)
 {
+	struct sd_obj_req req;
 	char name[128];
 	int i, fd, ret;
+	unsigned dummy = 0;
 	char *buf;
 
 	buf = zalloc(size);
@@ -258,6 +260,23 @@ static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigne
 		return;
 	}
 
+	fd = connect_to(sdhost, sdport);
+	if (fd < 0)
+		return;
+
+	memset(&req, 0, sizeof(req));
+	/* Guarantee that backend store has the latest vdi object */
+	req.opcode = SD_OP_FLUSH_VDI;
+	req.oid = oid;
+	req.epoch = node_list_version;
+
+	ret = exec_req(fd, (struct sd_req *)&req, NULL, &dummy, &dummy);
+	close(fd);
+	if (ret < 0) {
+		fprintf(stderr, "Failed to connect to %s\n", name);
+		return;
+	}
+
 	for (i = 0; i < nr_nodes; i++) {
 		unsigned wlen = 0, rlen = size;
 		struct sd_obj_req hdr;
-- 
1.7.8.2




More information about the sheepdog mailing list