[Sheepdog] [PATCH v6 03/17] sheep: transfer store backend for newly joined node

Liu Yuan namei.unix at gmail.com
Thu Jan 12 14:37:14 CET 2012


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

When the new node joins the cluster, it doesn't know what kind of
backend store the cluster uses, so we need to transfer this information
by master node in the join phase.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 include/sheep.h |    2 +-
 sheep/group.c   |   12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/sheep.h b/include/sheep.h
index bbca7f8..785c8ae 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -17,7 +17,7 @@
 #include "net.h"
 #include "logger.h"
 
-#define SD_SHEEP_PROTO_VER 0x03
+#define SD_SHEEP_PROTO_VER 0x04
 
 #define SD_DEFAULT_REDUNDANCY 3
 #define SD_MAX_REDUNDANCY 8
diff --git a/sheep/group.c b/sheep/group.c
index e81007c..41242c9 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -27,6 +27,8 @@
 
 static int cdrv_fd;
 static struct coroutine *cdrv_co;
+extern struct store_driver *sd_store;
+extern char *obj_path;
 
 struct node {
 	struct sd_node ent;
@@ -44,7 +46,7 @@ struct join_message {
 	uint64_t ctime;
 	uint32_t result;
 	uint8_t inc_epoch; /* set non-zero when we increment epoch of all nodes */
-	uint8_t pad[3];
+	uint8_t store[STORE_LEN];
 	union {
 		struct sd_node nodes[0];
 		struct sd_node leave_nodes[0];
@@ -456,6 +458,8 @@ static void join(struct sd_node *joining, struct join_message *msg)
 	msg->nr_sobjs = sys->nr_sobjs;
 	msg->cluster_flags = sys->flags;
 	msg->ctime = get_cluster_ctime();
+	if (sd_store)
+		strcpy((char *)msg->store, sd_store->name);
 }
 
 static int get_vdi_bitmap_from(struct sd_node *node)
@@ -569,6 +573,12 @@ static void update_cluster_info(struct join_message *msg,
 	     && msg->inc_epoch)
 		update_epoch_log(sys->epoch);
 
+	if (!sd_store && strlen((char *)msg->store)) {
+		sd_store = find_store_driver((char *)msg->store);
+		if (sd_store)
+			sd_store->init(obj_path);
+	}
+
 join_finished:
 	sys->nodes[sys->nr_nodes++] = *joined;
 	qsort(sys->nodes, sys->nr_nodes, sizeof(*sys->nodes), node_cmp);
-- 
1.7.8.2




More information about the sheepdog mailing list