Skip to content

Commit f582f98

Browse files
Amit Kapilareshke
authored andcommitted
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 a790f4c commit f582f98

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/backend/replication/logical/relation.c

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

604604
entry = &part_entry->relmapentry;
605605

606+
/*
607+
* We must always overwrite entry->localrel with the latest partition
608+
* Relation pointer, because the Relation pointed to by the old value may
609+
* have been cleared after the caller would have closed the partition
610+
* relation after the last use of this entry. Note that localrelvalid is
611+
* only updated by the relcache invalidation callback, so it may still be
612+
* true irrespective of whether the Relation pointed to by localrel has
613+
* been cleared or not.
614+
*/
606615
if (found && entry->localrelvalid)
616+
{
617+
entry->localrel = partrel;
607618
return entry;
619+
}
608620

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

0 commit comments

Comments
 (0)