Hi all,
Except if I am missing something, is there any reason why the sequence used
in XLogArchiveCheckDone and XLogArchiveIsBusy to check if a XLOG segment
has been already archived is duplicated? I guess that doing a little bit of
refactoring here would make sense for simplicity, patch is attached.
Regards,
--
Michael
From 9b96e5825f6f6d2cbbc5ddf9c45c6609e6c01fb7 Mon Sep 17 00:00:00 2001
From: Michael Paquier <[email protected]>
Date: Mon, 20 Oct 2014 16:33:26 +0900
Subject: [PATCH] Refactor archive status analysis into a single function
The same code block was used for XLogArchiveIsBusy and XLogArchiveCheckDone
to check the archive status of a given segment...
---
src/backend/access/transam/xlogarchive.c | 50 +++++++++++++++++---------------
src/include/access/xlog_internal.h | 1 +
2 files changed, 27 insertions(+), 24 deletions(-)
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c
index 047efa2..047e8f8 100644
--- a/src/backend/access/transam/xlogarchive.c
+++ b/src/backend/access/transam/xlogarchive.c
@@ -607,12 +607,7 @@ XLogArchiveForceDone(const char *xlog)
}
/*
- * XLogArchiveCheckDone
- *
- * This is called when we are ready to delete or recycle an old XLOG segment
- * file or backup history file. If it is okay to delete it then return true.
- * If it is not time to delete it, make sure a .ready file exists, and return
- * false.
+ * XLogArchiveIsDone
*
* If <XLOG>.done exists, then return true; else if <XLOG>.ready exists,
* then return false; else create <XLOG>.ready and return false.
@@ -621,15 +616,11 @@ XLogArchiveForceDone(const char *xlog)
* create <XLOG>.ready fails, we'll retry during subsequent checkpoints.
*/
bool
-XLogArchiveCheckDone(const char *xlog)
+XLogArchiveIsDone(const char *xlog)
{
char archiveStatusPath[MAXPGPATH];
struct stat stat_buf;
- /* Always deletable if archiving is off */
- if (!XLogArchivingActive())
- return true;
-
/* First check for .done --- this means archiver is done with it */
StatusFilePath(archiveStatusPath, xlog, ".done");
if (stat(archiveStatusPath, &stat_buf) == 0)
@@ -645,6 +636,28 @@ XLogArchiveCheckDone(const char *xlog)
if (stat(archiveStatusPath, &stat_buf) == 0)
return true;
+ return false;
+}
+
+/*
+ * XLogArchiveCheckDone
+ *
+ * This is called when we are ready to delete or recycle an old XLOG segment
+ * file or backup history file. If it is okay to delete it then return true.
+ * If it is not time to delete it, make sure a .ready file exists, and return
+ * false.
+ */
+bool
+XLogArchiveCheckDone(const char *xlog)
+{
+ /* Always deletable if archiving is off */
+ if (!XLogArchivingActive())
+ return true;
+
+ /* Check if segment is marked as .done */
+ if (XLogArchiveIsDone(xlog))
+ return true;
+
/* Retry creation of the .ready file */
XLogArchiveNotify(xlog);
return false;
@@ -666,19 +679,8 @@ XLogArchiveIsBusy(const char *xlog)
char archiveStatusPath[MAXPGPATH];
struct stat stat_buf;
- /* First check for .done --- this means archiver is done with it */
- StatusFilePath(archiveStatusPath, xlog, ".done");
- if (stat(archiveStatusPath, &stat_buf) == 0)
- return false;
-
- /* check for .ready --- this means archiver is still busy with it */
- StatusFilePath(archiveStatusPath, xlog, ".ready");
- if (stat(archiveStatusPath, &stat_buf) == 0)
- return true;
-
- /* Race condition --- maybe archiver just finished, so recheck */
- StatusFilePath(archiveStatusPath, xlog, ".done");
- if (stat(archiveStatusPath, &stat_buf) == 0)
+ /* Check that segment is not yet marked as .done */
+ if (XLogArchiveIsDone(xlog))
return false;
/*
diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h
index 27b9899..6d1a66c 100644
--- a/src/include/access/xlog_internal.h
+++ b/src/include/access/xlog_internal.h
@@ -287,6 +287,7 @@ extern void KeepFileRestoredFromArchive(char *path, char *xlogfname);
extern void XLogArchiveNotify(const char *xlog);
extern void XLogArchiveNotifySeg(XLogSegNo segno);
extern void XLogArchiveForceDone(const char *xlog);
+extern bool XLogArchiveIsDone(const char *xlog);
extern bool XLogArchiveCheckDone(const char *xlog);
extern bool XLogArchiveIsBusy(const char *xlog);
extern void XLogArchiveCleanup(const char *xlog);
--
2.1.2
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers