pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Tim Clarke <tim.clarke@minerva.info>
Cc: PostgreSQL General List <pgsql-general@postgresql.org>
Subject: Re: logical replication - negative bitmapset member not allowed
Date: Fri, 25 Oct 2019 17:38:21 +0200
Message-ID: <20191025173821.6bd76407@firost> (raw)
In-Reply-To: <20191010151546.69d4f0e9@firost>
References: <20190401214304.GA29208@alvherre.pgsql>
	<4a16af4e-ba61-e46d-6d69-0a20ef7ed97d@2ndquadrant.com>
	<20191010151546.69d4f0e9@firost>

On Thu, 10 Oct 2019 15:15:46 +0200
Jehan-Guillaume de Rorthais <jgdr@dalibo.com> wrote:

[...]
> Here is a script to reproduce it under version 10, 11 and 12:

I investigated on this bug while coming back from pgconf.eu. Bellow what I found
so far.

The message "negative bitmapset member not allowed" comes from
logicalrep_rel_open().

Every field that are unknown, dropped or generated are mapped to remote attnum
-1. See backend/replication/logical/relation.c:

    if (attr->attisdropped || attr->attgenerated)
    {
        entry->attrmap[i] = -1;
        continue;
    }

    attnum = logicalrep_rel_att_by_name(remoterel, NameStr(attr->attname));

Note that logicalrep_rel_att_by_name returns -1 on unknown fields.

Later in the same function, we check if fields belonging to some PK or unique
index appears in remote keys as well:

    while ((i = bms_next_member(idkey, i)) >= 0)
    {
        [...]
        if (!bms_is_member(entry->attrmap[attnum], remoterel->attkeys))
        {
            entry->updatable = false;
            break;
        }
    }

However, before checking if the local attribute belong to the remote keys,
it should check if it actually mapped to a remote one. In other words, I
suppose we should check entry->attrmap[attnum] > 0 before calling
bms_is_member().

The trivial patch would be:

-        if (!bms_is_member(entry->attrmap[attnum], remoterel->attkeys))
+        if (entry->attrmap[attnum] < 0 ||
+            !bms_is_member(entry->attrmap[attnum], remoterel->attkeys))
         {
             entry->updatable = false;
             break;
         }

I tested with the attached scenario and it sound to work correctly.

Note that while trying to fix this bug, I found a segment fault while compiling
with asserts. You might want to review/test without --enable-cassert. I will
report in another thread as this seems not related to this bug or fix.

Attachments:

  negative_bitmap_error-fix.bash (application/octet-stream, 2.3K) download

view thread (20+ messages)  latest in thread

Message-ID: <20191025173821.6bd76407@firost>
Permalink:  ../20191025173821.6bd76407@firost/
Also on:    postgresql.org/message-id/20191025173821.6bd76407@firost

 · 

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-general@postgresql.org
  Cc: jgdr@dalibo.com, peter.eisentraut@2ndquadrant.com, tgl@sss.pgh.pa.us, alvherre@2ndquadrant.com, tim.clarke@minerva.info
  Subject: Re: logical replication - negative bitmapset member not allowed
  In-Reply-To: <20191025173821.6bd76407@firost>
  References: <20190401214304.GA29208@alvherre.pgsql> <4a16af4e-ba61-e46d-6d69-0a20ef7ed97d@2ndquadrant.com> <20191010151546.69d4f0e9@firost> <20191025173821.6bd76407@firost>

* 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