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 | 9 +++++++++ sheep/group.c | 8 ++++++++ sheep/sheep_priv.h | 1 + 3 files changed, 18 insertions(+), 0 deletions(-) diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c index 19b8945..7912cb7 100644 --- a/sheep/farm/farm.c +++ b/sheep/farm/farm.c @@ -695,6 +695,14 @@ static int farm_format(struct siocb *iocb) return SD_RES_SUCCESS; } +static int farm_purge_obj(void) +{ + if (cleanup_working_dir() < 0) + return SD_RES_EIO; + + return SD_RES_SUCCESS; +} + struct store_driver farm = { .name = "farm", .init = farm_init, @@ -711,6 +719,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 |