Re: [HACKERS] logical decoding of two-phase transactions

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Peter Smith <smithpb2250(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] logical decoding of two-phase transactions
Date: 2021-03-08 05:19:45
Message-ID: CAA4eK1JrHk1NNUN+41XyRUJUUPhbdBtVgx9kVzEnYkJ_Si5NSA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Mar 8, 2021 at 10:04 AM Peter Smith <smithpb2250(at)gmail(dot)com> wrote:
>
> On Sun, Mar 7, 2021 at 3:00 PM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
> >
> > On Sun, Mar 7, 2021 at 7:35 AM Peter Smith <smithpb2250(at)gmail(dot)com> wrote:
> > >
> > > Please find attached the latest patch set v51*
> > >
> >
> > Few more comments on v51-0006-Fix-apply-worker-empty-prepare:
> > ======================================================
> > 1.
> > +/*
> > + * A Prepare spoolfile hash entry. We create this entry in the
> > psf_hash. This is
> > + * for maintaining a mapping between the name of the prepared
> > spoolfile, and the
> > + * corresponding fileset handles of same.
> > + */
> > +typedef struct PsfHashEntry
> > +{
> > + char name[MAXPGPATH]; /* Hash key --- must be first */
> > + bool allow_delete; /* ok to delete? */
> > +} PsfHashEntry;
> > +
> >
> > IIUC, this has table is used for two purposes in the patch (a) to
> > check for existence of prepare spool file where we anyway to check it
> > on disk if not found in the hash table. (b) to allow the prepare spool
> > file to be removed on proc_exit.
> >
> > I think we don't need the optimization provided by (a) because it will
> > be too rare a case to deserve any optimization, we might write a
> > comment in prepare_spoolfile_exists to indicate such an optimization.
> > For (b), we can use a simple list to track files to be removed on
> > proc_exit something like we do in CreateLockFile. I think avoiding
> > hash table usage will reduce the code and chances of bugs in this
> > area. It won't be easy to write a lot of automated tests to test this
> > functionality so it is better to avoid minor optimizations at this
> > stage.
>
> Our data structure psf_hash also needs to be able to discover the
> entry for a specific spool file and remove it. e.g. anything marked as
> "allow_delete = false" (during prepare) must be able to be re-found
> and removed from that structure at commit_prepared or
> rollback_prepared time.
>

But, I think that is not reliable because after restart the entry
might not be present and we anyway need to check the presence of the
file on disk. Actually, you don't need any manipulation with list or
hash at commit_prepared or rollback_prepared, we should just remove
the entry for it at the prepare time and there should be an assert if
we find that entry in the in-memory structure.

> Looking at CreateLockFile code, I don't see that it is ever deleting
> entries from its "lock_files" list on-the-fly, so it's not really a
> fair comparison to say just use a List like CreateLockFile.
>

Sure, but you can additionally traverse the list and find the required entry.

> So, even though we (currently) only have a single data member
> "allow_delete", I think the requirement to do a key lookup/delete
> makes a HTAB a more appropriate data structure than a List.
>

Actually, that member is also not required at all because you just
need it till the time of prepare and then remove it.

--
With Regards,
Amit Kapila.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2021-03-08 05:27:39 Re: Huge memory consumption on partitioned table with FKs
Previous Message Thomas Munro 2021-03-08 05:10:36 Re: Replace buffer I/O locks with condition variables (reviving an old patch)