[sheepdog] [PATCH v3 8/8] sheep: use node_id_cmp to compare node

Liu Yuan namei.unix at gmail.com
Tue Jun 26 10:45:44 CEST 2012


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

- remove vnode_node_cmp(), node_cmp()

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 include/sheep.h       |   31 +++++++------------------------
 sheep/cluster/local.c |    2 +-
 sheep/group.c         |    6 +++---
 sheep/recovery.c      |    4 ++--
 sheep/sockfd_cache.c  |   17 -----------------
 5 files changed, 13 insertions(+), 47 deletions(-)

diff --git a/include/sheep.h b/include/sheep.h
index d26daae..7ab2bf7 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -329,43 +329,26 @@ static inline const char *sd_strerror(int err)
 	return "Invalid error code";
 }
 
-static inline int vnode_node_cmp(const void *a, const void *b)
+static inline int node_id_cmp(const void *a, const void *b)
 {
-	const struct sd_vnode *node1 = a;
-	const struct sd_node *node2 = b;
-	int cmp;
-
-	cmp = memcmp(node1->nid.addr, node2->nid.addr, sizeof(node1->nid.addr));
-	if (cmp != 0)
-		return cmp;
-
-	if (node1->nid.port < node2->nid.port)
-		return -1;
-	if (node1->nid.port > node2->nid.port)
-		return 1;
-	return 0;
-}
-
-static inline int node_cmp(const void *a, const void *b)
-{
-	const struct sd_node *node1 = a;
-	const struct sd_node *node2 = b;
+	const struct node_id *node1 = a;
+	const struct node_id *node2 = b;
 	int cmp;
 
-	cmp = memcmp(node1->nid.addr, node2->nid.addr, sizeof(node1->nid.addr));
+	cmp = memcmp(node1->addr, node2->addr, sizeof(node1->addr));
 	if (cmp != 0)
 		return cmp;
 
-	if (node1->nid.port < node2->nid.port)
+	if (node1->port < node2->port)
 		return -1;
-	if (node1->nid.port > node2->nid.port)
+	if (node1->port > node2->port)
 		return 1;
 	return 0;
 }
 
 static inline int node_eq(const struct sd_node *a, const struct sd_node *b)
 {
-	return node_cmp(a, b) == 0;
+	return node_id_cmp(a, b) == 0;
 }
 
 static inline int vnode_cmp(const void *a, const void *b)
diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index ef50107..0fc2f89 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -231,7 +231,7 @@ static void add_event(enum local_event_type type, struct sd_node *node,
 		ev.nr_nodes++;
 		break;
 	case EVENT_LEAVE:
-		n = lfind(node, ev.nodes, &ev.nr_nodes, sizeof(*n), node_cmp);
+		n = lfind(node, ev.nodes, &ev.nr_nodes, sizeof(*n), node_id_cmp);
 		if (!n)
 			panic("internal error\n");
 		idx = n - ev.nodes;
diff --git a/sheep/group.c b/sheep/group.c
index 39e2a50..1f923f7 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -125,7 +125,7 @@ bool have_enough_zones(void)
 static int get_node_idx(struct vnode_info *vnode_info, struct sd_node *ent)
 {
 	ent = bsearch(ent, vnode_info->nodes, vnode_info->nr_nodes,
-		      sizeof(*ent), node_cmp);
+		      sizeof(*ent), node_id_cmp);
 	if (!ent)
 		return -1;
 
@@ -217,7 +217,7 @@ static struct vnode_info *alloc_vnode_info(struct sd_node *nodes,
 
 	vnode_info->nr_nodes = nr_nodes;
 	memcpy(vnode_info->nodes, nodes, sizeof(*nodes) * nr_nodes);
-	qsort(vnode_info->nodes, nr_nodes, sizeof(*nodes), node_cmp);
+	qsort(vnode_info->nodes, nr_nodes, sizeof(*nodes), node_id_cmp);
 
 	vnode_info->nr_vnodes = nodes_to_vnodes(nodes, nr_nodes,
 						vnode_info->vnodes);
@@ -574,7 +574,7 @@ static int cluster_wait_for_join_check(struct sd_node *joined,
 			epoch, local_epoch);
 
 		if (bsearch(joined, local_entries, nr_local_entries,
-			    sizeof(struct sd_node), node_cmp))
+			    sizeof(struct sd_node), node_id_cmp))
 			return CJ_RES_FAIL;
 		return CJ_RES_JOIN_LATER;
 	}
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 0fafea8..8656562 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -154,7 +154,7 @@ static int is_invalid_vnode(struct sd_vnode *entry, struct sd_node *nodes,
 				int nr_nodes)
 {
 	if (bsearch(entry, nodes, nr_nodes, sizeof(struct sd_node),
-		    vnode_node_cmp))
+		    node_id_cmp))
 		return 0;
 	return 1;
 }
@@ -532,7 +532,7 @@ static void screen_object_list(struct recovery_work *rw,
 static int newly_joined(struct sd_node *node, struct recovery_work *rw)
 {
 	if (bsearch(node, rw->old_vnodes->nodes, rw->old_vnodes->nr_nodes,
-		    sizeof(struct sd_node), node_cmp))
+		    sizeof(struct sd_node), node_id_cmp))
 		return 0;
 	return 1;
 }
diff --git a/sheep/sockfd_cache.c b/sheep/sockfd_cache.c
index 372ec58..c27d99b 100644
--- a/sheep/sockfd_cache.c
+++ b/sheep/sockfd_cache.c
@@ -66,23 +66,6 @@ struct sockfd_cache_entry {
 	uint8_t fd_in_use[SOCKFD_CACHE_MAX_FD];
 };
 
-static inline int node_id_cmp(const void *a, const void *b)
-{
-	const struct node_id *node1 = a;
-	const struct node_id *node2 = b;
-	int cmp;
-
-	cmp = memcmp(node1->addr, node2->addr, sizeof(node1->addr));
-	if (cmp != 0)
-		return cmp;
-
-	if (node1->port < node2->port)
-		return -1;
-	if (node1->port > node2->port)
-		return 1;
-	return 0;
-}
-
 static struct sockfd_cache_entry *
 sockfd_cache_insert(struct sockfd_cache_entry *new)
 {
-- 
1.7.10.2




More information about the sheepdog mailing list