[Sheepdog] [PATCH v3 2/7] sheep: transient failure - parameter changes

yaohaiting.wujue at gmail.com yaohaiting.wujue at gmail.com
Wed May 2 09:12:50 CEST 2012


From: HaiTing Yao <wujue.yht at taobao.com>

Usage: collie cluster format [-t templeave]

Options:
  -t, --templeave         specify the time(in seconds) node can leave
then join again

Without this parameter, there is no transient failure detection and
sheepdog works as before.

Signed-off-by: HaiTing Yao <wujue.yht at taobao.com>
---
 collie/cluster.c         |   25 ++++++++++++++++++-------
 collie/collie.c          |    2 ++
 include/sheepdog_proto.h |    1 +
 sheep/ops.c              |    5 +++++
 4 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/collie/cluster.c b/collie/cluster.c
index 8d872f1..256cea2 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -23,6 +23,7 @@ struct cluster_cmd_data {
 	int nohalt;
 	int force;
 	char name[STORE_LEN];
+	char leavetime[LEAVE_TIME_LEN];
 } cluster_cmd_data;
 
 #define DEFAULT_STORE	"simple"
@@ -79,7 +80,7 @@ static int cluster_format(int argc, char **argv)
 	struct sd_so_rsp *rsp = (struct sd_so_rsp *)&hdr;
 	unsigned rlen, wlen;
 	struct timeval tv;
-	char store_name[STORE_LEN];
+	char data[STORE_LEN + LEAVE_TIME_LEN];
 
 	fd = connect_to(sdhost, sdport);
 	if (fd < 0)
@@ -97,14 +98,21 @@ static int cluster_format(int argc, char **argv)
 	hdr.ctime = (uint64_t) tv.tv_sec << 32 | tv.tv_usec * 1000;
 
 	if (strlen(cluster_cmd_data.name))
-		strncpy(store_name, cluster_cmd_data.name, STORE_LEN);
+		strncpy(data, cluster_cmd_data.name, STORE_LEN);
 	else
-		strcpy(store_name, DEFAULT_STORE);
-	hdr.data_length = wlen = strlen(store_name) + 1;
+		strcpy(data, DEFAULT_STORE);
+	hdr.data_length = wlen = strlen(data) + 1;
+	printf("using backend %s store\n", data);
+
+	if (strlen(cluster_cmd_data.leavetime)) {
+		strncpy(data + STORE_LEN, cluster_cmd_data.leavetime,
+			LEAVE_TIME_LEN);
+		hdr.data_length = wlen = STORE_LEN + LEAVE_TIME_LEN;
+	}
+
 	hdr.flags |= SD_FLAG_CMD_WRITE;
 
-	printf("using backend %s store\n", store_name);
-	ret = exec_req(fd, (struct sd_req *)&hdr, store_name, &wlen, &rlen);
+	ret = exec_req(fd, (struct sd_req *)&hdr, data, &wlen, &rlen);
 	close(fd);
 
 	if (ret) {
@@ -477,7 +485,7 @@ static int cluster_recover(int argc, char **argv)
 static struct subcommand cluster_cmd[] = {
 	{"info", NULL, "aprh", "show cluster information",
 	 SUBCMD_FLAG_NEED_NODELIST, cluster_info},
-	{"format", NULL, "bcHaph", "create a Sheepdog store",
+	{"format", NULL, "btcHaph", "create a Sheepdog store",
 	 0, cluster_format},
 	{"shutdown", NULL, "aph", "stop Sheepdog",
 	 SUBCMD_FLAG_NEED_NODELIST, cluster_shutdown},
@@ -531,6 +539,9 @@ static int cluster_parser(int ch, char *opt)
 	case 'l':
 		cluster_cmd_data.list = 1;
 		break;
+	case 't':
+		strncpy(cluster_cmd_data.leavetime, opt, LEAVE_TIME_LEN - 1);
+		break;
 	}
 
 	return 0;
diff --git a/collie/collie.c b/collie/collie.c
index 5a2dc82..0e23096 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -41,6 +41,8 @@ static const struct sd_option collie_options[] = {
 
 	/* cluster options */
 	{'b', "store", 1, "specify backend store"},
+	{'t', "templeave", 1,
+		"specify the time(in seconds) node can leave then join again"},
 	{'c', "copies", 1, "specify the data redundancy (number of copies)"},
 	{'H', "nohalt", 0, "serve IO requests even if there are too few\n\
                           nodes for the configured redundancy"},
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 11c2c7c..23beada 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -98,6 +98,7 @@
 #define CURRENT_VDI_ID 0
 
 #define STORE_LEN 16
+#define LEAVE_TIME_LEN 8
 
 struct sd_req {
 	uint8_t		proto_ver;
diff --git a/sheep/ops.c b/sheep/ops.c
index 27351af..1c25499 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -246,6 +246,11 @@ static int cluster_make_fs(const struct sd_req *req, struct sd_rsp *rsp,
 	created_time = hdr->ctime;
 	set_cluster_ctime(created_time);
 
+	if (hdr->data_length > STORE_LEN)
+		sys->templeft_time = atoi((char *)data + STORE_LEN);
+	else
+		sys->templeft_time = 0;
+
 	for (i = 1; i <= latest_epoch; i++)
 		remove_epoch(i);
 
-- 
1.7.1




More information about the sheepdog mailing list