[sheepdog] [PATCH] farm: remove stale objects for crashed sheep when it comes back

Liu Yuan namei.unix at gmail.com
Sat May 19 12:06:09 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

During the window the crashed sheep restarts, the objects might be updated.
So we need to purge store/obj directory to assure consistency.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/farm/farm.c  |   16 ++++++++++++++++
 sheep/group.c      |    8 ++++++++
 sheep/sheep_priv.h |    1 +
 3 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c
index 19b8945..027b36a 100644
--- a/sheep/farm/farm.c
+++ b/sheep/farm/farm.c
@@ -695,6 +695,21 @@ static int farm_format(struct siocb *iocb)
 	return SD_RES_SUCCESS;
 }
 
+static int farm_purge_obj(void)
+{
+	char path[PATH_MAX];
+	int ret = SD_RES_SUCCESS;
+
+	dprintf("try to purge obj\n");
+	sprintf(path, "%s", obj_path);
+	ret = rmdir_r(path);
+	if (ret && ret != -ENOENT) {
+		eprintf("failed to purge obj %m\n");
+		return SD_RES_EIO;
+	}
+	return ret;
+}
+
 struct store_driver farm = {
 	.name = "farm",
 	.init = farm_init,
@@ -711,6 +726,7 @@ struct store_driver farm = {
 	.restore = farm_restore,
 	.get_snap_file = farm_get_snap_file,
 	.format = farm_format,
+	.purge_obj = farm_purge_obj,
 };
 
 add_store_driver(farm);
diff --git a/sheep/group.c b/sheep/group.c
index 7c5c8f5..ae6e335 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -643,6 +643,14 @@ static void finish_join(struct join_message *msg, struct sd_node *joined,
 		} else
 				panic("backend store %s not supported\n", msg->store);
 	}
+
+	/* We need to purge the stale objects for sheep joining back
+	 * after crash
+	 */
+	if (msg->inc_epoch)
+		if (sd_store->purge_obj &&
+		    sd_store->purge_obj() != SD_RES_SUCCESS)
+			eprintf("WARN: may have stale objects\n");
 }
 
 static void update_cluster_info(struct join_message *msg,
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 157bb45..6f6a320 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -178,6 +178,7 @@ struct store_driver {
 	int (*atomic_put)(uint64_t oid, struct siocb *);
 	int (*begin_recover)(struct siocb *);
 	int (*end_recover)(struct siocb *);
+	int (*purge_obj)(void);
 	/* Operations for snapshot */
 	int (*snapshot)(struct siocb *);
 	int (*cleanup)(struct siocb *);
-- 
1.7.8.2




More information about the sheepdog mailing list