Commit 71e0d0a7 authored by Fujii Masao's avatar Fujii Masao

Tidy up XLogSource code in xlog.c.

This commit replaces 0 used as an initial value of XLogSource variable,
with XLOG_FROM_ANY. Also this commit changes those variable so that
XLogSource instead of int is used as the type for them. These changes
are for code readability and debugger-friendliness.

Author: Kyotaro Horiguchi
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/20200227.124830.2197604521555566121.horikyota.ntt@gmail.com
parent 8728b2c7
...@@ -795,7 +795,7 @@ static int readFile = -1; ...@@ -795,7 +795,7 @@ static int readFile = -1;
static XLogSegNo readSegNo = 0; static XLogSegNo readSegNo = 0;
static uint32 readOff = 0; static uint32 readOff = 0;
static uint32 readLen = 0; static uint32 readLen = 0;
static XLogSource readSource = 0; /* XLOG_FROM_* code */ static XLogSource readSource = XLOG_FROM_ANY;
/* /*
* Keeps track of which source we're currently reading from. This is * Keeps track of which source we're currently reading from. This is
...@@ -804,7 +804,7 @@ static XLogSource readSource = 0; /* XLOG_FROM_* code */ ...@@ -804,7 +804,7 @@ static XLogSource readSource = 0; /* XLOG_FROM_* code */
* attempt to read from currentSource failed, and we should try another source * attempt to read from currentSource failed, and we should try another source
* next. * next.
*/ */
static XLogSource currentSource = 0; /* XLOG_FROM_* code */ static XLogSource currentSource = XLOG_FROM_ANY;
static bool lastSourceFailed = false; static bool lastSourceFailed = false;
typedef struct XLogPageReadPrivate typedef struct XLogPageReadPrivate
...@@ -823,7 +823,7 @@ typedef struct XLogPageReadPrivate ...@@ -823,7 +823,7 @@ typedef struct XLogPageReadPrivate
* XLogReceiptSource tracks where we last successfully read some WAL.) * XLogReceiptSource tracks where we last successfully read some WAL.)
*/ */
static TimestampTz XLogReceiptTime = 0; static TimestampTz XLogReceiptTime = 0;
static XLogSource XLogReceiptSource = 0; /* XLOG_FROM_* code */ static XLogSource XLogReceiptSource = XLOG_FROM_ANY;
/* State information for XLOG reading */ /* State information for XLOG reading */
static XLogRecPtr ReadRecPtr; /* start of last record read */ static XLogRecPtr ReadRecPtr; /* start of last record read */
...@@ -886,8 +886,8 @@ static bool InstallXLogFileSegment(XLogSegNo *segno, char *tmppath, ...@@ -886,8 +886,8 @@ static bool InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
bool find_free, XLogSegNo max_segno, bool find_free, XLogSegNo max_segno,
bool use_lock); bool use_lock);
static int XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli, static int XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
int source, bool notfoundOk); XLogSource source, bool notfoundOk);
static int XLogFileReadAnyTLI(XLogSegNo segno, int emode, int source); static int XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source);
static int XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, static int XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
int reqLen, XLogRecPtr targetRecPtr, char *readBuf); int reqLen, XLogRecPtr targetRecPtr, char *readBuf);
static bool WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, static bool WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
...@@ -3633,7 +3633,7 @@ XLogFileOpen(XLogSegNo segno) ...@@ -3633,7 +3633,7 @@ XLogFileOpen(XLogSegNo segno)
*/ */
static int static int
XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli, XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
int source, bool notfoundOk) XLogSource source, bool notfoundOk)
{ {
char xlogfname[MAXFNAMELEN]; char xlogfname[MAXFNAMELEN];
char activitymsg[MAXFNAMELEN + 16]; char activitymsg[MAXFNAMELEN + 16];
...@@ -3715,7 +3715,7 @@ XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli, ...@@ -3715,7 +3715,7 @@ XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
* This version searches for the segment with any TLI listed in expectedTLEs. * This version searches for the segment with any TLI listed in expectedTLEs.
*/ */
static int static int
XLogFileReadAnyTLI(XLogSegNo segno, int emode, int source) XLogFileReadAnyTLI(XLogSegNo segno, int emode, XLogSource source)
{ {
char path[MAXPGPATH]; char path[MAXPGPATH];
ListCell *cell; ListCell *cell;
...@@ -4387,7 +4387,7 @@ ReadRecord(XLogReaderState *xlogreader, int emode, ...@@ -4387,7 +4387,7 @@ ReadRecord(XLogReaderState *xlogreader, int emode,
* so that we will check the archive next. * so that we will check the archive next.
*/ */
lastSourceFailed = false; lastSourceFailed = false;
currentSource = 0; currentSource = XLOG_FROM_ANY;
continue; continue;
} }
...@@ -11673,7 +11673,7 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen, ...@@ -11673,7 +11673,7 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
close(readFile); close(readFile);
readFile = -1; readFile = -1;
readSource = 0; readSource = XLOG_FROM_ANY;
} }
XLByteToSeg(targetPagePtr, readSegNo, wal_segment_size); XLByteToSeg(targetPagePtr, readSegNo, wal_segment_size);
...@@ -11693,7 +11693,7 @@ retry: ...@@ -11693,7 +11693,7 @@ retry:
close(readFile); close(readFile);
readFile = -1; readFile = -1;
readLen = 0; readLen = 0;
readSource = 0; readSource = XLOG_FROM_ANY;
return -1; return -1;
} }
...@@ -11799,7 +11799,7 @@ next_record_is_invalid: ...@@ -11799,7 +11799,7 @@ next_record_is_invalid:
close(readFile); close(readFile);
readFile = -1; readFile = -1;
readLen = 0; readLen = 0;
readSource = 0; readSource = XLOG_FROM_ANY;
/* In standby-mode, keep trying */ /* In standby-mode, keep trying */
if (StandbyMode) if (StandbyMode)
...@@ -11870,7 +11870,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, ...@@ -11870,7 +11870,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
*/ */
if (!InArchiveRecovery) if (!InArchiveRecovery)
currentSource = XLOG_FROM_PG_WAL; currentSource = XLOG_FROM_PG_WAL;
else if (currentSource == 0 || else if (currentSource == XLOG_FROM_ANY ||
(!StandbyMode && currentSource == XLOG_FROM_STREAM)) (!StandbyMode && currentSource == XLOG_FROM_STREAM))
{ {
lastSourceFailed = false; lastSourceFailed = false;
...@@ -11879,7 +11879,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, ...@@ -11879,7 +11879,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
for (;;) for (;;)
{ {
int oldSource = currentSource; XLogSource oldSource = currentSource;
/* /*
* First check if we failed to read from the current source, and * First check if we failed to read from the current source, and
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment