[sheepdog] [PATCH v2 4/5] sheep/md: change the method of generating vnodes in md
Robin Dong
robin.k.dong at gmail.com
Wed May 7 12:25:41 CEST 2014
From: Robin Dong <sanbai at taobao.com>
Because the method of generating vnodes in cluster is changed, the
method of generating vnodes in md should changed also.
After changing generate item from nodes to disks, adding new disk
or removing old disk should also cause whole cluster to do recovery.
Signed-off-by: Robin Dong <sanbai at taobao.com>
---
sheep/group.c | 28 +++++++++++++++++++++++++++-
sheep/md.c | 32 ++++++++++++++++++++++++++++----
2 files changed, 55 insertions(+), 5 deletions(-)
diff --git a/sheep/group.c b/sheep/group.c
index efb47fb..d72ba39 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -638,6 +638,32 @@ void wait_get_vdis_done(void)
sd_debug("vdi list ready");
}
+static bool nodes_changed(const struct cluster_info *cinfo,
+ const struct rb_root *nroot,
+ size_t nr_nodes)
+{
+ const struct sd_node *key, *n;
+ int i, ret;
+
+ if (nr_nodes != cinfo->nr_nodes)
+ return true;
+
+ if (!is_cluster_diskmode(cinfo))
+ return false;
+
+ for (i = 0; i < cinfo->nr_nodes; i++) {
+ key = cinfo->nodes + i;
+ n = rb_search(nroot, key, rb, node_cmp);
+ if (!n)
+ continue;
+ ret = memcmp(n->disks, key->disks,
+ sizeof(struct disk_info) * DISK_MAX);
+ if (ret)
+ return true;
+ }
+ return false;
+}
+
static void update_cluster_info(const struct cluster_info *cinfo,
const struct sd_node *joined,
const struct rb_root *nroot,
@@ -670,7 +696,7 @@ static void update_cluster_info(const struct cluster_info *cinfo,
/* initialize config file */
set_cluster_config(&sys->cinfo);
- if (nr_nodes != cinfo->nr_nodes) {
+ if (nodes_changed(cinfo, nroot, nr_nodes)) {
int ret;
if (old_vnode_info)
put_vnode_info(old_vnode_info);
diff --git a/sheep/md.c b/sheep/md.c
index 54d2f8c..b95e032 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -70,7 +70,18 @@ static struct vdisk *oid_to_vdisk(uint64_t oid)
static void create_vdisks(const struct disk *disk)
{
uint64_t hval = sd_hash(disk->path, strlen(disk->path));
- int nr = vdisk_number(disk);
+ const struct sd_node *n = &sys->this_node;
+ uint64_t node_hval;
+ int nr;
+
+ if (is_cluster_diskmode(&sys->cinfo)) {
+ node_hval = sd_hash(&n->nid, offsetof(typeof(n->nid), io_addr));
+ hval = fnv_64a_64(node_hval, hval);
+ nr = disk->space / WEIGHT_MIN;
+ if (0 == n->nid.port)
+ return;
+ } else
+ nr = vdisk_number(disk);
for (int i = 0; i < nr; i++) {
struct vdisk *v = xmalloc(sizeof(*v));
@@ -92,7 +103,16 @@ static inline void vdisk_free(struct vdisk *v)
static void remove_vdisks(const struct disk *disk)
{
uint64_t hval = sd_hash(disk->path, strlen(disk->path));
- int nr = vdisk_number(disk);
+ const struct sd_node *n = &sys->this_node;
+ uint64_t node_hval;
+ int nr;
+
+ if (is_cluster_diskmode(&sys->cinfo)) {
+ node_hval = sd_hash(&n->nid, offsetof(typeof(n->nid), io_addr));
+ hval = fnv_64a_64(node_hval, hval);
+ nr = disk->space / WEIGHT_MIN;
+ } else
+ nr = vdisk_number(disk);
for (int i = 0; i < nr; i++) {
struct vdisk *v;
@@ -490,8 +510,12 @@ static inline void kick_recover(void)
{
struct vnode_info *vinfo = get_vnode_info();
- start_recovery(vinfo, vinfo, false);
- put_vnode_info(vinfo);
+ if (is_cluster_diskmode(&sys->cinfo))
+ sys->cdrv->update_node(&sys->this_node);
+ else {
+ start_recovery(vinfo, vinfo, false);
+ put_vnode_info(vinfo);
+ }
}
static void md_do_recover(struct work *work)
--
1.7.12.4
More information about the sheepdog
mailing list