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

Hitoshi Mitake mitake.hitoshi at gmail.com
Sun Apr 14 17:54:18 CEST 2013


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>
---
v3: remove the obsolete comment

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

diff --git a/sheep/journal.c b/sheep/journal.c
index 92a005e..be1a6b7 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -248,8 +248,6 @@ skip:
 }
 
 /*
- * FIXME: clear jfile at shutdown command.
- *
  * We recover the journal file in order of wall time in the corner case that
  * sheep crashes while in the middle of journal committing. For most of cases,
  * we actually only recover one jfile, the other would be empty. This process
@@ -293,6 +291,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 9e6de4d..7990893 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -706,6 +706,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.5.1




More information about the sheepdog mailing list