[sheepdog] [PATCH RFC 01/11] sheep: enable variale-length of join_message in response of join event
Yunkai Zhang
yunkai.me at gmail.com
Wed Aug 8 23:14:13 CEST 2012
From: Yunkai Zhang <qiushu.zyk at taobao.com>
Next patch need variale-length of join_message when master need to share
more data for joining node.
Signed-off-by: Yunkai Zhang <qiushu.zyk at taobao.com>
---
sheep/cluster.h | 6 ++++--
sheep/cluster/accord.c | 2 +-
sheep/cluster/corosync.c | 9 ++++++---
sheep/cluster/local.c | 2 +-
sheep/cluster/zookeeper.c | 2 +-
sheep/group.c | 7 ++++++-
6 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/sheep/cluster.h b/sheep/cluster.h
index 75596a8..b5c3a30 100644
--- a/sheep/cluster.h
+++ b/sheep/cluster.h
@@ -20,11 +20,13 @@
#include <memory.h>
#include "sheepdog_proto.h"
+#include "internal_proto.h"
#include "sheep.h"
#include "logger.h"
/* maximum payload size sent in ->notify and ->unblock */
-#define SD_MAX_EVENT_BUF_SIZE (64 * 1024)
+#define SD_MAX_EVENT_BUF_SIZE (sizeof(struct join_message) \
+ + SD_MAX_NODES * sizeof(struct sd_node))
enum cluster_join_result {
CJ_RES_SUCCESS, /* Success */
@@ -197,7 +199,7 @@ void sd_leave_handler(struct sd_node *left, struct sd_node *members,
void sd_notify_handler(struct sd_node *sender, void *msg, size_t msg_len);
bool sd_block_handler(struct sd_node *sender);
enum cluster_join_result sd_check_join_cb(struct sd_node *joining,
- void *opaque);
+ void *opaque, size_t *opaque_len);
void recalculate_vnodes(struct sd_node *nodes, int nr_nodes);
#endif
diff --git a/sheep/cluster/accord.c b/sheep/cluster/accord.c
index a0f1d00..d0fb892 100644
--- a/sheep/cluster/accord.c
+++ b/sheep/cluster/accord.c
@@ -481,7 +481,7 @@ static void acrd_handler(int listen_fd, int events, void *data)
break;
}
- res = sd_check_join_cb(&ev.sender, ev.buf);
+ res = sd_check_join_cb(&ev.sender, ev.buf, &ev.buf_len);
ev.join_result = res;
ev.type = EVENT_JOIN_RESPONSE;
acrd_queue_push_back(ahandle, &ev);
diff --git a/sheep/cluster/corosync.c b/sheep/cluster/corosync.c
index b3f6471..af6c1da 100644
--- a/sheep/cluster/corosync.c
+++ b/sheep/cluster/corosync.c
@@ -283,6 +283,8 @@ static int __corosync_dispatch_one(struct corosync_event *cevent)
{
enum cluster_join_result res;
struct sd_node entries[SD_MAX_NODES];
+ char *buf[SD_MAX_EVENT_BUF_SIZE];
+ size_t buf_len;
int idx;
static bool blocked = false;
@@ -299,14 +301,15 @@ static int __corosync_dispatch_one(struct corosync_event *cevent)
/* check_join() must be called only once */
return 0;
- res = sd_check_join_cb(&cevent->sender.ent,
- cevent->msg);
+ buf_len = cevent->msg_len;
+ memcpy(buf, cevent->msg, buf_len);
+ res = sd_check_join_cb(&cevent->sender.ent, buf, &buf_len);
if (res == CJ_RES_MASTER_TRANSFER)
nr_cpg_nodes = 0;
send_message(COROSYNC_MSG_TYPE_JOIN_RESPONSE, res,
&cevent->sender, cpg_nodes, nr_cpg_nodes,
- cevent->msg, cevent->msg_len);
+ buf, buf_len);
if (res == CJ_RES_MASTER_TRANSFER) {
eprintf("failed to join sheepdog cluster: please retry when master is up\n");
diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index 3e6333a..38ad320 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -357,7 +357,7 @@ static bool local_process_event(void)
if (!node_eq(&ev->nodes[0], &this_node))
return false;
- res = sd_check_join_cb(&ev->sender, ev->buf);
+ res = sd_check_join_cb(&ev->sender, ev->buf, &ev->buf_len);
ev->join_result = res;
ev->type = EVENT_JOIN_RESPONSE;
msync(ev, sizeof(*ev), MS_SYNC);
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 4cd5be8..f70fc1c 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -681,7 +681,7 @@ static void zk_handler(int listen_fd, int events, void *data)
break;
}
- res = sd_check_join_cb(&ev.sender.node, ev.buf);
+ res = sd_check_join_cb(&ev.sender.node, ev.buf, &ev.buf_len);
ev.join_result = res;
ev.type = EVENT_JOIN_RESPONSE;
ev.sender.joined = 1;
diff --git a/sheep/group.c b/sheep/group.c
index 05ffb3e..cb244f7 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -917,10 +917,12 @@ void sd_notify_handler(struct sd_node *sender, void *data, size_t data_len)
}
}
-enum cluster_join_result sd_check_join_cb(struct sd_node *joining, void *opaque)
+enum cluster_join_result sd_check_join_cb(struct sd_node *joining,
+ void *opaque, size_t *opaque_len)
{
struct join_message *jm = opaque;
char str[256];
+ size_t n;
int ret;
if (jm->proto_ver != SD_SHEEP_PROTO_VER) {
@@ -1010,6 +1012,9 @@ enum cluster_join_result sd_check_join_cb(struct sd_node *joining, void *opaque)
if (jm->cluster_status != SD_STATUS_OK &&
(ret == CJ_RES_SUCCESS || ret == CJ_RES_JOIN_LATER))
format_exceptional_node_list(jm);
+
+ n = jm->nr_failed_nodes + jm->nr_delayed_nodes;
+ *opaque_len = sizeof(*jm) + n * sizeof(jm->nodes[0]);
return ret;
}
--
1.7.11.2
More information about the sheepdog
mailing list