[sheepdog] [PATCH v2 3/9] sheep: remove inc_epoch from join_message

MORITA Kazutaka morita.kazutaka at gmail.com
Fri Jul 12 22:25:53 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

This moves the check of epoch incrementation from
cluster_wait_for_join_check() to update_cluster_info() and removes the
inc_epoch field from the join_message structure.

This changes the size of the join_message structure,
SD_SHEEP_PROTO_VER is also updated.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/internal_proto.h |    6 ++----
 sheep/group.c            |   32 +++++++++-----------------------
 2 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/include/internal_proto.h b/include/internal_proto.h
index 317096e..d1fe0d2 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -20,7 +20,7 @@
 #include <stdint.h>
 #include <netinet/in.h>
 
-#define SD_SHEEP_PROTO_VER 0x07
+#define SD_SHEEP_PROTO_VER 0x08
 
 #define SD_DEFAULT_COPIES 3
 #define SD_MAX_COPIES 8
@@ -155,10 +155,8 @@ struct epoch_log {
 
 struct join_message {
 	uint8_t proto_ver;
-	uint8_t __pad1[7];
+	uint8_t __pad[3];
 	uint32_t cluster_status;
-	uint8_t inc_epoch; /* set non-zero when we increment epoch of all nodes */
-	uint8_t __pad2[3];
 
 	/*
 	 * A joining sheep puts the local cluster info here.  After the master
diff --git a/sheep/group.c b/sheep/group.c
index b6ae376..d58f097 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -466,21 +466,8 @@ static int cluster_wait_for_join_check(const struct sd_node *joining,
 	 * node list, we can set the cluster live now.
 	 */
 	if (sys->cinfo.epoch > 0 &&
-	    enough_nodes_gathered(jm, joining, nodes, nr_nodes)) {
-		/*
-		 * The number of current nodes is (nr_nodes + 1) because 'nodes'
-		 * doesn't contain the 'joining' node.
-		 */
-		size_t nr_current_nodes = nr_nodes + 1;
-
-		if (jm->cinfo.nr_nodes < nr_current_nodes)
-			/*
-			 * There are nodes which didn't exist in the previous
-			 * epoch, so we have to increment epoch.
-			 */
-			jm->inc_epoch = 1;
+	    enough_nodes_gathered(jm, joining, nodes, nr_nodes))
 		jm->cluster_status = SD_STATUS_OK;
-	}
 
 	return CJ_RES_SUCCESS;
 }
@@ -499,7 +486,6 @@ static int cluster_running_check(struct join_message *jm)
 			return ret;
 	}
 
-	jm->inc_epoch = 1;
 	return CJ_RES_SUCCESS;
 }
 
@@ -617,14 +603,15 @@ static struct vnode_info *alloc_old_vnode_info(const struct sd_node *joined,
 	return alloc_vnode_info(old_nodes, nr_nodes);
 }
 
-static void setup_backend_store(const char *store, bool need_purge)
+static void setup_backend_store(const struct join_message *jm)
 {
 	int ret;
 
 	if (!sd_store) {
-		sd_store = find_store_driver(store);
+		sd_store = find_store_driver((char *)jm->cinfo.store);
 		if (!sd_store)
-			panic("backend store %s not supported", store);
+			panic("backend store %s not supported",
+			      jm->cinfo.store);
 
 		ret = sd_store->init();
 		if (ret != SD_RES_SUCCESS)
@@ -635,7 +622,8 @@ static void setup_backend_store(const char *store, bool need_purge)
 	 * We need to purge the stale objects for sheep joining back
 	 * after crash
 	 */
-	if (need_purge && sd_store->purge_obj) {
+	if (xlfind(&sys->this_node, jm->cinfo.nodes, jm->cinfo.nr_nodes,
+		   node_cmp) == NULL) {
 		ret = sd_store->purge_obj();
 		if (ret != SD_RES_SUCCESS)
 			panic("can't remove stale objects");
@@ -651,8 +639,7 @@ static void finish_join(const struct join_message *msg,
 
 	if (msg->cinfo.store[0]) {
 		if (!sys->gateway_only)
-			setup_backend_store((char *)msg->cinfo.store,
-					    !!msg->inc_epoch);
+			setup_backend_store(msg);
 	}
 
 	sockfd_cache_add_group(nodes, nr_nodes);
@@ -754,7 +741,7 @@ static void update_cluster_info(const struct join_message *msg,
 
 		sys->status = msg->cluster_status;
 
-		if (msg->inc_epoch) {
+		if (nr_nodes != msg->cinfo.nr_nodes) {
 			int ret = inc_and_log_epoch();
 			if (ret != 0)
 				panic("cannot log current epoch %d",
@@ -888,7 +875,6 @@ enum cluster_join_result sd_check_join_cb(const struct sd_node *joining,
 	}
 
 	jm->cluster_status = sys->status;
-	jm->inc_epoch = 0;
 
 	switch (sys->status) {
 	case SD_STATUS_SHUTDOWN:
-- 
1.7.9.5




More information about the sheepdog mailing list