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

Skip to content

Commit f2ff203

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 cd8c73a commit f2ff203

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
@@ -78,7 +78,6 @@ readTimeLineHistory(TimeLineID targetTLI)
7878
List *result;
7979
char path[MAXPGPATH];
8080
char histfname[MAXFNAMELEN];
81-
char fline[MAXPGPATH];
8281
FILE *fd;
8382
TimeLineHistoryEntry *entry;
8483
TimeLineID lasttli = 0;
@@ -123,15 +122,30 @@ readTimeLineHistory(TimeLineID targetTLI)
123122
* Parse the file...
124123
*/
125124
prevend = InvalidXLogRecPtr;
126-
while (fgets(fline, sizeof(fline), fd) != NULL)
125+
for (;;)
127126
{
128-
/* skip leading whitespace and check for # comment */
127+
char fline[MAXPGPATH];
128+
char *res;
129129
char *ptr;
130130
TimeLineID tli;
131131
uint32 switchpoint_hi;
132132
uint32 switchpoint_lo;
133133
int nfields;
134134

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

394408
nbytes = strlen(buffer);
395409
errno = 0;
410+
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_WRITE);
396411
if ((int) write(fd, buffer, nbytes) != nbytes)
397412
{
398413
int save_errno = errno;
@@ -408,6 +423,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
408423
(errcode_for_file_access(),
409424
errmsg("could not write to file \"%s\": %m", tmppath)));
410425
}
426+
pgstat_report_wait_end();
411427

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

0 commit comments

Comments
 (0)