Re: [HACKERS] Re: PANIC: invalid index offnum: 186 when processing BRIN indexes in VACUUM - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] Re: PANIC: invalid index offnum: 186 when processing BRIN indexes in VACUUM
Date
Msg-id 13135.1509479192@sss.pgh.pa.us
Whole thread Raw
In response to Re: [HACKERS] Re: PANIC: invalid index offnum: 186 when processing BRIN indexes in VACUUM  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [HACKERS] Re: PANIC: invalid index offnum: 186 when processingBRIN indexes in VACUUM  (Tomas Vondra <tomas.vondra@2ndquadrant.com>)
List pgsql-hackers
I wrote:
> maybe
> we just have some run-of-the-mill bugs to find, like the off-the-end
> bug I spotted in brin_doupdate.  There's apparently at least one
> more, but given the error message it must be something like not
> checking for a page to have turned into a revmap page.  Shouldn't
> be too hard to find...

Actually, I think it might be as simple as the attached.
brin_getinsertbuffer checks for the old page having turned into revmap,
but the "samepage" path in brin_doupdate does not :-(

With this applied, Alvaro's version of the test case has survived
without error for quite a bit longer than its former MTBF.  There
might still be some issues though in other code paths.

            regards, tom lane

diff --git a/src/backend/access/brin/brin_pageops.c b/src/backend/access/brin/brin_pageops.c
index 80f803e..b0f86f3 100644
*** a/src/backend/access/brin/brin_pageops.c
--- b/src/backend/access/brin/brin_pageops.c
*************** brin_doupdate(Relation idxrel, BlockNumb
*** 113,121 ****

      /*
       * Check that the old tuple wasn't updated concurrently: it might have
!      * moved someplace else entirely ...
       */
!     if (!ItemIdIsNormal(oldlp))
      {
          LockBuffer(oldbuf, BUFFER_LOCK_UNLOCK);

--- 113,127 ----

      /*
       * Check that the old tuple wasn't updated concurrently: it might have
!      * moved someplace else entirely, and for that matter the whole page
!      * might've become a revmap page.  Note that in the first two cases
!      * checked here, the "oldlp" we just calculated is garbage; but
!      * PageGetItemId() is simple enough that it was safe to do that
!      * calculation anyway.
       */
!     if (!BRIN_IS_REGULAR_PAGE(oldpage) ||
!         oldoff > PageGetMaxOffsetNumber(oldpage) ||
!         !ItemIdIsNormal(oldlp))
      {
          LockBuffer(oldbuf, BUFFER_LOCK_UNLOCK);


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: [HACKERS] Transaction control in procedures
Next
From: Pavel Stehule
Date:
Subject: Re: [HACKERS] SQL procedures