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>
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-28 05:49:00
Message-ID: b208e403-e654-b609-3802-7998b21d016e@oss.nttdata.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2020/04/28 11:10, Masahiro Ikeda wrote:
> On 2020-04-27 12:25, Fujii Masao wrote:
>> On 2020/04/24 11:29, Masahiro Ikeda wrote:
>>> Hi,
>>>
>>> There are two unexpected codes for me about wait events for timeline history file.
>>> Please let me know your thoughts whether if we need to change.
>>>
>>>
>>> 1. readTimeLineHistory() function in timeline.c
>>>
>>> The readTimeLineHistory() reads a timeline history file,
>>> but it doesn't report “WAIT_EVENT_TIMELINE_HISTORY_READ".
>>
>> Yeah, this sounds strange.
>>
>>> In my understanding, sscanf() is blocking read.
>>> So, it's important to report a wait event.
>>
>> Shouldn't the wait event be reported during fgets() rather than sscanf()?
>>
>>> 2. writeTimeLineHistory() function in timeline.c
>>>
>>> The writeTimeLineHistory() function may write a timeline history file twice,
>>> but it reports “WAIT_EVENT_TIMELINE_HISTORY_WRITE" only once.
>>>
>>> It makes sense to report a wait event twice, because both of them use write().
>>
>> Yes.
>>
>>> I attached a patch to mention the code line number.
>>>
>>>
>>> I checked the commit log which "WAIT_EVENT_TIMELINE_HISTORY_READ" and
>>> "WAIT_EVENT_TIMELINE_HISTORY_WRITE" are committed and the discussion about it.
>>> But I can't find the reason.
>>>
>>> Please give me your comments.
>>> If we need to change, I can make a patch to fix them.
>>
>> Thanks! I agree to fix those issues.
>
> Thanks for the comments. I attach a patch to fix those issues.
> Please review it.

Thanks for the patch!

prevend = InvalidXLogRecPtr;
+ pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_READ);
while (fgets(fline, sizeof(fline), fd) != NULL)
{
/* skip leading whitespace and check for # comment */
@@ -172,6 +173,7 @@ readTimeLineHistory(TimeLineID targetTLI)

/* we ignore the remainder of each line */
}
+ pgstat_report_wait_end();

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.

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 Michael Paquier 2020-04-28 06:03:28 Re: +(pg_lsn, int8) and -(pg_lsn, int8) operators
Previous Message Andres Freund 2020-04-28 05:19:09 Re: Fix compilation failure against LLVM 11