Re: Add contrib/pg_logicalsnapinspect

From: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>, Peter Smith <smithpb2250(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Add contrib/pg_logicalsnapinspect
Date: 2024-09-26 00:04:18
Message-ID: CAD21AoBHkL-C22pgGJCA_8Jv6HjYq0c_1Y_b2Xktk7_SdUqxqA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Wed, Sep 25, 2024 at 10:29 AM Bertrand Drouvot
<bertranddrouvot(dot)pg(at)gmail(dot)com> wrote:
>
> Hi,
>
> On Wed, Sep 25, 2024 at 04:04:43PM +0200, Peter Eisentraut wrote:
> > Is there a reason for this elaborate error handling:
>
> Thanks for looking at it!
>
> > + fd = OpenTransientFile(path, O_RDONLY | PG_BINARY);
> > +
> > + if (fd < 0 && errno == ENOENT)
> > + ereport(ERROR,
> > + errmsg("file \"%s\" does not exist", path));
> > + else if (fd < 0)
> > + ereport(ERROR,
> > + (errcode_for_file_access(),
> > + errmsg("could not open file \"%s\": %m", path)));
> >
> > Couldn't you just use the second branch for all errno's?
>
> Yeah, I think it comes from copying/pasting from SnapBuildRestore() too "quickly".
> v10 attached uses the second branch only.
>

I've reviewed v10 patch and here are some comments:

+static void
+ValidateAndRestoreSnapshotFile(XLogRecPtr lsn, SnapBuildOnDisk *ondisk,
+ const char *path)

This function and SnapBuildRestore() have duplicate codes. Can we have
a common function that reads the snapshot data from disk to
SnapBuildOnDisk, and have both ValidateAndRestoreSnapshotFile() and
SnapBuildRestore() call it?

---
+CREATE FUNCTION pg_get_logical_snapshot_meta(IN in_lsn pg_lsn,
(snip)
+CREATE FUNCTION pg_get_logical_snapshot_info(IN in_lsn pg_lsn,

Is there any reason why both functions take a pg_lsn value as an
argument? Given that the main usage would be to use these functions
with pg_ls_logicalsnapdir(), I think it would be easier for users if
these functions take a filename as a function argument. That way, we
can use these functions like:

select info.* from pg_ls_logicalsnapdir(),
pg_get_logical_snapshot_info(name) as info;

If there are use cases where specifying a LSN is easier, I think we
would have both types.

----
+static const char *const SnapBuildStateDesc[] = {
+ [SNAPBUILD_START + SNAPBUILD_STATE_INCR] = "start",
+ [SNAPBUILD_BUILDING_SNAPSHOT + SNAPBUILD_STATE_INCR] = "building",
+ [SNAPBUILD_FULL_SNAPSHOT + SNAPBUILD_STATE_INCR] = "full",
+ [SNAPBUILD_CONSISTENT + SNAPBUILD_STATE_INCR] = "consistent",
+};

I think that it'd be better to have a dedicated function that returns
a string representation of the given state by using a switch
statement. That way, we don't need SNAPBUILD_STATE_INCR and a compiler
warning would help realize a missing state if a new state is
introduced in the future. It needs a function call but I believe it
won't be a problem in this use case.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2024-09-26 01:08:21 Re: query_id, pg_stat_activity, extended query protocol
Previous Message Masahiko Sawada 2024-09-25 22:46:27 Re: pg_trgm comparison bug on cross-architecture replication due to different char implementation