[Sheepdog] [PATCH 2/4 v2] sheep: transient failure - parameter changes

HaiTing Yao yaohaiting.wujue at gmail.com
Thu Mar 15 07:27:25 CET 2012


Usage: collie cluster format [-b store] [-t templeave] [-c copies] [-H]
[-a address] [-p port] [-h]
Options:
  -b, --store             specify backend store
  -t, --templeave         specify the time(in seconds) node can leave
then join again
  -c, --copies            specify the data redundancy (number of copies)
  -H, --nohalt            serve IO requests even if there are too few
                          nodes for the configured redundancy
  -a, --address           specify the daemon address (default:
localhost)
  -p, --port              specify the daemon port
  -h, --help              display this help and exit

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

diff --git a/collie/cluster.c b/collie/cluster.c
index b846a9a..052378d 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,20 @@ 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) {
@@ -427,7 +434,7 @@ static int cluster_recover(int argc, char **argv)
 static struct subcommand cluster_cmd[] = {
 	{"info", NULL, "aprh", "show cluster information",
 	 0, 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},
@@ -479,6 +486,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 7989bb2..3fcd753 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 2d0d5ec..580d4c2 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -95,6 +95,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 783d68d..b75f0df 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -164,6 +164,11 @@ static int cluster_make_fs(const struct sd_req *req, struct sd_rsp *rsp,
 	ctime = hdr->ctime;
 	set_cluster_ctime(ctime);
 
+	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