[sheepdog] [PATCH 7/8] sheep: use node_id_cmp to compare node
Liu Yuan
namei.unix at gmail.com
Wed Jun 27 09:25:38 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/accord.c | 3 ++-
sheep/cluster/local.c | 2 +-
sheep/cluster/zookeeper.c | 2 +-
sheep/group.c | 6 +++---
sheep/recovery.c | 4 ++--
sheep/sockfd_cache.c | 17 -----------------
7 files changed, 16 insertions(+), 49 deletions(-)
diff --git a/include/sheep.h b/include/sheep.h
index d4037bd..e14bf1d 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -327,43 +327,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/accord.c b/sheep/cluster/accord.c
index ae75ced..12dc687 100644
--- a/sheep/cluster/accord.c
+++ b/sheep/cluster/accord.c
@@ -266,7 +266,8 @@ static int add_event(struct acrd_handle *ah, enum acrd_event_type type,
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)
goto out;
idx = n - ev.nodes;
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/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 57b91d8..4c07a3d 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -330,7 +330,7 @@ static inline int zk_node_cmp(const void *a, const void *b)
{
const struct zk_node *znode1 = a;
const struct zk_node *znode2 = b;
- return node_cmp(&znode1->node, &znode2->node);
+ return node_id_cmp(&znode1->node.nid, &znode2->node.nid);
}
static void node_btree_add(void **btroot, struct zk_node *znode)
diff --git a/sheep/group.c b/sheep/group.c
index 035bcca..c7f94e0 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