Convert macros to static inline functions (xlog_internal.h)

Reviewed-by: Amul Sul <sulamul@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/5b558da8-99fb-0a99-83dd-f72f05388517%40enterprisedb.com
This commit is contained in:
Peter Eisentraut 2022-07-15 12:05:01 +02:00
parent 3e9ca52601
commit 507ba16b28
1 changed files with 87 additions and 49 deletions

View File

@ -159,74 +159,112 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
#define XLOG_FNAME_LEN 24 #define XLOG_FNAME_LEN 24
/* /*
* Generate a WAL segment file name. Do not use this macro in a helper * Generate a WAL segment file name. Do not use this function in a helper
* function allocating the result generated. * function allocating the result generated.
*/ */
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes) \ static inline void
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, \ XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \ {
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes))) snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,
(uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
(uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
}
#define XLogFileNameById(fname, tli, log, seg) \ static inline void
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg) XLogFileNameById(char *fname, TimeLineID tli, uint32 log, uint32 seg)
{
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg);
}
#define IsXLogFileName(fname) \ static inline bool
(strlen(fname) == XLOG_FNAME_LEN && \ IsXLogFileName(const char *fname)
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN) {
return (strlen(fname) == XLOG_FNAME_LEN && \
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN);
}
/* /*
* XLOG segment with .partial suffix. Used by pg_receivewal and at end of * XLOG segment with .partial suffix. Used by pg_receivewal and at end of
* archive recovery, when we want to archive a WAL segment but it might not * archive recovery, when we want to archive a WAL segment but it might not
* be complete yet. * be complete yet.
*/ */
#define IsPartialXLogFileName(fname) \ static inline bool
(strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") && \ IsPartialXLogFileName(const char *fname)
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \ {
strcmp((fname) + XLOG_FNAME_LEN, ".partial") == 0) return (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, wal_segsz_bytes) \ static inline void
do { \ XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
uint32 log; \ {
uint32 seg; \ uint32 log;
sscanf(fname, "%08X%08X%08X", tli, &log, &seg); \ uint32 seg;
*logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg; \
} while (0)
#define XLogFilePath(path, tli, logSegNo, wal_segsz_bytes) \ sscanf(fname, "%08X%08X%08X", tli, &log, &seg);
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, \ *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg;
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \ }
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))
#define TLHistoryFileName(fname, tli) \ static inline void
snprintf(fname, MAXFNAMELEN, "%08X.history", tli) XLogFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
{
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli,
(uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
(uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
}
#define IsTLHistoryFileName(fname) \ static inline void
(strlen(fname) == 8 + strlen(".history") && \ TLHistoryFileName(char *fname, TimeLineID tli)
strspn(fname, "0123456789ABCDEF") == 8 && \ {
strcmp((fname) + 8, ".history") == 0) snprintf(fname, MAXFNAMELEN, "%08X.history", tli);
}
#define TLHistoryFilePath(path, tli) \ static inline bool
snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli) IsTLHistoryFileName(const char *fname)
{
return (strlen(fname) == 8 + strlen(".history") &&
strspn(fname, "0123456789ABCDEF") == 8 &&
strcmp(fname + 8, ".history") == 0);
}
#define StatusFilePath(path, xlog, suffix) \ static inline void
snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix) TLHistoryFilePath(char *path, TimeLineID tli)
{
snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli);
}
#define BackupHistoryFileName(fname, tli, logSegNo, startpoint, wal_segsz_bytes) \ static inline void
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli, \ StatusFilePath(char *path, const char *xlog, const char *suffix)
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \ {
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)), \ snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix);
(uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes))) }
#define IsBackupHistoryFileName(fname) \ static inline void
(strlen(fname) > XLOG_FNAME_LEN && \ BackupHistoryFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \ {
strcmp((fname) + strlen(fname) - strlen(".backup"), ".backup") == 0) snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli,
(uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
(uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
(uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)));
}
#define BackupHistoryFilePath(path, tli, logSegNo, startpoint, wal_segsz_bytes) \ static inline bool
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli, \ IsBackupHistoryFileName(const char *fname)
(uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \ {
(uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)), \ return (strlen(fname) > XLOG_FNAME_LEN &&
(uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes))) strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
strcmp(fname + strlen(fname) - strlen(".backup"), ".backup") == 0);
}
static inline void
BackupHistoryFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
{
snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli,
(uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
(uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
(uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)));
}
/* /*
* Information logged when we detect a change in one of the parameters * Information logged when we detect a change in one of the parameters