aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2015-07-02 10:35:38 +0900
committerFujii Masao <fujii@postgresql.org>2015-07-02 10:35:38 +0900
commitfb174687f7a730edcf301949785a6ac0dbfd70d0 (patch)
treeaeacb3bcf839aefba61500c8fee43e6fb38627a0 /src
parent1e24cf645d24aab3ea39a9d259897fd0cae4e4b6 (diff)
downloadpostgresql-fb174687f7a730edcf301949785a6ac0dbfd70d0.tar.gz
postgresql-fb174687f7a730edcf301949785a6ac0dbfd70d0.zip
Make use of xlog_internal.h's macros in WAL-related utilities.
Commit 179cdd09 added macros to check if a filename is a WAL segment or other such file. However there were still some instances of the strlen + strspn combination to check for that in WAL-related utilities like pg_archivecleanup. Those checks can be replaced with the macros. This patch makes use of the macros in those utilities and which would make the code a bit easier to read. Back-patch to 9.5. Michael Paquier
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_archivecleanup/pg_archivecleanup.c22
-rw-r--r--src/bin/pg_resetxlog/pg_resetxlog.c11
-rw-r--r--src/include/access/xlog_internal.h19
3 files changed, 26 insertions, 26 deletions
diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c b/src/bin/pg_archivecleanup/pg_archivecleanup.c
index ba6e242f155..579a9bb8430 100644
--- a/src/bin/pg_archivecleanup/pg_archivecleanup.c
+++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c
@@ -21,6 +21,8 @@
#include "pg_getopt.h"
+#include "access/xlog_internal.h"
+
const char *progname;
/* Options and defaults */
@@ -31,7 +33,7 @@ char *additional_ext = NULL; /* Extension to remove from filenames */
char *archiveLocation; /* where to find the archive? */
char *restartWALFileName; /* the file from which we can restart restore */
char WALFilePath[MAXPGPATH]; /* the file path including archive */
-char exclusiveCleanupFileName[MAXPGPATH]; /* the oldest file we
+char exclusiveCleanupFileName[MAXFNAMELEN]; /* the oldest file we
* want to remain in
* archive */
@@ -51,12 +53,6 @@ char exclusiveCleanupFileName[MAXPGPATH]; /* the oldest file we
* folded in to later versions of this program.
*/
-#define XLOG_DATA_FNAME_LEN 24
-/* Reworked from access/xlog_internal.h */
-#define XLogFileName(fname, tli, log, seg) \
- snprintf(fname, XLOG_DATA_FNAME_LEN + 1, "%08X%08X%08X", tli, log, seg)
-#define XLOG_BACKUP_FNAME_LEN 40
-
/*
* Initialize allows customized commands into the archive cleanup program.
*
@@ -110,7 +106,7 @@ CleanupPriorWALFiles(void)
{
/*
* Truncation is essentially harmless, because we skip names of
- * length other than XLOG_DATA_FNAME_LEN. (In principle, one
+ * length other than XLOG_FNAME_LEN. (In principle, one
* could use a 1000-character additional_ext and get trouble.)
*/
strlcpy(walfile, xlde->d_name, MAXPGPATH);
@@ -129,8 +125,7 @@ CleanupPriorWALFiles(void)
* file. Note that this means files are not removed in the order
* they were originally written, in case this worries you.
*/
- if (strlen(walfile) == XLOG_DATA_FNAME_LEN &&
- strspn(walfile, "0123456789ABCDEF") == XLOG_DATA_FNAME_LEN &&
+ if (IsXLogFileName(walfile) &&
strcmp(walfile + 8, exclusiveCleanupFileName + 8) < 0)
{
/*
@@ -202,13 +197,12 @@ SetWALFileNameForCleanup(void)
* 000000010000000000000010.00000020.backup is after
* 000000010000000000000010.
*/
- if (strlen(restartWALFileName) == XLOG_DATA_FNAME_LEN &&
- strspn(restartWALFileName, "0123456789ABCDEF") == XLOG_DATA_FNAME_LEN)
+ if (IsXLogFileName(restartWALFileName))
{
strcpy(exclusiveCleanupFileName, restartWALFileName);
fnameOK = true;
}
- else if (strlen(restartWALFileName) == XLOG_BACKUP_FNAME_LEN)
+ else if (IsBackupHistoryFileName(restartWALFileName))
{
int args;
uint32 tli = 1,
@@ -225,7 +219,7 @@ SetWALFileNameForCleanup(void)
* Use just the prefix of the filename, ignore everything after
* first period
*/
- XLogFileName(exclusiveCleanupFileName, tli, log, seg);
+ XLogFileNameById(exclusiveCleanupFileName, tli, log, seg);
}
}
diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c
index 6ffe795348d..e19a72b4c16 100644
--- a/src/bin/pg_resetxlog/pg_resetxlog.c
+++ b/src/bin/pg_resetxlog/pg_resetxlog.c
@@ -261,7 +261,7 @@ main(int argc, char *argv[])
break;
case 'l':
- if (strspn(optarg, "01234567890ABCDEFabcdef") != 24)
+ if (strspn(optarg, "01234567890ABCDEFabcdef") != XLOG_FNAME_LEN)
{
fprintf(stderr, _("%s: invalid argument for option %s\n"), progname, "-l");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
@@ -976,8 +976,7 @@ KillExistingXLOG(void)
while (errno = 0, (xlde = readdir(xldir)) != NULL)
{
- if (strlen(xlde->d_name) == 24 &&
- strspn(xlde->d_name, "0123456789ABCDEF") == 24)
+ if (IsXLogFileName(xlde->d_name))
{
snprintf(path, MAXPGPATH, "%s/%s", XLOGDIR, xlde->d_name);
if (unlink(path) < 0)
@@ -1027,9 +1026,9 @@ KillExistingArchiveStatus(void)
while (errno = 0, (xlde = readdir(xldir)) != NULL)
{
- if (strspn(xlde->d_name, "0123456789ABCDEF") == 24 &&
- (strcmp(xlde->d_name + 24, ".ready") == 0 ||
- strcmp(xlde->d_name + 24, ".done") == 0))
+ if (strspn(xlde->d_name, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
+ (strcmp(xlde->d_name + XLOG_FNAME_LEN, ".ready") == 0 ||
+ strcmp(xlde->d_name + XLOG_FNAME_LEN, ".done") == 0))
{
snprintf(path, MAXPGPATH, "%s/%s", ARCHSTATDIR, xlde->d_name);
if (unlink(path) < 0)
diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h
index fbf9324ba43..5ebaa5f69c6 100644
--- a/src/include/access/xlog_internal.h
+++ b/src/include/access/xlog_internal.h
@@ -137,13 +137,20 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
*/
#define MAXFNAMELEN 64
+/* Length of XLog file name */
+#define XLOG_FNAME_LEN 24
+
#define XLogFileName(fname, tli, logSegNo) \
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, \
(uint32) ((logSegNo) / XLogSegmentsPerXLogId), \
(uint32) ((logSegNo) % XLogSegmentsPerXLogId))
+#define XLogFileNameById(fname, tli, log, seg) \
+ snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)
+
#define IsXLogFileName(fname) \
- (strlen(fname) == 24 && strspn(fname, "0123456789ABCDEF") == 24)
+ (strlen(fname) == XLOG_FNAME_LEN && \
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN)
/*
* XLOG segment with .partial suffix. Used by pg_receivexlog and at end of
@@ -151,9 +158,9 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
* be complete yet.
*/
#define IsPartialXLogFileName(fname) \
- (strlen(fname) == 24 + strlen(".partial") && \
- strspn(fname, "0123456789ABCDEF") == 24 && \
- strcmp((fname) + 24, ".partial") == 0)
+ (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") && \
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
+ strcmp((fname) + XLOG_FNAME_LEN, ".partial") == 0)
#define XLogFromFileName(fname, tli, logSegNo) \
do { \
@@ -188,8 +195,8 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
(uint32) ((logSegNo) % XLogSegmentsPerXLogId), offset)
#define IsBackupHistoryFileName(fname) \
- (strlen(fname) > 24 && \
- strspn(fname, "0123456789ABCDEF") == 24 && \
+ (strlen(fname) > XLOG_FNAME_LEN && \
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
strcmp((fname) + strlen(fname) - strlen(".backup"), ".backup") == 0)
#define BackupHistoryFilePath(path, tli, logSegNo, offset) \