Re: error context for vacuum to include block number

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Justin Pryzby <pryzby(at)telsasoft(dot)com>
Cc: Masahiko Sawada <masahiko(dot)sawada(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: error context for vacuum to include block number
Date: 2020-03-24 14:00:45
Message-ID: CAA4eK1LkxBgRisM8kwJSo2WzAaxcFppAeeiB-NpLbT2gMsbSRA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Mar 24, 2020 at 7:18 PM Justin Pryzby <pryzby(at)telsasoft(dot)com> wrote:
>
> On Tue, Mar 24, 2020 at 07:07:03PM +0530, Amit Kapila wrote:
> > On Tue, Mar 24, 2020 at 6:18 PM Masahiko Sawada <masahiko(dot)sawada(at)2ndquadrant(dot)com> wrote:
> > > 1.
> > > + /* Update error traceback information */
> > > + olderrcbarg = *vacrelstats;
> > > + update_vacuum_error_cbarg(vacrelstats,
> > > + VACUUM_ERRCB_PHASE_TRUNCATE,
> > > new_rel_pages, NULL,
> > > + false);
> > > +
> > > /*
> > > * Scan backwards from the end to verify that the end pages actually
> > > * contain no tuples. This is *necessary*, not optional, because
> > > * other backends could have added tuples to these pages whilst we
> > > * were vacuuming.
> > > */
> > > new_rel_pages = count_nondeletable_pages(onerel, vacrelstats);
> > >
> > > We need to set the error context after setting new_rel_pages.
> >
> > We want to cover the errors raised in count_nondeletable_pages(). In
> > an earlier version of the patch, we had TRUNCATE_PREFETCH phase which
> > use to cover those errors, but that was not good as we were
> > setting/resetting it multiple times and it was not clear such a
> > separate phase would add any value.
>
> I insisted on covering count_nondeletable_pages since it calls ReadBuffer(),
> but I think we need to at least set vacrelsats->blkno = new_rel_pages, since it
> may be different, right ?
>

yeah, that makes sense.

> > > 2.
> > > + vacrelstats->relnamespace =
> > > get_namespace_name(RelationGetNamespace(onerel));
> > > + vacrelstats->relname = pstrdup(RelationGetRelationName(onerel));
> > >
> > > I think we can pfree these two variables to avoid a memory leak during
> > > vacuum on multiple relations.
> >
> > Yeah, I had also thought about it but I noticed that we are not
> > freeing for vacrelstats. Also, I think the memory is allocated in
> > TopTransactionContext which should be freed via
> > CommitTransactionCommand before vacuuming of the next relation, so not
> > sure if there is much value in freeing those variables.
>
> One small reason to free them is that (as Tom mentioned upthread) it's good to
> ensure that those variables are their own allocation, and not depending on
> being able to access relcache or anything else during an unexpected error.
>

That is a good reason to allocate them separately but not for doing
retail free especially when the caller of the function will free the
context in which that is allocated. I think Sawada-San's concern was
that it will leak memory across the vacuum of multiple relations but
that is not the case here. Won't it look odd if we are freeing memory
for members of vacrelstats but not for vacrelstats itself?

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message James Coleman 2020-03-24 14:01:43 Re: improve transparency of bitmap-only heap scans
Previous Message Justin Pryzby 2020-03-24 13:48:49 Re: error context for vacuum to include block number