Re: Support for REINDEX CONCURRENTLY

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Simon Riggs <simon(at)2ndquadrant(dot)com>
Subject: Re: Support for REINDEX CONCURRENTLY
Date: 2013-06-23 06:34:03
Message-ID: CAB7nPqQ0SfYLEZH=KWuyxNTnNLt-UX+u=wR6vp7kEJkruvSPUQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

OK. Please find an updated patch for the toast part.

On Sat, Jun 22, 2013 at 10:48 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> On 2013-06-22 22:45:26 +0900, Michael Paquier wrote:
>> On Sat, Jun 22, 2013 at 10:34 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>> > On 2013-06-22 12:50:52 +0900, Michael Paquier wrote:
>> >> By looking at the comments of RelationGetIndexList:relcache.c,
>> >> actually the method of the patch is correct because in the event of a
>> >> shared cache invalidation, rd_indexvalid is set to 0 when the index
>> >> list is reset, so the index list would get recomputed even in the case
>> >> of shared mem invalidation.
>> >
>> > The problem I see is something else. Consider code like the following:
>> >
>> > RelationFetchIndexListIfInvalid(toastrel);
>> > foreach(lc, toastrel->rd_indexlist)
>> > toastidxs[i++] = index_open(lfirst_oid(lc), RowExclusiveLock);
>> >
>> > index_open calls relation_open calls LockRelationOid which does:
>> > if (res != LOCKACQUIRE_ALREADY_HELD)
>> > AcceptInvalidationMessages();
>> >
>> > So, what might happen is that you open the first index, which accepts an
>> > invalidation message which in turn might delete the indexlist. Which
>> > means we would likely read invalid memory if there are two indexes.
>> And I imagine that you have the same problem even with
>> RelationGetIndexList, not only RelationGetIndexListIfInvalid, because
>> this would appear as long as you try to open more than 1 index with an
>> index list.
>
> No. RelationGetIndexList() returns a copy of the list for exactly that
> reason. The danger is not to see an outdated list - we should be
> protected by locks against that - but looking at uninitialized or reused
> memory.
OK, so I removed RelationGetIndexListIfInvalid (such things could be
an optimization for another patch) and replaced it by calls to
RelationGetIndexList to get a copy of rd_indexlist in a local list
variable, list free'd when it is not necessary anymore.

It looks that there is nothing left for this patch, no?
--
Michael

Attachment Content-Type Size
20130623_1_remove_reltoastidxid_v12.patch application/octet-stream 49.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2013-06-23 06:52:34 Re: A better way than tweaking NTUP_PER_BUCKET
Previous Message Amit kapila 2013-06-23 06:14:35 wrong state of patch in CF