pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: ruihaij@gmail.com
Subject: BUG #15887: An extra "break" instruction causes a bug
Date: Wed, 03 Jul 2019 03:04:47 +0000
Message-ID: <15887-e9320033d84cf7ea@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15887
Logged by:          Rui Hai Jiang
Email address:      ruihaij@gmail.com
PostgreSQL version: 12beta2
Operating system:   all
Description:        

In function TopoSort(), an extra "break" instruction make it impossible to
set beforeConstraints to -1 for other 
processes in the same group.  If the waiter's group has more than one
members in the wait for queue, the sorting couldn't get the right order. 

The issue exists in all V10,V11,V12 releases.

static bool
TopoSort(LOCK *lock,
                 EDGE *constraints,
                 int nConstraints,
                 PGPROC **ordering)             /* output argument */
{
     MemSet(beforeConstraints, 0, queue_size * sizeof(int));
        MemSet(afterConstraints, 0, queue_size * sizeof(int));
        for (i = 0; i < nConstraints; i++)
        {
                /*
                 * Find a representative process that is on the lock queue
and part of
                 * the waiting lock group.  This may or may not be the
leader, which
                 * may or may not be waiting at all.  If there are any other
processes
                 * in the same lock group on the queue, set their number
of
                 * beforeConstraints to -1 to indicate that they should be
emitted
                 * with their groupmates rather than considered
separately.
                 */
                proc = constraints[i].waiter;
                Assert(proc != NULL);
                jj = -1;
                for (j = queue_size; --j >= 0;)
                {
                        PGPROC     *waiter = topoProcs[j];

                        if (waiter == proc || waiter->lockGroupLeader ==
proc)
                        {
                                Assert(waiter->waitLock == lock);
                                if (jj == -1)
                                        jj = j;
                                else
                                {
                                        Assert(beforeConstraints[j] <= 0);
                                        beforeConstraints[j] = -1;
                                }
                                break;
                        }
                }
        }
}


A proposed patch is also sent to the hacker' list.

https://www.postgresql.org/message-id/CAEri+mLd3bpHLyW+a9pSe1y=aEkeuJpwBSwvo-+m4n7-ceRmXw@mail.gmail...



Message-ID: <15887-e9320033d84cf7ea@postgresql.org>
Permalink:  ../15887-e9320033d84cf7ea@postgresql.org/
Also on:    postgresql.org/message-id/15887-e9320033d84cf7ea@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, ruihaij@gmail.com
  Subject: Re: BUG #15887: An extra "break" instruction causes a bug
  In-Reply-To: <15887-e9320033d84cf7ea@postgresql.org>
  References: <15887-e9320033d84cf7ea@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox