Skip to content

Commit a354d01

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/d11b0c910b63684424e06772eb844ab5@oss.nttdata.com
1 parent e1d70ba commit a354d01

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))
@@ -392,6 +406,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
392406

393407
nbytes = strlen(buffer);
394408
errno = 0;
409+
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_WRITE);
395410
if ((int) write(fd, buffer, nbytes) != nbytes)
396411
{
397412
int save_errno = errno;
@@ -407,6 +422,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
407422
(errcode_for_file_access(),
408423
errmsg("could not write to file \"%s\": %m", tmppath)));
409424
}
425+
pgstat_report_wait_end();
410426

411427
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_SYNC);
412428
if (pg_fsync(fd) != 0)

0 commit comments

Comments
 (0)