From: Liu Yuan <
liu...@cmss.chinamobile.com>
Also write some comments for why we are busy waiting at 'join' event.
Signed-off-by: Liu Yuan <
liu...@cmss.chinamobile.com>
---
sheep/cluster/zookeeper.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 6bf2680..ad562f4 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -1069,7 +1069,17 @@ static void zk_handle_join(struct zk_event *ev)
{
sd_debug("sender: %s", node_to_str(&ev->sender.node));
if (!uatomic_is_true(&is_master)) {
- /* Let's await master acking the join-request */
+ /*
+ * Let's await master acking the join-request
+ *
+ * zk_queue_peek(next) will peek the 'join' event and
+ * will be busy popping out zk_handle_join() to wait for the
+ * master node to rewrite 'join' event as 'accept' event.
+ * We have to do busy waiting because the master might die
+ * before pushing 'acccept' event. Someone else should take the
+ * role over the dead to ack the join-request.
+ */
+ usleep(200000); /* Reduce reads from zk */
queue_pos--;
return;
}
--
1.9.1