[sheepdog] [PATCH v4 2/5] sheep: rejoin cluster after a zookeeper session timeout

Liu Yuan namei.unix at gmail.com
Tue Jun 18 09:26:19 CEST 2013


On 06/18/2013 02:15 PM, Kai Zhang wrote:
> +	if (zoo_state(zhandle) == ZOO_EXPIRED_SESSION_STATE) {
> +		sd_eprintf("detect a session timeout. reconnecting...");
> +		/* clean memory states */
> +		close(efd);
> +		zk_tree_destroy();
> +		INIT_RB_ROOT(&zk_node_root);
> +		INIT_LIST_HEAD(&zk_block_list);
> +		nr_sd_nodes = 0;
> +		first_push = true;
> +		memset(sd_nodes, 0, sizeof(struct sd_node) * SD_MAX_NODES);
> +
> +		/* call sd_reconnect_handler to reconnect */

This comment is useless, your function name is already self-explained it.

> +		while (sd_reconnect_handler()) {
> +			sd_eprintf("failed to reconnect. sleep and retry...");
> +			sleep(1);
> +		}

Please explain why you need call sd_reconnect_handler() in a loop, in
what case it will fail?

Also, I'd like to use a helper function, for e.g,
  if (zoo_state(zhandle) == ZOO_EXPIRED_SESSION_STATE)
      return handle_session_expired();

Thanks,
Yuan



More information about the sheepdog mailing list