Re: Calling pgstat_report_wait_end() before ereport(ERROR)
От | Masahiko Sawada |
---|---|
Тема | Re: Calling pgstat_report_wait_end() before ereport(ERROR) |
Дата | |
Msg-id | CAD21AoDZK0n1Up3_XV_CMOhPLgN0Bw_qr22C5NGi4nA3tv04yQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Calling pgstat_report_wait_end() before ereport(ERROR) (Tom Lane <tgl@sss.pgh.pa.us>) |
Список | pgsql-hackers |
On Fri, Apr 12, 2019 at 11:05 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: > > Masahiko Sawada <sawada.mshk@gmail.com> writes: > > There are something like the following code in many places in PostgreSQL code. > > ... > > Since we eventually call > > pgstat_report_wait_end() in AbortTransaction(). I think that we don't > > need to call pgstat_report_wait_end() if we're going to raise an error > > just after that. Is that right? > > Yes ... and those CloseTransientFile calls are unnecessary as well. > > To a first approximation, *any* cleanup-type call occurring just before > an ereport(ERROR) is probably unnecessary, or if it is necessary then > the code is broken in other ways. One should not assume that there is > no other way for an error to be thrown while the resource is held, and > therefore it's generally better design to have enough infrastructure > so that the error cleanup mechanisms can handle whatever cleanup is > needed. We certainly have such infrastructure for OpenTransientFile/ > CloseTransientFile, and according to what you say above (I didn't > check it) pgstat wait reporting is handled similarly. So these > call sites could all be simplified substantially. > > There are exceptions to this rule of thumb. In some places, for > instance, it's worth releasing a lock before ereport simply to shorten > the length of time that the lock might stay held. And there are places > where a very low-level resource (such as a spinlock) is only held in > straight-line code so there's not really need for error cleanup > infrastructure for it. Perhaps there's an argument to be made that > pgstat wait reporting could be put in this second category, but > I doubt it. > Thank you for explanation! That's really helpful for me. Regards, -- Masahiko Sawada NIPPON TELEGRAPH AND TELEPHONE CORPORATION NTT Open Source Software Center
В списке pgsql-hackers по дате отправления: