[sheepdog] [PATCH] zookeeper: add more detailed description on how zk_watcher report states
Liu Yuan
namei.unix at gmail.com
Wed Feb 11 11:42:16 CET 2015
From: Liu Yuan <liuyuan at cmss.chinamobile.com>
Signed-off-by: Liu Yuan <liuyuan at cmss.chinamobile.com>
---
sheep/cluster/zookeeper.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index b603d36..e2ee248 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -685,6 +685,27 @@ static int add_event(enum zk_event_type type, struct zk_node *znode, void *buf,
}
}
+/*
+ * Type value:
+ * -1 SESSION_EVENT, use State to indicate what kind of sub-event
+ * State value:
+ * -122 SESSION EXPIRED
+ * 1 CONNECTING
+ * 3 CONNECTED
+ * 1 CREATED_EVENT
+ * 2 DELETED_EVENT
+ * 3 CHANGED_EVENT
+ * 4 CHILD_EVENT
+ *
+ * While connection to zk is disconnected (zk cluster in election, network is
+ * broken, etc.), zk library will try to reconnect zk cluster on its own and
+ * report both the connection state and session state to sheep via zk_watcher.
+ *
+ * Once the connection is reestablished (state changed from 1 to 3)within the
+ * timeout window, the session is still valid, meaning that all the watchers
+ * will function as before. If not within the timeout window, zk_watcher will
+ * report to sheep that session is expired.
+ */
static void zk_watcher(zhandle_t *zh, int type, int state, const char *path,
void *ctx)
{
@@ -693,6 +714,8 @@ static void zk_watcher(zhandle_t *zh, int type, int state, const char *path,
uint64_t lock_id;
int ret;
+ sd_debug("path:%s, type:%d, state:%d", path, type, state);
+
if (type == ZOO_SESSION_EVENT && state == ZOO_EXPIRED_SESSION_STATE) {
/*
* do reconnect in main thread to avoid on-the-fly zookeeper
@@ -702,8 +725,6 @@ static void zk_watcher(zhandle_t *zh, int type, int state, const char *path,
return;
}
-/* CREATED_EVENT 1, DELETED_EVENT 2, CHANGED_EVENT 3, CHILD_EVENT 4 */
- sd_debug("path:%s, type:%d, state:%d", path, type, state);
if (type == ZOO_CREATED_EVENT || type == ZOO_CHANGED_EVENT) {
ret = sscanf(path, MEMBER_ZNODE "/%s", str);
if (ret == 1)
--
1.9.1
More information about the sheepdog
mailing list