[sheepdog] [PATCH v2 3/3] journal: clean journal files when sheep exits correctly

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Wed Apr 10 10:25:12 CEST 2013


From: Hitoshi Mitake <mitake.hitoshi at gmail.com>

Journal files don't have to exist if an owner sheep exits correctly.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---

v2: sync() before unlink() journal files

 sheep/journal.c    |   18 ++++++++++++++++++
 sheep/sheep.c      |    6 ++++++
 sheep/sheep_priv.h |    1 +
 3 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/sheep/journal.c b/sheep/journal.c
index 59608ac..f7577ec 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -283,6 +283,24 @@ int journal_file_init(const char *path, size_t size, bool skip)
 	return 0;
 }
 
+void clean_journal_file(const char *p)
+{
+	int ret;
+	char path[PATH_MAX];
+
+	sync();
+
+	snprintf(path, sizeof(path), "%s/%s", p, jfile_name[0]);
+	ret = unlink(path);
+	if (ret < 0)
+		sd_eprintf("unlink(%s): %m", path);
+
+	snprintf(path, sizeof(path), "%s/%s", p, jfile_name[1]);
+	ret = unlink(path);
+	if (ret < 0)
+		sd_eprintf("unlink(%s): %m", path);
+}
+
 static inline bool jfile_enough_space(size_t size)
 {
 	if (jfile.pos + size > jfile_size)
diff --git a/sheep/sheep.c b/sheep/sheep.c
index cda8493..61abd1a 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -691,6 +691,12 @@ int main(int argc, char **argv)
 	sd_printf(SDOG_INFO, "shutdown");
 
 	leave_cluster();
+
+	if (uatomic_is_true(&sys->use_journal)) {
+		sd_iprintf("cleaning journal file");
+		clean_journal_file(jpath);
+	}
+
 	log_close();
 
 	if (pid_file)
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index d1022ac..a447387 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -402,6 +402,7 @@ bool sheep_need_retry(uint32_t epoch);
 
 /* journal_file.c */
 int journal_file_init(const char *path, size_t size, bool skip);
+void clean_journal_file(const char *p);
 int
 journal_write_store(uint64_t oid, const char *buf, size_t size, off_t, bool);
 int journal_write_epoch(const char *buf, size_t size, uint32_t epoch);
-- 
1.7.2.5




More information about the sheepdog mailing list