diff options
author | Fujii Masao | 2020-05-08 01:36:40 +0000 |
---|---|---|
committer | Fujii Masao | 2020-05-08 01:36:40 +0000 |
commit | f2ff2035962cd2ddd56c1593709d48ca0d3a78c5 (patch) | |
tree | 873633aa70fe2ffe6edc653a9ff08cf5a4d5a527 /src/backend/access/transam/timeline.c | |
parent | cd8c73a38a23c364e71973d6832a585616d24756 (diff) |
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]
Diffstat (limited to 'src/backend/access/transam/timeline.c')
-rw-r--r-- | src/backend/access/transam/timeline.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c index de57d699af1..e6a29d9a9b7 100644 --- a/src/backend/access/transam/timeline.c +++ b/src/backend/access/transam/timeline.c @@ -78,7 +78,6 @@ readTimeLineHistory(TimeLineID targetTLI) List *result; char path[MAXPGPATH]; char histfname[MAXFNAMELEN]; - char fline[MAXPGPATH]; FILE *fd; TimeLineHistoryEntry *entry; TimeLineID lasttli = 0; @@ -123,15 +122,30 @@ readTimeLineHistory(TimeLineID targetTLI) * Parse the file... */ prevend = InvalidXLogRecPtr; - while (fgets(fline, sizeof(fline), fd) != NULL) + for (;;) { - /* skip leading whitespace and check for # comment */ + char fline[MAXPGPATH]; + char *res; char *ptr; TimeLineID tli; uint32 switchpoint_hi; uint32 switchpoint_lo; int nfields; + pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_READ); + res = fgets(fline, sizeof(fline), fd); + pgstat_report_wait_end(); + if (res == NULL) + { + if (ferror(fd)) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not read file \"%s\": %m", path))); + + break; + } + + /* skip leading whitespace and check for # comment */ for (ptr = fline; *ptr; ptr++) { if (!isspace((unsigned char) *ptr)) @@ -393,6 +407,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, nbytes = strlen(buffer); errno = 0; + pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_WRITE); if ((int) write(fd, buffer, nbytes) != nbytes) { int save_errno = errno; @@ -408,6 +423,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, (errcode_for_file_access(), errmsg("could not write to file \"%s\": %m", tmppath))); } + pgstat_report_wait_end(); pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_SYNC); if (pg_fsync(fd) != 0) |