Subject: Re: Bugs in pgoutput.c

From: Amit Kapila <[email-masked]>
Date: Thu, 3 Feb 2022 08:15:16 +0530

On Sat, Jan 29, 2022 at 8:32 AM Amit Kapila <[email-masked]> wrote:
>
> On Thu, Jan 6, 2022 at 3:42 AM Tom Lane <[email-masked]> wrote:
> >
> > Commit 6ce16088b caused me to look at pgoutput.c's handling of
> > cache invalidations, and I was pretty appalled by what I found.
> >
> > * rel_sync_cache_relation_cb does the wrong thing when called for
> > a cache flush (i.e., relid == 0).  Instead of invalidating all
> > RelationSyncCache entries as it should, it will do nothing.
> >
> > * When rel_sync_cache_relation_cb does invalidate an entry,
> > it immediately zaps the entry->map structure, even though that
> > might still be in use (as per the adjacent comment that carefully
> > explains why this isn't safe).  I'm not sure if this could lead
> > to a dangling-pointer core dump, but it sure seems like it could
> > lead to failing to translate tuples that are about to be sent.
> >
> > * Similarly, rel_sync_cache_publication_cb is way too eager to
> > reset the pubactions flags, which would likely lead to failing
> > to transmit changes that we should transmit.
> >
>
> Are you planning to proceed with this patch?
>

Tom, is it okay for you if I go ahead with this patch after some testing?

-- 
With Regards,
Amit Kapila.

---

From: Tom Lane <[email-masked]>
Date: Wed, 02 Feb 2022 21:48:18 -0500

> Tom, is it okay for you if I go ahead with this patch after some testing?

I've been too busy to get back to it, so sure.

			regards, tom lane

---

From: Amit Kapila <[email-masked]>
Date: Thu, 3 Feb 2022 17:24:35 +0530

> I've been too busy to get back to it, so sure.

Thanks. I have tested the patch by generating an invalidation message
for table DDL before accessing the syscache in
logicalrep_write_tuple(). I see that it correctly invalidates the
entry and rebuilds it for the next operation. I couldn't come up with
some automatic test for it so used the debugger to test it. I have
made a minor change in one of the comments. I am planning to push this
tomorrow unless there are comments or suggestions.

-- 
With Regards,
Amit Kapila.