Re: Why are wait events not reported even though it reads/writes a timeline history file?

From: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>
To: Masahiro Ikeda <ikedamsh(at)oss(dot)nttdata(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Why are wait events not reported even though it reads/writes a timeline history file?
Date: 2020-04-30 15:25:46
Message-ID: 688e355d-6a70-b127-87ed-0b1fa8403dda@oss.nttdata.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2020/04/28 17:42, Masahiro Ikeda wrote:
> On 2020-04-28 15:09, Michael Paquier wrote:
>> On Tue, Apr 28, 2020 at 02:49:00PM +0900, Fujii Masao wrote:
>>> Isn't it safer to report the wait event during fgets() rather than putting
>>> those calls around the whole loop, like other code does? For example,
>>> writeTimeLineHistory() reports the wait event during read() rather than
>>> whole loop.
>>
>> Yeah, I/O wait events should be taken only during the duration of the
>> system calls.  Particularly here, you may finish with an elog() that
>> causes the wait event to be set longer than it should, leading to a
>> rather incorrect state if a snapshot of pg_stat_activity is taken.
>> --
>
> Thanks for your comments.
>
> I fixed it to report the wait event during fgets() only.
> Please review the v2 patch I attached.

Thanks for updating the patch! Here are the review comments from me.

+ char *result;
+ pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_READ);
+ result = fgets(fline, sizeof(fline), fd);
+ pgstat_report_wait_end();
+ if (result == NULL)
+ break;
+
/* skip leading whitespace and check for # comment */
char *ptr;

Since the variable name "result" has been already used in this function,
it should be renamed.

The code should not be inject into the variable declaration block.

When reading this patch, I found that IO-error in fgets() has not
been checked there. Though this is not the issue that you reported,
but it seems better to fix it together. So what about adding
the following code?

if (ferror(fd))
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not read file \"%s\": %m", path)));

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2020-04-30 15:58:09 Re: Proposing WITH ITERATIVE
Previous Message Fujii Masao 2020-04-30 14:40:59 Re: +(pg_lsn, int8) and -(pg_lsn, int8) operators