pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
Cc: 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: Thu, 7 Nov 2019 16:02:21 +0100
Message-ID: <78e914d8-5a9b-4ffc-887e-2acda9890962@2ndquadrant.com> (raw)
In-Reply-To: <20191105170505.2f5d38d1@firost>
References: <20190401214304.GA29208@alvherre.pgsql>
	<4a16af4e-ba61-e46d-6d69-0a20ef7ed97d@2ndquadrant.com>
	<20191010151546.69d4f0e9@firost>
	<20191025173821.6bd76407@firost>
	<d31863d3-5a47-a492-837d-4b41d9989374@2ndquadrant.com>
	<20191105170505.2f5d38d1@firost>

On 2019-11-05 17:05, Jehan-Guillaume de Rorthais wrote:
>> I have simplified your reproduction steps from the previous message to a
>> test case, and I can confirm that your proposed fix addresses the issue.
> 
> Thanks for the feedback and the test case. I wonder if ALTER SUBSCRIPTION
> DISABLE/ENABLE is useful in the test case?

Turns out it's not necessary.  Attached is an updated patch that 
simplifies the test even further and moves it into the 
008_diff_schema.pl file.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

v2-0001-Fix-negative-bitmapset-member-not-allowed-error-i.patch (text/plain, 4.0K) download From dcc12ec8315ecb8613190052d4f787cf0554e2c2 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter@eisentraut.org> Date: Thu, 7 Nov 2019 13:48:59 +0100 Subject: [PATCH v2] Fix negative bitmapset member not allowed error in logical replication This happens when we add a replica identity column on a subscriber that does not yet exist on the publisher, according to the mapping maintained by the subscriber. Code that checks whether the target relation on the subscriber is updatable would check the replica identity attribute bitmap with a column number -1, which would result in an error. To fix, skip such columns in the bitmap lookup and consider the relation not updatable. The result is consistent with the rule that the replica identity columns on the subscriber must be a subset of those on the publisher, since if the column doesn't exist on the publisher, the column set on the subscriber can't be a subset. Reported-by: Tim Clarke <tim.clarke@minerva.info> Analyzed-by: Jehan-Guillaume de Rorthais <jgdr@dalibo.com> Discussion: https://www.postgresql.org/message-id/flat/a9139c29-7ddd-973b-aa7f-71fed9c38d75%40minerva.info --- src/backend/replication/logical/relation.c | 3 +- src/test/subscription/t/008_diff_schema.pl | 37 ++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c index f938d1fa48..b386f8460d 100644 --- a/src/backend/replication/logical/relation.c +++ b/src/backend/replication/logical/relation.c @@ -340,7 +340,8 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode) attnum = AttrNumberGetAttrOffset(attnum); - 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; diff --git a/src/test/subscription/t/008_diff_schema.pl b/src/test/subscription/t/008_diff_schema.pl index 3ad00eae3b..d1c8fb7061 100644 --- a/src/test/subscription/t/008_diff_schema.pl +++ b/src/test/subscription/t/008_diff_schema.pl @@ -3,7 +3,7 @@ use warnings; use PostgresNode; use TestLib; -use Test::More tests => 4; +use Test::More tests => 5; # Create publisher node my $node_publisher = get_new_node('publisher'); @@ -29,7 +29,7 @@ # Setup logical replication my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; $node_publisher->safe_psql('postgres', - "CREATE PUBLICATION tap_pub FOR TABLE test_tab"); + "CREATE PUBLICATION tap_pub FOR ALL TABLES"); $node_subscriber->safe_psql('postgres', "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub" @@ -88,5 +88,38 @@ is($result, qq(3|3|3|3), 'check extra columns contain local defaults after apply'); + +# Check a bug about adding a replica identity column on the subscriber +# that was not yet mapped to a column on the publisher. This would +# result in errors on the subscriber and replication thus not +# progressing. +# (https://www.postgresql.org/message-id/flat/a9139c29-7ddd-973b-aa7f-71fed9c38d75%40minerva.info) + +$node_publisher->safe_psql('postgres', + "CREATE TABLE test_tab2 (a int)"); + +$node_subscriber->safe_psql('postgres', + "CREATE TABLE test_tab2 (a int)"); + +$node_subscriber->safe_psql('postgres', + "ALTER SUBSCRIPTION tap_sub REFRESH PUBLICATION"); + +# Add replica identity column. (The serial is not necessary, but it's +# a convenient way to get a default on the new column so that rows +# from the publisher that don't have the column yet can be inserted.) +$node_subscriber->safe_psql('postgres', + "ALTER TABLE test_tab2 ADD COLUMN b serial PRIMARY KEY"); + +$node_publisher->safe_psql('postgres', + "INSERT INTO test_tab2 VALUES (1)"); + +$node_publisher->wait_for_catchup('tap_sub'); + +is($node_subscriber->safe_psql('postgres', + "SELECT count(*), min(a), max(a) FROM test_tab2"), + qq(1|1|1), + 'check replicated inserts on subscriber'); + + $node_subscriber->stop; $node_publisher->stop; base-commit: e5cfb8cbbe91e73ee92d9e4ab023ca208f3b748a -- 2.23.0

view thread (20+ messages)  latest in thread

Message-ID: <78e914d8-5a9b-4ffc-887e-2acda9890962@2ndquadrant.com>
Permalink:  ../78e914d8-5a9b-4ffc-887e-2acda9890962@2ndquadrant.com/
Also on:    postgresql.org/message-id/78e914d8-5a9b-4ffc-887e-2acda9890962@2ndquadrant.com

 ·  · 

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: peter.eisentraut@2ndquadrant.com, jgdr@dalibo.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: <78e914d8-5a9b-4ffc-887e-2acda9890962@2ndquadrant.com>
  References: <20190401214304.GA29208@alvherre.pgsql> <4a16af4e-ba61-e46d-6d69-0a20ef7ed97d@2ndquadrant.com> <20191010151546.69d4f0e9@firost> <20191025173821.6bd76407@firost> <d31863d3-5a47-a492-837d-4b41d9989374@2ndquadrant.com> <20191105170505.2f5d38d1@firost> <78e914d8-5a9b-4ffc-887e-2acda9890962@2ndquadrant.com>

* 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