At Wed, 11 Feb 2015 18:42:16 +0800,
Liu Yuan wrote:
> 
> From: Liu Yuan <liuy...@cmss.chinamobile.com>
> 
> Signed-off-by: Liu Yuan <liuy...@cmss.chinamobile.com>
> ---
>  sheep/cluster/zookeeper.c | 25 +++++++++++++++++++++++--
>  1 file changed, 23 insertions(+), 2 deletions(-)

Cc-ing Ruoyu. If he cannot allocate time for review, I'll do it later.

Thanks,
Hitoshi

> 
> 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
> 
> -- 
> sheepdog mailing list
> sheepdog@lists.wpkg.org
> https://lists.wpkg.org/mailman/listinfo/sheepdog
-- 
sheepdog mailing list
sheepdog@lists.wpkg.org
https://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to