Commit f0022a77 authored by Amit Kapila's avatar Amit Kapila

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 f1ac27bf that
introduced this code but we didn't notice it till the recent commit
26b3455afa 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
parent 52d5ea9a
...@@ -596,8 +596,20 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root, ...@@ -596,8 +596,20 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
entry = &part_entry->relmapentry; entry = &part_entry->relmapentry;
/*
* We must always overwrite entry->localrel with the latest partition
* Relation pointer, because the Relation pointed to by the old value may
* have been cleared after the caller would have closed the partition
* relation after the last use of this entry. Note that localrelvalid is
* only updated by the relcache invalidation callback, so it may still be
* true irrespective of whether the Relation pointed to by localrel has
* been cleared or not.
*/
if (found && entry->localrelvalid) if (found && entry->localrelvalid)
{
entry->localrel = partrel;
return entry; return entry;
}
/* Switch to longer-lived context. */ /* Switch to longer-lived context. */
oldctx = MemoryContextSwitchTo(LogicalRepPartMapContext); oldctx = MemoryContextSwitchTo(LogicalRepPartMapContext);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment