[sheepdog] [PATCH] zk: use panic instead of assert for code logic

Liu Yuan namei.unix at gmail.com
Wed May 29 07:57:34 CEST 2013


If NDEBUG is defined, the code in assert() won't be called at all.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/cluster/zookeeper.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 1cd39f7..e2d5cea 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -189,7 +189,7 @@ zk_create_seq_node(const char *path, const char *value, int valuelen,
 		panic("failed, path:%s, %s", path, zerror(rc));
 }
 
-static inline ZOOAPI int zk_get_data(const char *path, void *buffer,
+static inline ZOOAPI void zk_get_data(const char *path, void *buffer,
 				     int *buffer_len)
 {
 	int rc;
@@ -197,9 +197,8 @@ static inline ZOOAPI int zk_get_data(const char *path, void *buffer,
 		rc = zoo_get(zhandle, path, 1, (char *)buffer,
 			     buffer_len, NULL);
 		if (rc != ZOK)
-			sd_eprintf("failed, path:%s, %s", path, zerror(rc));
+			panic("failed, path:%s, %s", path, zerror(rc));
 	} while (rc == ZOPERATIONTIMEOUT || rc == ZCONNECTIONLOSS);
-	return rc;
 }
 
 static inline ZOOAPI int
@@ -308,7 +307,7 @@ static void zk_queue_pop_advance(struct zk_event *ev)
 
 	len = sizeof(*ev);
 	snprintf(path, sizeof(path), QUEUE_ZNODE "/%010"PRId32, queue_pos);
-	assert(zk_get_data(path, ev, &len) == ZOK);
+	zk_get_data(path, ev, &len);
 	sd_dprintf("%s, type:%d, len:%d, pos:%"PRId32, path, ev->type, len,
 		   queue_pos);
 	queue_pos++;
@@ -475,7 +474,8 @@ static int add_join_event(void *msg, size_t msg_len)
 	struct zk_event ev;
 	size_t len = msg_len + sizeof(struct sd_node) * SD_MAX_NODES;
 
-	assert(len <= SD_MAX_EVENT_BUF_SIZE);
+	if (len > SD_MAX_EVENT_BUF_SIZE);
+		panic("message length too big");
 	ev.type = EVENT_JOIN_REQUEST;
 	ev.sender = this_node;
 	ev.msg_len = msg_len;
-- 
1.7.9.5




More information about the sheepdog mailing list