Re: XLogWrite uses palloc within a critical section

From: Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>
To: hlinnaka(at)iki(dot)fi
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: XLogWrite uses palloc within a critical section
Date: 2018-05-25 07:57:42
Message-ID: 20180525.165742.66009686.horiguchi.kyotaro@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thank you for the comment.

At Fri, 25 May 2018 09:05:21 +0300, Heikki Linnakangas <hlinnaka(at)iki(dot)fi> wrote in <466a3c6d-7986-8cb1-d908-e85aa6a090e0(at)iki(dot)fi>
> On 25/05/18 07:45, Kyotaro HORIGUCHI wrote:
> > Hello.
> > I happened to see the following in XLogWrite.
> >
> >> ereport(PANIC,
> >> (errcode_for_file_access(),
> >> errmsg("could not seek in log file %s to offset %u: %m",
> >> XLogFileNameP(ThisTimeLineID, openLogSegNo),
> >> startoffset)));
> > where XLogFileNameP calls palloc within, and it is within a
> > critical section there. So it ends with assertion failure hiding
> > the PANIC message. We should use XLogFileName instead. The
> > problem has existed at least since 9.3. The code is frequently
> > revised so the patch needed to vary into four files.
>
> Hmm, that's rather annoying, it sure would be handy if we could do
> small palloc()s like this in error messages safely.
>
> I wonder if we could switch to ErrorContext in errstart()? That way,
> any small allocations in the ereport() arguments, like what
> XLogFileNameP() does, would be allocated in ErrorContext.

It already controlling error context per-recursion-level basis
but it doesn't work for the top-level errmsg(). I'm not sure the
basis of edata->assoc_context, it seems always set to
ErrorContext.

As a PoC, just moving to and restore from ErrorContext at the top
level seems working fine. (The first attached and it changes only
ereport.)

# The second is less invasive version of the previous patch..

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

Attachment Content-Type Size
PoC_use_errctx_in_ereport.patch text/x-patch 1.9 KB
fix_xlog_crit_ereports_v2_11b1-master.patch text/x-patch 3.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashwin Agrawal 2018-05-25 09:24:55 Avoiding Tablespace path collision for primary and standby
Previous Message Ashwin Agrawal 2018-05-25 07:36:35 Re: Keeping temporary tables in shared buffers