[Sheepdog] [zookeeper][PATCH 2/2] Revise coding style problems in zookeeper driver

Yunkai Zhang yunkai.me at gmail.com
Fri Apr 6 11:58:04 CEST 2012


I have checked and revised all coding style problems in
zookeeper driver using checkpatch.pl tool.

I found that other files, such as sheep.c, also have the
same problems, but this patch only focus on zookeeper.c.

Actually, I don't want to use a separate patch to fix coding
style, but there were so many such problems that it is very
hard to rebase previous patches, sorry:(

Signed-off-by: Yunkai Zhang <qiushu.zyk at taobao.com>
---
 sheep/cluster/zookeeper.c |  224 ++++++++++++++++++++++++++-------------------
 1 files changed, 131 insertions(+), 93 deletions(-)

diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index fedb5a9..440b437 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -31,22 +31,23 @@
 
 
 /* zookeeper API wrapper prototypes */
-ZOOAPI int zk_create(zhandle_t *zh, const char *path, const char *value,
-        int valuelen, const struct ACL_vector *acl, int flags,
-        char *path_buffer, int path_buffer_len);
+static int zk_create(zhandle_t *zh, const char *path, const char *value,
+		int valuelen, const struct ACL_vector *acl, int flags,
+		char *path_buffer, int path_buffer_len);
 
-ZOOAPI int zk_delete(zhandle_t *zh, const char *path, int version);
+static int zk_delete(zhandle_t *zh, const char *path, int version);
 
-ZOOAPI int zk_get(zhandle_t *zh, const char *path, int watch, char *buffer,
-                   int* buffer_len, struct Stat *stat);
+static int zk_get(zhandle_t *zh, const char *path, int watch, char *buffer,
+		int *buffer_len, struct Stat *stat);
 
-ZOOAPI int zk_set(zhandle_t *zh, const char *path, const char *buffer,
-                   int buflen, int version);
+static int zk_set(zhandle_t *zh, const char *path, const char *buffer,
+		int buflen, int version);
 
-ZOOAPI int zk_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat);
+static int zk_exists(zhandle_t *zh, const char *path, int watch,
+		struct Stat *stat);
 
-ZOOAPI int zk_get_children(zhandle_t *zh, const char *path, int watch,
-                            struct String_vector *strings);
+static int zk_get_children(zhandle_t *zh, const char *path, int watch,
+		struct String_vector *strings);
 
 /* iterate child znodes */
 #define FOR_EACH_ZNODE(zh, parent, path, strs)			       \
@@ -99,69 +100,70 @@ static struct zk_node zk_nodes[SD_MAX_NODES];
 static size_t nr_zk_nodes;
 
 /* zookeeper API wrapper */
-inline ZOOAPI int zk_create(zhandle_t *zh, const char *path, const char *value,
-        int valuelen, const struct ACL_vector *acl, int flags,
-        char *path_buffer, int path_buffer_len)
+inline int zk_create(zhandle_t *zh, const char *path, const char *value,
+		int valuelen, const struct ACL_vector *acl, int flags,
+		char *path_buffer, int path_buffer_len)
 {
 	int rc;
 	do {
 		rc = zoo_create(zh, path, value, valuelen, acl,
 				flags, path_buffer, path_buffer_len);
 		dprintf("rc:%d\n", rc);
-	}while(rc==ZOPERATIONTIMEOUT || rc==ZCONNECTIONLOSS);
+	} while (rc == ZOPERATIONTIMEOUT || rc == ZCONNECTIONLOSS);
 	return rc;
 }
 
-inline ZOOAPI int zk_delete(zhandle_t *zh, const char *path, int version)
+inline int zk_delete(zhandle_t *zh, const char *path, int version)
 {
 	int rc;
 	do {
 		rc = zoo_delete(zh, path, version);
 		dprintf("rc:%d\n", rc);
-	}while(rc==ZOPERATIONTIMEOUT || rc==ZCONNECTIONLOSS);
+	} while (rc == ZOPERATIONTIMEOUT || rc == ZCONNECTIONLOSS);
 	return rc;
 }
 
-inline ZOOAPI int zk_get(zhandle_t *zh, const char *path, int watch, char *buffer,
-                   int* buffer_len, struct Stat *stat)
+inline int zk_get(zhandle_t *zh, const char *path, int watch, char *buffer,
+		int *buffer_len, struct Stat *stat)
 {
 	int rc;
 	do {
 		rc = zoo_get(zh, path, watch, buffer, buffer_len, stat);
 		dprintf("rc:%d\n", rc);
-	}while(rc==ZOPERATIONTIMEOUT || rc==ZCONNECTIONLOSS);
+	} while (rc == ZOPERATIONTIMEOUT || rc == ZCONNECTIONLOSS);
 	return rc;
 }
 
-inline ZOOAPI int zk_set(zhandle_t *zh, const char *path, const char *buffer,
-                   int buflen, int version)
+inline int zk_set(zhandle_t *zh, const char *path, const char *buffer,
+		int buflen, int version)
 {
 	int rc;
 	do {
 		rc = zoo_set(zh, path, buffer, buflen, version);
 		dprintf("rc:%d\n", rc);
-	}while(rc==ZOPERATIONTIMEOUT || rc==ZCONNECTIONLOSS);
+	} while (rc == ZOPERATIONTIMEOUT || rc == ZCONNECTIONLOSS);
 	return rc;
 }
 
-inline ZOOAPI int zk_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat)
+inline int zk_exists(zhandle_t *zh, const char *path, int watch,
+		struct Stat *stat)
 {
 	int rc;
 	do {
 		rc = zoo_exists(zh, path, watch, stat);
 		dprintf("rc:%d\n", rc);
-	}while(rc==ZOPERATIONTIMEOUT || rc==ZCONNECTIONLOSS);
+	} while (rc == ZOPERATIONTIMEOUT || rc == ZCONNECTIONLOSS);
 	return rc;
 }
 
-inline ZOOAPI int zk_get_children(zhandle_t *zh, const char *path, int watch,
-                            struct String_vector *strings)
+inline int zk_get_children(zhandle_t *zh, const char *path, int watch,
+		struct String_vector *strings)
 {
 	int rc;
 	do {
 		rc = zoo_get_children(zh, path, watch, strings);
 		dprintf("rc:%d\n", rc);
-	}while(rc==ZOPERATIONTIMEOUT || rc==ZCONNECTIONLOSS);
+	} while (rc == ZOPERATIONTIMEOUT || rc == ZCONNECTIONLOSS);
 	return rc;
 }
 
@@ -173,11 +175,10 @@ static void zk_lock(zhandle_t *zh)
 again:
 	rc = zk_create(zh, LOCK_ZNODE, "", 0, &ZOO_OPEN_ACL_UNSAFE,
 			ZOO_EPHEMERAL, NULL, 0);
-	if (rc == ZOK){
+	if (rc == ZOK) {
 		dprintf("locked\n");
 		return;
-	}
-	else if (rc == ZNODEEXISTS) {
+	} else if (rc == ZNODEEXISTS) {
 		dprintf("retry, rc:%d\n", rc);
 		usleep(10000); /* FIXME: use watch notification */
 		goto again;
@@ -227,7 +228,8 @@ static int zk_queue_push(zhandle_t *zh, struct zk_event *ev)
 	sprintf(path, "%s/", QUEUE_ZNODE);
 	rc = zk_create(zh, path, (char *)ev, len,
 		&ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, buf, sizeof(buf));
-	dprintf("create path:%s, nr_nodes:%ld, queue_pos:%d, len:%d, rc:%d\n", buf, nr_zk_nodes, queue_pos, len, rc);
+	dprintf("create path:%s, nr_nodes:%ld, queue_pos:%d, len:%d, rc:%d\n",
+			buf, nr_zk_nodes, queue_pos, len, rc);
 	if (rc != ZOK)
 		panic("failed to zk_create path:%s, rc:%d\n", path, rc);
 
@@ -263,7 +265,8 @@ static int zk_queue_push_back(zhandle_t *zh, struct zk_event *ev)
 		len = (char *)(ev->buf) - (char *)ev + ev->buf_len;
 		sprintf(path, QUEUE_ZNODE "/%010d", queue_pos);
 		rc = zk_set(zh, path, (char *)ev, len, -1);
-		dprintf("update path:%s, queue_pos:%d, len:%d, rc:%d\n", path, queue_pos, len, rc);
+		dprintf("update path:%s, queue_pos:%d, len:%d, rc:%d\n",
+				path, queue_pos, len, rc);
 		if (rc != ZOK)
 			panic("failed to zk_set path:%s, rc:%d\n", path, rc);
 
@@ -282,7 +285,9 @@ static int zk_queue_pop(zhandle_t *zh, struct zk_event *ev)
 	/* process leave event */
 	if (__sync_add_and_fetch(&nr_zk_levents, 0)) {
 		dprintf("found a leave event.\n");
-		dprintf("nr_zk_levents:%d, head:%u\n", __sync_sub_and_fetch(&nr_zk_levents, 1) + 1, zk_levent_head);
+		dprintf("nr_zk_levents:%d, head:%u\n",
+				__sync_sub_and_fetch(&nr_zk_levents, 1) + 1,
+				zk_levent_head);
 
 		lev = &zk_levents[zk_levent_head%SD_MAX_NODES];
 
@@ -291,14 +296,18 @@ static int zk_queue_pop(zhandle_t *zh, struct zk_event *ev)
 		len = sizeof(*ev);
 		sprintf(path, QUEUE_ZNODE "/%010d", queue_pos);
 		rc = zk_get(zh, path, 1, (char *)ev, &len, NULL);
-		if (rc == ZOK && node_cmp(&ev->sender.node, &lev->sender.node) == 0 && ev->blocked) {
-			dprintf("this queue_pos:%d have blocked whole cluster, ignore it\n", queue_pos);
+		if (rc == ZOK
+		    && node_cmp(&ev->sender.node, &lev->sender.node) == 0
+		    && ev->blocked) {
+			dprintf("this queue_pos:%d have blocked whole cluster" \
+				", ignore it\n", queue_pos);
 			queue_pos++;
 
 			/* watch next data */
 			sprintf(path, QUEUE_ZNODE "/%010d", queue_pos);
 			rc = zk_exists(zh, path, 1, NULL);
-			dprintf("watch path:%s, exists:%d\n", path, (rc==ZOK));
+			dprintf("watch path:%s, exists:%d\n",
+					path, (rc == ZOK));
 			if (rc == ZOK) {
 				/* we lost this message, manual notify */
 				dprintf("write event to efd:%d\n", efd);
@@ -309,7 +318,7 @@ static int zk_queue_pop(zhandle_t *zh, struct zk_event *ev)
 		memcpy(ev, lev, sizeof(*ev));
 		zk_levent_head++;
 
-		if (__sync_add_and_fetch(&nr_zk_levents, 0) || rc==ZOK) {
+		if (__sync_add_and_fetch(&nr_zk_levents, 0) || rc == ZOK) {
 			/* we have pending leave events
 			 * or queue nodes, manual notify */
 			dprintf("write event to efd:%d\n", efd);
@@ -325,7 +334,8 @@ static int zk_queue_pop(zhandle_t *zh, struct zk_event *ev)
 	len = sizeof(*ev);
 	sprintf(path, QUEUE_ZNODE "/%010d", queue_pos);
 	rc = zk_get(zh, path, 1, (char *)ev, &len, NULL);
-	dprintf("read path:%s, nr_nodes:%ld, type:%d, len:%d, rc:%d\n", path, nr_zk_nodes, ev->type, len, rc);
+	dprintf("read path:%s, nr_nodes:%ld, type:%d, len:%d, rc:%d\n",
+			path, nr_zk_nodes, ev->type, len, rc);
 	if (rc != ZOK)
 		panic("failed to zk_set path:%s, rc:%d\n", path, rc);
 
@@ -340,7 +350,7 @@ static int zk_queue_pop(zhandle_t *zh, struct zk_event *ev)
 	/* watch next data */
 	sprintf(path, QUEUE_ZNODE "/%010d", queue_pos);
 	rc = zk_exists(zh, path, 1, NULL);
-	dprintf("watch path:%s, exists:%d\n", path, (rc==ZOK));
+	dprintf("watch path:%s, exists:%d\n", path, (rc == ZOK));
 	if (rc == ZOK) {
 		/* we lost this message, manual notify */
 		dprintf("write event to efd:%d\n", efd);
@@ -349,9 +359,8 @@ static int zk_queue_pop(zhandle_t *zh, struct zk_event *ev)
 
 out:
 	/* ignore LEAVE event */
-	if (ev->type == EVENT_LEAVE){
+	if (ev->type == EVENT_LEAVE)
 		return -1;
-	}
 
 	return 0;
 }
@@ -377,7 +386,8 @@ static int is_zk_queue_valid(zhandle_t *zh)
 
 	rc = zk_get_children(zh, MEMBER_ZNODE, 1, &strs);
 	if (rc != ZOK)
-		panic("failed to zk_get_children path:%s, rc:%d\n", MEMBER_ZNODE, rc);
+		panic("failed to zk_get_children path:%s, rc:%d\n",
+				MEMBER_ZNODE, rc);
 
 	return strs.count;
 }
@@ -394,7 +404,7 @@ static void sort_zk_nodes(struct zk_node *znodes, size_t nr_nodes)
 	if (nr_nodes <= 1)
 		return;
 
-	for (i=0; i<nr_nodes; i++) {
+	for (i = 0; i < nr_nodes; i++) {
 		idxs[i].idx = i;
 		idxs[i].seq = znodes[i].seq;
 		dprintf("zk_nodes[%d], seq:%d, value:%s\n",
@@ -402,12 +412,11 @@ static void sort_zk_nodes(struct zk_node *znodes, size_t nr_nodes)
 	}
 
 	/* sort idxs by seq */
-	for (i=nr_nodes-1; i>0; i--) {
+	for (i = nr_nodes-1; i > 0; i--) {
 		k = i;
-		for (j=i-1; j>=0; j--) {
-			if (idxs[k].seq < idxs[j].seq) {
+		for (j = i-1; j >= 0; j--) {
+			if (idxs[k].seq < idxs[j].seq)
 				k = j;
-			}
 		}
 
 		if (i != k) {
@@ -417,7 +426,7 @@ static void sort_zk_nodes(struct zk_node *znodes, size_t nr_nodes)
 		}
 	}
 
-	for (i=0; i<nr_nodes; i++) {
+	for (i = 0; i < nr_nodes; i++) {
 		N[i] = znodes[idxs[i].idx];
 		dprintf("N[%d], seq:%d, value:%s\n",
 			i, znodes[idxs[i].idx].seq, node_to_str(&N[i].node));
@@ -434,14 +443,14 @@ static void build_node_list(struct zk_node *znodes, size_t nr_nodes,
 		entries[i] = znodes[i].node;
 }
 
-static struct zk_node* find_node(struct zk_node *znodes, int nr_nodes, struct zk_node *znode)
+static struct zk_node *find_node(struct zk_node *znodes, int nr_nodes,
+		struct zk_node *znode)
 {
 	int i;
 
-	for (i=0; i<nr_nodes; i++) {
-		if (node_cmp(&znode->node, &znodes[i].node) == 0) {
+	for (i = 0; i < nr_nodes; i++) {
+		if (node_cmp(&znode->node, &znodes[i].node) == 0)
 			return &znodes[i];
-		}
 	}
 
 	return NULL;
@@ -474,19 +483,21 @@ static void zk_data_init(zhandle_t *zh)
 			len = sizeof(znode);
 			rc = zk_get(zh, path, 1, (char *)&znode, &len, NULL);
 			if (rc == ZOK && znode.joined == 0) {
-				dprintf("wait until znode:%s become joined\n", path);
+				dprintf("wait until znode:%s become joined\n",
+						path);
 				usleep(10000);
 				continue;
 			}
 
-			switch(rc) {
+			switch (rc) {
 			case ZOK:
 				zk_nodes[nr_zk_nodes] = znode;
 				nr_zk_nodes++;
 			case ZNONODE:
 				break;
 			default:
-				panic("failed to zk_get path:%s, rc:%d\n", path, rc);
+				panic("failed to zk_get path:%s, rc:%d\n",
+						path, rc);
 			}
 		}
 	}
@@ -555,7 +566,9 @@ static int add_event(zhandle_t *zh, enum zk_event_type type,
 
 		memcpy(lev, &ev, sizeof(ev));
 
-		dprintf("nr_zk_levents:%d, tail:%u\n", __sync_add_and_fetch(&nr_zk_levents, 1), zk_levent_tail);
+		dprintf("nr_zk_levents:%d, tail:%u\n",
+				__sync_add_and_fetch(&nr_zk_levents, 1),
+				zk_levent_tail);
 
 		zk_levent_tail++;
 
@@ -576,7 +589,8 @@ out:
 	return 0;
 }
 
-static void watcher(zhandle_t *zh, int type, int state, const char *path, void* ctx)
+static void watcher(zhandle_t *zh, int type, int state, const char *path,
+		void *ctx)
 {
 	eventfd_t value = 1;
 	const clientid_t *cid;
@@ -599,23 +613,25 @@ static void watcher(zhandle_t *zh, int type, int state, const char *path, void*
 		ret = sscanf(path, MEMBER_ZNODE "/%s", str);
 		if (ret == 1) {
 			rc = zk_exists(zh, path, 1, NULL);
-			dprintf("watch path:%s, exists:%d\n", path, (rc==ZOK));
+			dprintf("watch path:%s, exists:%d\n", path,
+					(rc == ZOK));
 		}
 	}
 
 	if (type == ZOO_DELETED_EVENT) {
 		ret = sscanf(path, MEMBER_ZNODE "/%s", str);
-		if (ret != 1) {
+		if (ret != 1)
 			return;
-		}
 		p = strrchr(path, '/');
 		p++;
 
 		/* check the failed node */
-		for (i=0; i<nr_zk_nodes; i++) {
+		for (i = 0; i < nr_zk_nodes; i++) {
 			if (strcmp(p, node_to_str(&zk_nodes[i].node)) == 0) {
-				dprintf("zk_nodes[%d] leave:%s\n", i, node_to_str(&zk_nodes[i].node));
-				add_event(zh, EVENT_LEAVE, &zk_nodes[i], NULL, 0, NULL);
+				dprintf("zk_nodes[%d] leave:%s\n", i,
+						node_to_str(&zk_nodes[i].node));
+				add_event(zh, EVENT_LEAVE, &zk_nodes[i],
+						NULL, 0, NULL);
 				return;
 			}
 		}
@@ -683,8 +699,10 @@ static int zk_init(struct cdrv_handlers *handlers, const char *option,
 {
 	zk_hdlrs = *handlers;
 	if (!option) {
-		eprintf("specify comma separated host:port pairs, each corresponding to a zk server.\n");
-		eprintf("e.g. sheep /store -c zookeeper:127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002\n");
+		eprintf("specify comma separated host:port pairs," \
+				" each corresponding to a zk server.\n");
+		eprintf("e.g. sheep /store -c zookeeper:127.0.0.1:3000," \
+				"127.0.0.1:3001,127.0.0.1:3002\n");
 		return -1;
 	}
 
@@ -697,7 +715,7 @@ static int zk_init(struct cdrv_handlers *handlers, const char *option,
 		eprintf("failed to connect to zk server %s\n", option);
 		return -1;
 	}
-	dprintf("request session timeout:%dms, negotiated session timeout:%dms\n",
+	dprintf("request session timeout:%dms, negotiated timeout:%dms\n",
 			SESSION_TIMEOUT, zoo_recv_timeout(zhandle));
 
 	if (get_addr(myaddr) < 0)
@@ -738,14 +756,18 @@ static int zk_join(struct sd_node *myself,
 	/* try to recover previous session */
 	znode = find_node(zk_nodes, nr_zk_nodes, &this_node);
 	if (znode) {
-		zh = zookeeper_init(zk_option, watcher, SESSION_TIMEOUT, &znode->clientid, NULL, 0);
+		zh = zookeeper_init(zk_option, watcher, SESSION_TIMEOUT,
+				&znode->clientid, NULL, 0);
 		if (zh) {
-			dprintf("recover previous session successfully! this_seq:%d, clientid:%ld\n", znode->seq, znode->clientid.client_id);
+			dprintf("recover previous session successfully!" \
+					" this_seq:%d, clientid:%ld\n",
+					znode->seq, znode->clientid.client_id);
 			this_node = *znode;
 			zk_unlock(zhandle);
 			do {
 				rc = zookeeper_close(zhandle);
-			}while(rc == ZCONNECTIONLOSS || rc == ZOPERATIONTIMEOUT);
+			} while (rc == ZCONNECTIONLOSS
+				|| rc == ZOPERATIONTIMEOUT);
 			zhandle = zh;
 			return 0;
 		}
@@ -767,7 +789,8 @@ static int zk_join(struct sd_node *myself,
 	if (rc != ZOK)
 		panic("failed to create an ephemeral znode, rc:%d\n", rc);
 
-	rc = add_event(zhandle, EVENT_JOIN, &this_node, opaque, opaque_len, NULL);
+	rc = add_event(zhandle, EVENT_JOIN, &this_node,
+			opaque, opaque_len, NULL);
 
 	zk_unlock(zhandle);
 
@@ -781,7 +804,8 @@ static int zk_leave(void)
 
 static int zk_notify(void *msg, size_t msg_len, void (*block_cb)(void *arg))
 {
-	return add_event(zhandle, EVENT_NOTIFY, &this_node, msg, msg_len, block_cb);
+	return add_event(zhandle, EVENT_NOTIFY, &this_node,
+			msg, msg_len, block_cb);
 }
 
 static void zk_block(struct work *work)
@@ -828,9 +852,8 @@ static int zk_dispatch(void)
 	if (ret < 0)
 		return 0;
 
-	if (__sync_add_and_fetch(&zk_notify_blocked, 0)) {
+	if (__sync_add_and_fetch(&zk_notify_blocked, 0))
 		return 0;
-	}
 
 	ret = zk_queue_pop(zhandle, &ev);
 	if (ret < 0)
@@ -840,8 +863,11 @@ static int zk_dispatch(void)
 	case EVENT_JOIN:
 		dprintf("JOIN EVENT, blocked:%d\n", ev.blocked);
 		if (ev.blocked) {
-			dprintf("one sheep joined[up], nr_nodes:%ld, sender:%s, joined:%d\n",
-					nr_zk_nodes, node_to_str(&ev.sender.node), ev.sender.joined);
+			dprintf("one sheep joined[up], nr_nodes:%ld," \
+					" sender:%s, joined:%d\n",
+					nr_zk_nodes,
+					node_to_str(&ev.sender.node),
+					ev.sender.joined);
 			if (is_master(&this_node) >= 0) {
 				res = zk_check_join_cb(&ev.sender.node, ev.buf);
 				ev.join_result = res;
@@ -849,23 +875,30 @@ static int zk_dispatch(void)
 				ev.sender.joined = 1;
 
 				len = sizeof(znode);
-				sprintf(path, MEMBER_ZNODE "/%s", node_to_str(&ev.sender.node));
-				rc = zk_get(zhandle, path, 0, (char *)&znode, &len, NULL);
+				sprintf(path, MEMBER_ZNODE "/%s",
+						node_to_str(&ev.sender.node));
+				rc = zk_get(zhandle, path, 0, (char *)&znode,
+						&len, NULL);
 				if (rc != ZOK)
-					panic("failed to zk_get path:%s, rc:%d\n", path, rc);
+					panic("failed to zk_get path:%s, rc:%d\n",
+							path, rc);
 
-				/* update joined state in zookeeper MEMBER_ZNODE list*/
+				/* update joined state in zookeeper
+				 * MEMBER_ZNODE list*/
 				znode.joined = 1;
-				rc = zk_set(zhandle, path, (char *)&znode, sizeof(znode), -1);
+				rc = zk_set(zhandle, path, (char *)&znode,
+						sizeof(znode), -1);
 				if (rc != ZOK)
-					panic("failed to zk_set path:%s, rc:%d\n", path, rc);
+					panic("failed to zk_set path:%s, rc:%d\n",
+							path, rc);
 
 				dprintf("I'm master, push back join event\n");
 				zk_queue_push_back(zhandle, &ev);
 
 				if (res == CJ_RES_MASTER_TRANSFER) {
-					eprintf("failed to join sheepdog cluster: "
-						"please retry when master is up\n");
+					eprintf("failed to join sheepdog" \
+						" cluster: please retry" \
+						" when master is up\n");
 					exit(1);
 				}
 			} else
@@ -875,9 +908,8 @@ static int zk_dispatch(void)
 		}
 
 		if (ev.join_result == CJ_RES_MASTER_TRANSFER) {
-			/* FIXME: This code is tricky, but Sheepdog assumes that */
-			/* nr_nodes = 1 when join_result = MASTER_TRANSFER... */
-			//ev.nr_nodes = 1;
+			/* FIXME: This code is tricky, but Sheepdog assumes that
+			 * nr_nodes = 1 when join_result = MASTER_TRANSFER... */
 			nr_zk_nodes = 1;
 			zk_nodes[0] = this_node;
 			zk_nodes[0].joined  = 1;
@@ -887,12 +919,15 @@ static int zk_dispatch(void)
 
 		zk_nodes[nr_zk_nodes] = ev.sender;
 		nr_zk_nodes++;
-		dprintf("one sheep joined[down], nr_nodes:%ld, sender:%s, joined:%d\n",
-				nr_zk_nodes, node_to_str(&ev.sender.node), ev.sender.joined);
+		dprintf("one sheep joined[down], nr_nodes:%ld," \
+				" sender:%s, joined:%d\n",
+				nr_zk_nodes,
+				node_to_str(&ev.sender.node),
+				ev.sender.joined);
 
 		sprintf(path, MEMBER_ZNODE "/%s", node_to_str(&ev.sender.node));
 		rc = zk_exists(zhandle, path, 1, NULL);
-		dprintf("watch path:%s, exists:%d\n", path, (rc==ZOK));
+		dprintf("watch path:%s, exists:%d\n", path, (rc == ZOK));
 
 		build_node_list(zk_nodes, nr_zk_nodes, entries);
 		zk_hdlrs.join_handler(&ev.sender.node, entries, nr_zk_nodes,
@@ -903,7 +938,8 @@ static int zk_dispatch(void)
 		/*reset master if necessary */
 		n = find_node(zk_nodes, nr_zk_nodes, &ev.sender);
 		if (!n) {
-			dprintf("can't find this leave node:%s, ignore it.\n", node_to_str(&ev.sender.node));
+			dprintf("can't find this leave node:%s, ignore it.\n",
+					node_to_str(&ev.sender.node));
 			goto out;
 		}
 
@@ -911,7 +947,8 @@ static int zk_dispatch(void)
 		nr_zk_nodes--;
 
 		memmove(n, n + 1, sizeof(*n) * (nr_zk_nodes - idx));
-		dprintf("one sheep left, nr_nodes:%ld, idx:%d\n", nr_zk_nodes, idx);
+		dprintf("one sheep left, nr_nodes:%ld, idx:%d\n",
+				nr_zk_nodes, idx);
 
 		build_node_list(zk_nodes, nr_zk_nodes, entries);
 		zk_hdlrs.leave_handler(&ev.sender.node, entries, nr_zk_nodes);
@@ -919,7 +956,8 @@ static int zk_dispatch(void)
 	case EVENT_NOTIFY:
 		dprintf("NOTIFY, blocked:%d\n", ev.blocked);
 		if (ev.blocked) {
-			if (node_cmp(&ev.sender.node, &this_node.node) == 0 && !ev.callbacked) {
+			if (node_cmp(&ev.sender.node, &this_node.node) == 0
+					&& !ev.callbacked) {
 				ev.callbacked = 1;
 
 				__sync_add_and_fetch(&zk_notify_blocked, 1);
-- 
1.7.7.6




More information about the sheepdog mailing list