aboutsummaryrefslogtreecommitdiff
path: root/src/include/access/xlog_internal.h
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:36:18 +0900
commit163e29dc380137127cf7e9c23b1596b78ad0ce81 (patch)
tree584dfda34f9d7d23dab4f3074fe7c08fefd016a6 /src/include/access/xlog_internal.h
parentcd7030ff085f5c378e837b392cb719cf23df9d0b (diff)
downloadpostgresql-163e29dc380137127cf7e9c23b1596b78ad0ce81.tar.gz
postgresql-163e29dc380137127cf7e9c23b1596b78ad0ce81.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/include/access/xlog_internal.h')
-rw-r--r--src/include/access/xlog_internal.h19
1 files changed, 13 insertions, 6 deletions
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) \