[Sheepdog] [zookeeper][PATCH v2 06/11] Rewatch znode in /sheepdog/member after it changed

Yunkai Zhang yunkai.me at gmail.com
Thu Apr 26 17:21:25 CEST 2012


From: Yunkai Zhang <qiushu.zyk at taobao.com>

If we not rewatch znode in /sheepdog/member after it changed, we
will lose all events of it in the future, such as DELETE event.

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

diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 9d88f1d..e391bd1 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -585,7 +585,7 @@ static void watcher(zhandle_t *zh, int type, int state, const char *path, void*
 	eventfd_t value = 1;
 	const clientid_t *cid;
 	char str[256], *p;
-	int ret, i;
+	int ret, rc, i;
 
 	dprintf("path:%s, type:%d\n", path, type);
 
@@ -599,6 +599,14 @@ static void watcher(zhandle_t *zh, int type, int state, const char *path, void*
 	if (type < 0 || type == ZOO_CHILD_EVENT)
 		return;
 
+	if (type == ZOO_CHANGED_EVENT) {
+		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));
+		}
+	}
+
 	if (type == ZOO_DELETED_EVENT) {
 		ret = sscanf(path, MEMBER_ZNODE "/%s", str);
 		if (ret != 1) {
-- 
1.7.7.6




More information about the sheepdog mailing list