This is an automated email from the ASF dual-hosted git repository.

reshke pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit f582f98bef6583424a8e3f9712870560b194feec
Author: Amit Kapila <[email protected]>
AuthorDate: Tue Jun 21 15:30:36 2022 +0530

    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 f1ac27bfda 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/oszpr01mb6310f46cd425a967e4aef736fd...@oszpr01mb6310.jpnprd01.prod.outlook.com
---
 src/backend/replication/logical/relation.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/backend/replication/logical/relation.c 
b/src/backend/replication/logical/relation.c
index f1cff93b920..d0ed64da17d 100644
--- a/src/backend/replication/logical/relation.c
+++ b/src/backend/replication/logical/relation.c
@@ -603,8 +603,20 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
 
        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)
+       {
+               entry->localrel = partrel;
                return entry;
+       }
 
        /* Switch to longer-lived context. */
        oldctx = MemoryContextSwitchTo(LogicalRepPartMapContext);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to