Skip to content

Commit 75bfe74

Browse files
author
Amit Kapila
committed
Fix stale values in partition map entries on subscribers.
We build the partition map entries on subscribers while applying the changes for update/delete on partitions. The component relation in each entry is closed after its use so we need to update it on successive use of cache entries. This problem was there since the original commit f1ac27b that introduced this code but we didn't notice it till the recent commit 26b3455 started to use the component relation of partition map cache entry. Reported-by: Tom Lane, as per buildfarm Author: Amit Langote, Hou Zhijie Reviewed-by: Amit Kapila, Shi Yu Backpatch-through: 13, where it was introduced Discussion: https://postgr.es/m/OSZPR01MB6310F46CD425A967E4AEF736FDA49@OSZPR01MB6310.jpnprd01.prod.outlook.com
1 parent 26a6d14 commit 75bfe74

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/backend/replication/logical/relation.c

+12
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,20 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
596596

597597
entry = &part_entry->relmapentry;
598598

599+
/*
600+
* We must always overwrite entry->localrel with the latest partition
601+
* Relation pointer, because the Relation pointed to by the old value may
602+
* have been cleared after the caller would have closed the partition
603+
* relation after the last use of this entry. Note that localrelvalid is
604+
* only updated by the relcache invalidation callback, so it may still be
605+
* true irrespective of whether the Relation pointed to by localrel has
606+
* been cleared or not.
607+
*/
599608
if (found && entry->localrelvalid)
609+
{
610+
entry->localrel = partrel;
600611
return entry;
612+
}
601613

602614
/* Switch to longer-lived context. */
603615
oldctx = MemoryContextSwitchTo(LogicalRepPartMapContext);

0 commit comments

Comments
 (0)