RE: Replica Identity check of partition table on subscriber
Yu Shi (Fujitsu) <shiy.fnst@fujitsu.com>
From: "shiy.fnst@fujitsu.com" <shiy.fnst@fujitsu.com>
To: Amit Kapila <amit.kapila16@gmail.com>, Amit Langote <amitlangote09@gmail.com>, Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, "houzj.fnst@fujitsu.com" <houzj.fnst@fujitsu.com>
Date: 2022-06-10T08:45:04Z
Lists: pgsql-hackers
Attachments
- v2-0001-Fix-partition-map-cache-issues.patch (application/octet-stream) patch v2-0001
- v2-0002-Check-partition-table-replica-identity-on-subscri.patch (application/octet-stream) patch v2-0002
On Thu, June 9, 2022 7:02 PM Amit Kapila <amit.kapila16@gmail.com> wrote: > > > I think one approach to fix it is to check the target partition in this case, > > instead of the partitioned table. > > > > This approach sounds reasonable to me. One minor point: > +/* > + * Check that replica identity matches. > + * > + * We allow for stricter replica identity (fewer columns) on subscriber as > + * that will not stop us from finding unique tuple. IE, if publisher has > + * identity (id,timestamp) and subscriber just (id) this will not be a > + * problem, but in the opposite scenario it will. > + * > + * Don't throw any error here just mark the relation entry as not updatable, > + * as replica identity is only for updates and deletes but inserts can be > + * replicated even without it. > + */ > +static void > +logicalrep_check_updatable(LogicalRepRelMapEntry *entry) > > Can we name this function as logicalrep_rel_mark_updatable as we are > doing that? If so, change the comments as well. > OK. Modified. > > When trying to fix it, I saw some other problems about updating partition > map > > cache. > > > > a) In logicalrep_partmap_invalidate_cb(), the type of the entry in > > LogicalRepPartMap should be LogicalRepPartMapEntry, instead of > > LogicalRepRelMapEntry. > > > > b) In logicalrep_partition_open(), it didn't check if the entry is valid. > > > > c) When the publisher send new relation mapping, only relation map cache > will be > > updated, and partition map cache wouldn't. I think it also should be updated > > because it has remote relation information, too. > > > > Is there any test case that can show the problem due to your above > observations? > Please see the following case. -- publisher create table tbl (a int primary key, b int); create publication pub for table tbl; -- subscriber create table tbl (a int primary key, b int, c int) partition by range (a); create table child partition of tbl default; -- publisher, make cache insert into tbl values (1,1); update tbl set a=a+1; alter table tbl add column c int; update tbl set c=1 where a=2; -- subscriber postgres=# select * from tbl; a | b | c ---+---+--- 2 | 1 | (1 row) The value of column c updated failed on subscriber. And after applying the first patch, it would work fine. I have added this case to the first patch. Also add a test case for the second patch. Attach the new patches. Regards, Shi yu
Commits
-
Fix memory leak due to LogicalRepRelMapEntry.attrmap.
- ac0e2d387a04 15.0 landed
- 3238b5c330bc 14.5 landed
- 3a6ef0cdf311 13.8 landed
- 9e0d9a24ef88 12.12 landed
- ed2a7a6bf67d 11.17 landed
- d873b5a5a340 10.22 landed
-
Fix stale values in partition map entries on subscribers.
- 75bfe7434d41 15.0 landed
- f0022a77d011 14.5 landed
- 419c72715172 13.8 landed
-
Fix partition table's REPLICA IDENTITY checking on the subscriber.
- 26b3455afaa9 15.0 landed
- 5f113d60e998 13.8 landed
- 52d5ea9adb01 14.5 landed
-
Fix data inconsistency between publisher and subscriber.
- b7658c24c7c1 15.0 landed
- 0980adfd4d02 14.5 landed
- 1f9a7738eb84 13.8 landed
-
Fix cache look-up failures while applying changes in logical replication.
- 16f5a8da76f2 13.8 landed
- d457cb4e8a5e 14.5 landed
- 5a97b1325453 15.0 landed
-
Add logical replication support to replicate into partitioned tables
- f1ac27bfda6c 13.0 cited