[sheepdog] [PATCH 2/2] sheep: save backend store name even if the node is gateway

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Mon Mar 11 06:47:30 CET 2013


A gateway node also has to save the store name to the config file to
notify the name to all the nodes when it becomes master.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/group.c      | 56 ++++++++++++++++++++++++++++++++++++------------------
 sheep/sheep.c      |  8 +++-----
 sheep/sheep_priv.h |  2 +-
 sheep/store.c      |  7 ++++++-
 4 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index c2070b4..c646101 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -723,38 +723,58 @@ static struct vnode_info *alloc_old_vnode_info(const struct sd_node *joined,
 	return alloc_vnode_info(old_nodes, count);
 }
 
+static void setup_backend_store(const char *store, bool need_purge)
+{
+	int ret;
+
+	if (!sd_store) {
+		sd_store = find_store_driver(store);
+		if (!sd_store)
+			panic("backend store %s not supported", store);
+
+		ret = sd_store->init(obj_path);
+		if (ret != SD_RES_SUCCESS)
+			panic("failed to initialize store");
+
+		ret = set_cluster_store(sd_store->name);
+		if (ret != SD_RES_SUCCESS)
+			panic("failed to store into config file");
+	}
+
+	/* We need to purge the stale objects for sheep joining back
+	 * after crash */
+	if (need_purge && sd_store->purge_obj) {
+		ret = sd_store->purge_obj();
+		if (ret != SD_RES_SUCCESS)
+			panic("can't remove stale objects");
+	}
+}
+
 static void finish_join(const struct join_message *msg,
 			const struct sd_node *joined,
 			const struct sd_node *nodes, size_t nr_nodes)
 {
+	int ret;
+
 	sys->join_finished = true;
 	sys->epoch = msg->epoch;
 
 	if (msg->cluster_status != SD_STATUS_OK)
 		update_exceptional_node_list(get_latest_epoch(), msg);
 
-	/* We don't need backend for gateway-only node */
-	if (!sys->gateway_only && !sd_store && strlen((char *)msg->store)) {
-		sd_store = find_store_driver((char *)msg->store);
-		if (sd_store) {
-			if (sd_store->init(obj_path) != SD_RES_SUCCESS)
-				panic("failed to initialize store");
-			if (set_cluster_store(sd_store->name) != SD_RES_SUCCESS)
+	if (msg->store[0]) {
+		/* We don't need backend for gateway-only node, but need to save
+		 * store name.  Otherwise, the node cannot notify the store name
+		 * when it become master */
+		if (sys->gateway_only) {
+			ret = set_cluster_store((char *)msg->store);
+			if (ret != SD_RES_SUCCESS)
 				panic("failed to store into config file");
 		} else
-				panic("backend store %s not supported",
-				      msg->store);
+			setup_backend_store((char *)msg->store,
+					    !!msg->inc_epoch);
 	}
 
-	/* We need to purge the stale objects for sheep joining back
-	 * after crash
-	 */
-	if (msg->inc_epoch)
-		if (!sys->gateway_only &&
-		    sd_store->purge_obj &&
-		    sd_store->purge_obj() != SD_RES_SUCCESS)
-			panic("can't remove stale objects");
-
 	sockfd_cache_add_group(nodes, nr_nodes);
 }
 
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 38fe350..39fe766 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -641,11 +641,9 @@ int main(int argc, char **argv)
 	if (ret)
 		exit(1);
 
-	if (!sys->gateway_only) {
-		ret = init_store_driver();
-		if (ret)
-			exit(1);
-	}
+	ret = init_store_driver(sys->gateway_only);
+	if (ret)
+		exit(1);
 
 	if (sys->enable_object_cache) {
 		if (!strlen(ocpath))
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index eaa326f..a4d8f03 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -220,7 +220,7 @@ static inline uint32_t sys_epoch(void)
 int create_listen_port(char *bindaddr, int port);
 int init_unix_domain_socket(const char *dir);
 
-int init_store_driver(void);
+int init_store_driver(bool is_gateway);
 int init_global_pathnames(const char *d);
 int init_base_path(const char *dir);
 int init_obj_path(const char *d);
diff --git a/sheep/store.c b/sheep/store.c
index 2a4301a..2e88c0d 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -261,7 +261,9 @@ static int init_jrnl_path(const char *base_path)
 	return 0;
 }
 
-int init_store_driver(void)
+/* if the node is gateway, this function only finds the store driver.
+ * Otherwise, this function initializes the backend store*/
+int init_store_driver(bool is_gateway)
 {
 	char driver_name[STORE_LEN], *p;
 	int ret;
@@ -294,6 +296,9 @@ int init_store_driver(void)
 		return SD_RES_NO_STORE;
 	}
 
+	if (is_gateway)
+		return SD_RES_SUCCESS;
+
 	return sd_store->init(obj_path);
 }
 
-- 
1.8.1.3.566.gaa39828




More information about the sheepdog mailing list