Skip to content

Commit 419c727

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 5f113d6 commit 419c727

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/backend/replication/logical/relation.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,20 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
564564

565565
entry = &part_entry->relmapentry;
566566

567+
/*
568+
* We must always overwrite entry->localrel with the latest partition
569+
* Relation pointer, because the Relation pointed to by the old value may
570+
* have been cleared after the caller would have closed the partition
571+
* relation after the last use of this entry. Note that localrelvalid is
572+
* only updated by the relcache invalidation callback, so it may still be
573+
* true irrespective of whether the Relation pointed to by localrel has
574+
* been cleared or not.
575+
*/
567576
if (found && entry->localrelvalid)
577+
{
578+
entry->localrel = partrel;
568579
return entry;
580+
}
569581

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

0 commit comments

Comments
 (0)