[sheepdog] [PATCH RFC 04/11] sheep: don't cleanup working directory when sheep joined back

Yunkai Zhang yunkai.me at gmail.com
Wed Aug 8 23:14:16 CEST 2012


From: Yunkai Zhang <qiushu.zyk at taobao.com>

After disable recovery, sheep can leave and join back again, it will
reuse its old data, that is what we want. Of course, we should solve the problem
that the joining node may lose some data updating, this work will be done in
follow-up patches.

Signed-off-by: Yunkai Zhang <qiushu.zyk at taobao.com>
---
 sheep/group.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index 30730df..8e4a3aa 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -616,9 +616,10 @@ static int cluster_wait_for_join_check(struct sd_node *joined,
 	return CJ_RES_SUCCESS;
 }
 
-static int cluster_running_check(struct join_message *jm)
+static int cluster_running_check(struct sd_node *joining,
+				 struct join_message *jm)
 {
-	int ret;
+	int i, ret;
 
 	/*
 	 * When the joining node is newly created and we are not waiting for
@@ -631,6 +632,20 @@ static int cluster_running_check(struct join_message *jm)
 	}
 
 	jm->inc_epoch = 1;
+	if (sys->disable_recovery) {
+		/*
+		 * If joining node joined back again, let's reset the inc_epoch
+		 * flag so that it can reuse its old data, otherwise its working
+		 * directory will be cleared.
+		 */
+		for (i = 0; i < nr_leaving_nodes; i++) {
+			if (node_eq(joining, leaving_nodes + i)) {
+				dprintf("reset inc_epoch\n");
+				jm->inc_epoch = 0;
+				break;
+			}
+		}
+	}
 	return CJ_RES_SUCCESS;
 }
 
@@ -757,6 +772,7 @@ static void finish_join(struct join_message *msg, struct sd_node *joined,
 	/* We need to purge the stale objects for sheep joining back
 	 * after crash
 	 */
+	dprintf("reset inc_epoch:%d\n", msg->inc_epoch);
 	if (msg->inc_epoch)
 		if (!sys->gateway_only &&
 		    sd_store->purge_obj &&
@@ -967,8 +983,8 @@ static void update_cluster_info(struct join_message *msg,
 
 		sys->status = msg->cluster_status;
 
-		if (msg->inc_epoch) {
-			if (!sys->disable_recovery) {
+		if (!sys->disable_recovery) {
+			if (msg->inc_epoch) {
 				uatomic_inc(&sys->epoch);
 				log_current_epoch();
 				clear_exceptional_node_lists();
@@ -981,10 +997,9 @@ static void update_cluster_info(struct join_message *msg,
 
 				start_recovery(current_vnode_info,
 					       old_vnode_info);
-			} else
-				prepare_join_recovery(msg, joined, nodes,
-						      nr_nodes);
-		}
+			}
+		} else
+			prepare_join_recovery(msg, joined, nodes, nr_nodes);
 
 		if (have_enough_zones())
 			sys->status = SD_STATUS_OK;
@@ -1106,7 +1121,7 @@ enum cluster_join_result sd_check_join_cb(struct sd_node *joining,
 		break;
 	case SD_STATUS_OK:
 	case SD_STATUS_HALT:
-		ret = cluster_running_check(jm);
+		ret = cluster_running_check(joining, jm);
 		break;
 	default:
 		eprintf("invalid system status: 0x%x\n", sys->status);
-- 
1.7.11.2




More information about the sheepdog mailing list