On 2019-10-25 17:38, Jehan-Guillaume de Rorthais wrote:
On Thu, 10 Oct 2019 15:15:46 +0200
Jehan-Guillaume de Rorthais <j...@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.

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. A patch is attached. Maybe someone can look it over. I target next week's minor releases.

--
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>From 12c3021110a1b30afbc5fddd1b3dc78f2010fb4e Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Tue, 5 Nov 2019 15:49:56 +0100
Subject: [PATCH] Fix negative bitmapset member not allowed error in logical
 replication

Reported-by: Tim Clarke <tim.cla...@minerva.info>
Analyzed-by: Jehan-Guillaume de Rorthais <j...@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/100_bugs.pl        | 54 +++++++++++++++++++++-
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/src/backend/replication/logical/relation.c 
b/src/backend/replication/logical/relation.c
index 85269c037d..ab80d4b4e0 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/100_bugs.pl 
b/src/test/subscription/t/100_bugs.pl
index 366a7a9435..2bd07b1cf6 100644
--- a/src/test/subscription/t/100_bugs.pl
+++ b/src/test/subscription/t/100_bugs.pl
@@ -3,7 +3,7 @@
 use warnings;
 use PostgresNode;
 use TestLib;
-use Test::More tests => 3;
+use Test::More tests => 4;
 
 # Bug #15114
 
@@ -100,3 +100,55 @@
 );
 
 $node_publisher->stop('fast');
+
+
+# TODO: 
https://www.postgresql.org/message-id/flat/a9139c29-7ddd-973b-aa7f-71fed9c38d75%40minerva.info
+
+$node_publisher = get_new_node('publisher3');
+$node_publisher->init(allows_streaming => 'logical');
+$node_publisher->start;
+
+$node_subscriber = get_new_node('subscriber3');
+$node_subscriber->init(allows_streaming => 'logical');
+$node_subscriber->start;
+
+$publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
+
+$node_publisher->safe_psql('postgres',
+       "CREATE TABLE tab1 (a int)");
+
+$node_subscriber->safe_psql('postgres',
+       "CREATE TABLE tab1 (a int)");
+
+$node_publisher->safe_psql('postgres',
+       "CREATE PUBLICATION pub1 FOR ALL TABLES");
+
+$node_subscriber->safe_psql('postgres',
+       "CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION 
pub1");
+
+$node_publisher->wait_for_catchup('sub1');
+
+$node_subscriber->safe_psql('postgres',
+       "ALTER SUBSCRIPTION sub1 DISABLE");
+
+$node_subscriber->safe_psql('postgres',
+       "ALTER TABLE tab1 ADD COLUMN b serial PRIMARY KEY");
+
+$node_publisher->safe_psql('postgres',
+       "INSERT INTO tab1 VALUES (1)");
+
+$node_publisher->safe_psql('postgres',
+       "ALTER TABLE tab1 ADD COLUMN b serial PRIMARY KEY");
+
+$node_subscriber->safe_psql('postgres',
+       "ALTER SUBSCRIPTION sub1 ENABLE");
+
+$node_publisher->wait_for_catchup('sub1');
+
+is($node_subscriber->safe_psql('postgres',
+                                                          "SELECT count(*), 
min(a), max(a) FROM tab1"),
+   qq(1|1|1),
+   'check replicated inserts on subscriber');
+
+$node_publisher->stop('fast');
+$node_subscriber->stop('fast');
-- 
2.23.0

Reply via email to