[sheepdog] [PATCH] zk: delete zk node before join cluster

Kai Zhang kyle at zelin.io
Thu May 30 08:37:53 CEST 2013


Delete zk node before join cluster and return -1 when fail.

Signed-off-by: Kai Zhang <kyle at zelin.io>
---
 sheep/cluster/zookeeper.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 5f5e867..d82a486 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -497,10 +497,11 @@ static int zk_join(const struct sd_node *myself,
 	this_node.node = *myself;
 
 	snprintf(path, sizeof(path), MEMBER_ZNODE "/%s", node_to_str(myself));
-	rc = zk_node_exists(path);
-	if (rc == ZOK) {
-		sd_eprintf("Previous zookeeper session exist, shoot myself.");
-		exit(1);
+	rc = zk_delete_node(path, -1);
+	if (rc != ZOK && rc != ZNONODE) {
+		sd_eprintf("failed to delete previous zookeeper path"
+			   " before join cluster");
+		return -1;
 	}
 
 	/* For concurrent nodes setup, we allow only one to continue */
-- 
1.7.1




More information about the sheepdog mailing list