Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc534fc

Browse files
committed
Report missing wait event for timeline history file.
TimelineHistoryRead and TimelineHistoryWrite wait events are reported during waiting for a read and write of a timeline history file, respectively. However, previously, TimelineHistoryRead wait event was not reported while readTimeLineHistory() was reading a timeline history file. Also TimelineHistoryWrite was not reported while writeTimeLineHistory() was writing one line with the details of the timeline split, at the end. This commit fixes these issues. Back-patch to v10 where wait events for a timeline history file was added. Author: Masahiro Ikeda Reviewed-by: Michael Paquier, Fujii Masao Discussion: https://postgr.es/m/[email protected]
1 parent 5db4880 commit cc534fc

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/backend/access/transam/timeline.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ readTimeLineHistory(TimeLineID targetTLI)
7777
List *result;
7878
char path[MAXPGPATH];
7979
char histfname[MAXFNAMELEN];
80-
char fline[MAXPGPATH];
8180
FILE *fd;
8281
TimeLineHistoryEntry *entry;
8382
TimeLineID lasttli = 0;
@@ -122,15 +121,30 @@ readTimeLineHistory(TimeLineID targetTLI)
122121
* Parse the file...
123122
*/
124123
prevend = InvalidXLogRecPtr;
125-
while (fgets(fline, sizeof(fline), fd) != NULL)
124+
for (;;)
126125
{
127-
/* skip leading whitespace and check for # comment */
126+
char fline[MAXPGPATH];
127+
char *res;
128128
char *ptr;
129129
TimeLineID tli;
130130
uint32 switchpoint_hi;
131131
uint32 switchpoint_lo;
132132
int nfields;
133133

134+
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_READ);
135+
res = fgets(fline, sizeof(fline), fd);
136+
pgstat_report_wait_end();
137+
if (res == NULL)
138+
{
139+
if (ferror(fd))
140+
ereport(ERROR,
141+
(errcode_for_file_access(),
142+
errmsg("could not read file \"%s\": %m", path)));
143+
144+
break;
145+
}
146+
147+
/* skip leading whitespace and check for # comment */
134148
for (ptr = fline; *ptr; ptr++)
135149
{
136150
if (!isspace((unsigned char) *ptr))
@@ -388,6 +402,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
388402

389403
nbytes = strlen(buffer);
390404
errno = 0;
405+
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_WRITE);
391406
if ((int) write(fd, buffer, nbytes) != nbytes)
392407
{
393408
int save_errno = errno;
@@ -403,6 +418,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
403418
(errcode_for_file_access(),
404419
errmsg("could not write to file \"%s\": %m", tmppath)));
405420
}
421+
pgstat_report_wait_end();
406422

407423
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_SYNC);
408424
if (pg_fsync(fd) != 0)

0 commit comments

Comments
 (0)