[Sheepdog] [PATCH v3 1/3] add a field nr_zones to cluster_info

Li Wenpeng levin108 at gmail.com
Thu Apr 5 08:29:40 CEST 2012


From: levin li <xingke.lwp at taobao.com>

In some path such as the object cache path, we need to determine the
copies count with the zones count, but we can't get the sd_vnodes list
to calucate the zones count, so it's better to include a nr_zones
field in cluster_info, everytime the cluster complete recovering, we
recalucate the nr_zones field.

Signed-off-by: levin li <xingke.lwp at taobao.com>
---
 sheep/farm/trunk.c   |    8 ++++++--
 sheep/group.c        |   16 ++++++++--------
 sheep/object_cache.c |    7 ++++++-
 sheep/sheep_priv.h   |    1 +
 4 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/sheep/farm/trunk.c b/sheep/farm/trunk.c
index 2a51a83..ce36e0d 100644
--- a/sheep/farm/trunk.c
+++ b/sheep/farm/trunk.c
@@ -287,10 +287,14 @@ static struct omap_entry *omap_file_insert(struct strbuf *buf, struct omap_entry
 
 static int oid_stale(uint64_t oid)
 {
-	int i, vidx;
+	int i, vidx, copies;
 	struct sd_vnode *vnodes = sys->vnodes;
 
-	for (i = 0; i < sys->nr_sobjs; i++) {
+	copies = sys->nr_sobjs;
+	if (copies > sys->nr_zones)
+		copies = sys->nr_zones;
+
+	for (i = 0; i < copies; i++) {
 		vidx = obj_to_sheep(vnodes, sys->nr_vnodes, oid, i);
 		if (is_myself(vnodes[vidx].addr, vnodes[vidx].port))
 			return 0;
diff --git a/sheep/group.c b/sheep/group.c
index 97bf2d9..1e840c8 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -162,7 +162,7 @@ int get_ordered_sd_vnode_list(struct sd_vnode **entries,
 		return SD_RES_NO_MEM;
 	}
 
-	cache->nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
+	cache->nr_zones = sys->nr_zones;
 	memcpy(cache->vnodes, sys->vnodes, sizeof(sys->vnodes[0]) * sys->nr_vnodes);
 	cache->nr_vnodes = sys->nr_vnodes;
 	cache->epoch = sys->epoch;
@@ -589,6 +589,8 @@ join_finished:
 	qsort(sys->nodes, sys->nr_nodes, sizeof(*sys->nodes), node_cmp);
 	sys->nr_vnodes = nodes_to_vnodes(sys->nodes, sys->nr_nodes,
 					 sys->vnodes);
+	sys->nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
+
 	if (msg->cluster_status == SD_STATUS_OK ||
 	    msg->cluster_status == SD_STATUS_HALT) {
 		if (msg->inc_epoch) {
@@ -843,9 +845,7 @@ static void __sd_join_done(struct cpg_event *cevent)
 	}
 
 	if (sys_stat_halt()) {
-		int nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
-
-		if (nr_zones >= sys->nr_sobjs)
+		if (sys->nr_zones >= sys->nr_sobjs)
 			sys_stat_set(SD_STATUS_OK);
 	}
 
@@ -863,6 +863,8 @@ static void __sd_leave_done(struct cpg_event *cevent)
 	qsort(sys->nodes, sys->nr_nodes, sizeof(*sys->nodes), node_cmp);
 	sys->nr_vnodes = nodes_to_vnodes(sys->nodes, sys->nr_nodes,
 					 sys->vnodes);
+	sys->nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
+
 	if (sys_can_recover()) {
 		sys->epoch++;
 		update_epoch_store(sys->epoch);
@@ -875,9 +877,7 @@ static void __sd_leave_done(struct cpg_event *cevent)
 		start_recovery(sys->epoch);
 
 	if (sys_can_halt()) {
-		int nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
-
-		if (nr_zones < sys->nr_sobjs)
+		if (sys->nr_zones < sys->nr_sobjs)
 			sys_stat_set(SD_STATUS_HALT);
 	}
 }
@@ -1008,7 +1008,7 @@ int is_access_to_busy_objects(uint64_t oid)
 			continue;
 		}
 		if (oid == req->local_oid)
-				return 1;
+			return 1;
 	}
 	return 0;
 }
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 68251b5..c8b0e2c 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -271,6 +271,7 @@ int object_cache_pull(struct object_cache *oc, uint32_t idx)
 	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
 	struct sd_vnode *vnodes = sys->vnodes;
 	void *buf;
+	int copies;
 
 	if (is_vdi_obj(oid))
 		data_length = sizeof(struct sheepdog_inode);
@@ -283,8 +284,12 @@ int object_cache_pull(struct object_cache *oc, uint32_t idx)
 		goto out;
 	}
 
+	copies = sys->nr_sobjs;
+	if (sys->nr_zones < copies)
+		copies = sys->nr_zones;
+
 	/* Check if we can read locally */
-	for (i = 0; i < sys->nr_sobjs; i++) {
+	for (i = 0; i < copies; i++) {
 		n = obj_to_sheep(vnodes, sys->nr_vnodes, oid, i);
 		if (is_myself(vnodes[n].addr, vnodes[n].port)) {
 			struct siocb iocb = { 0 };
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 90accb0..8046516 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -137,6 +137,7 @@ struct cluster_info {
 	struct list_head blocking_conn_list;
 
 	uint32_t nr_sobjs;
+	int nr_zones;
 
 	struct list_head cpg_event_siblings;
 	struct cpg_event *cur_cevent;
-- 
1.7.1




More information about the sheepdog mailing list