Re: splitting *_desc routines

Lists: pgsql-hackers
From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: splitting *_desc routines
Date: 2012-08-29 19:50:06
Message-ID: 1346268803-sup-9854@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

So Andres Freund floated a proposal to create an xlogdump sort of tool,
in core, and posted a patch.

One advantage of having xlogdump in core is that we can have buildfarm
test that part of the Xlog code, which currently sees no testing at all.
In fact we could use it as a testbed for XLog in general, say by having
it run during "make installcheck" or some such.

I looked at Andres' patch and the general idea is rather horrible: it
links all backend files into the output executable. This is so that the
*_desc functions can be used from their respective object files, which
obviously have a lot of requirements for backend infrastructure.

However, after looking at the _desc routines themselves, they turn out
to be quite light on requirements: the only thing they really care about
is having a StringInfo around. (There are also two of them that call
relpathperm(), but I think that's easily fixable.)

(There is also a bug of sorts in gin_desc, which calls elog(PANIC) when
finding a record it doesn't know about; but all other routines simply
call appendStringInfo("unkwown") instead, so I think the right fix here
is to change gin to do the same -- and this should be backpatched all the
way back.)

So it is my intention to split out the desc() functions out of their
current files, into their own file, allowing xlogdump to link against
that and not be forced to link the rest of the backend.

To solve the stringinfo problem, we would provide a separate
implementation of it, one that doesn't depend on palloc and elog.
Initially I would just put it in src/bin/xlogdump, but if people think
we could use it elsewhere, we could do that too. Alternatively we could
use a shim layer on top of PQExpBuffer. In fact, we could change the
desc() routines, so that #ifdef FRONTEND they use PQExpBuffer, and
StringInfo otherwise.

One further decision here is whether the various desc() routines should
be each in its own file, or have them all in a single file. If we use a
single file (which is what I'm inclined to do) we'd need to rename some
static routines that have the same name, such as "out_target"; but this
seems a rather trivial exercise.

Thoughts?

--
Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: splitting *_desc routines
Date: 2012-08-29 20:06:16
Message-ID: 1446.1346270776@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> writes:
> I looked at Andres' patch and the general idea is rather horrible: it
> links all backend files into the output executable. This is so that the
> *_desc functions can be used from their respective object files, which
> obviously have a lot of requirements for backend infrastructure.

Check.

> So it is my intention to split out the desc() functions out of their
> current files, into their own file, allowing xlogdump to link against
> that and not be forced to link the rest of the backend.

Meh. Can we compromise on one file per xlog rmgr? I don't much care
for the "one big file" idea.

> To solve the stringinfo problem, we would provide a separate
> implementation of it, one that doesn't depend on palloc and elog.

Shim on top of PQExpBuffer seems like the way to go.

An alternative thing that might be worth considering before you go all
in on this is whether the xlogdump functionality shouldn't just be part
of the regular server executable, ie you'd call it with

postgres --xlogdump <arguments>

and the only extra code needed is two lines for another redirect in
main.c. We've already done that for things like --describe-config.
This'd likely be a lot less work than getting the _desc routines to
be operable standalone ...

regards, tom lane


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Subject: Re: splitting *_desc routines
Date: 2012-08-30 16:14:24
Message-ID: 201208301814.24534.andres@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wednesday, August 29, 2012 10:06:16 PM Tom Lane wrote:
> Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> writes:
> > I looked at Andres' patch and the general idea is rather horrible: it
> > links all backend files into the output executable. This is so that the
> > *_desc functions can be used from their respective object files, which
> > obviously have a lot of requirements for backend infrastructure.
>
> Check.
I said it was a preliminary hack though ;). Especially the way I assembled the
object files...
The xlogdump utility itself is equally crappy atm, it was just a demonstration
which suited me enough for debugging... But it really doesn't need that much
more.

> An alternative thing that might be worth considering before you go all
> in on this is whether the xlogdump functionality shouldn't just be part
> of the regular server executable, ie you'd call it with
>
> postgres --xlogdump <arguments>
>
> and the only extra code needed is two lines for another redirect in
> main.c. We've already done that for things like --describe-config.
> This'd likely be a lot less work than getting the _desc routines to
> be operable standalone ...
It definitely would be simpler. It doesn't seem nice to pile more and more
utilities into the main postgres binary though.

Note the ugliness some the testing tools in src/backend go through just to
link to a few files... Yuck.

Andres
--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Subject: Re: splitting *_desc routines
Date: 2012-08-30 17:42:55
Message-ID: CA+TgmoZ=XPY=fxyMpSUiqvzmv0Of3yfens=c1FERC+AaDPAckQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Aug 30, 2012 at 12:14 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>> An alternative thing that might be worth considering before you go all
>> in on this is whether the xlogdump functionality shouldn't just be part
>> of the regular server executable, ie you'd call it with
>>
>> postgres --xlogdump <arguments>
>>
>> and the only extra code needed is two lines for another redirect in
>> main.c. We've already done that for things like --describe-config.
>> This'd likely be a lot less work than getting the _desc routines to
>> be operable standalone ...
> It definitely would be simpler. It doesn't seem nice to pile more and more
> utilities into the main postgres binary though.

Agreed. Another advantage of making this standalone is that other
people might then be able to write code that does interesting things
with it. If we just add the functionality into core then nobody's any
better off than before.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: splitting *_desc routines
Date: 2012-10-24 20:44:35
Message-ID: 20121024204435.GI6853@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Here's a small WIP patch that does the proposed splitting. This is a
first step towards the objective of having a separately compilable
xlogdump -- more work is needed before that can be made to work fully.

Now, per previous discussion, I have split each rmgr's desc function
into its own file. This is easiest, but it leaves us with several very
small files in some directories; for example we have

./src/backend/access/transam/clog_desc.c
./src/backend/access/transam/xact_desc.c
./src/backend/access/transam/xlog_desc.c
./src/backend/access/transam/mxact_desc.c

and also
./src/backend/commands/dbase_desc.c
./src/backend/commands/seq_desc.c
./src/backend/commands/tablespace_desc.c

Is people okay with that, or should we consider merging each subdir's
files into a single one? (say transam_desc.c and cmds_desc.c).

The other question is whether the function and struct declarations are
in the best possible locations considering that we will want the files
to be compilable without a backend environment. I am using xlogdump as
a testbed to ensure that everything is kosher (it's not yet there for
other reasons -- I might end up using something other than
xlog_internal.h, for example).

Once we settle these issues, I will finish up the patch by adding nice
file header comments and the like.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
splitdesc.patch text/x-diff 74.2 KB

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: splitting *_desc routines
Date: 2012-10-25 08:25:34
Message-ID: CA+U5nMKCGQomExp9hkt5wfViEMrJR07MZK+sLiviibvbAMDtBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 24 October 2012 21:44, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:
> Here's a small WIP patch that does the proposed splitting. This is a
> first step towards the objective of having a separately compilable
> xlogdump -- more work is needed before that can be made to work fully.
>
> Now, per previous discussion, I have split each rmgr's desc function
> into its own file. This is easiest, but it leaves us with several very
> small files in some directories; for example we have
>
> ./src/backend/access/transam/clog_desc.c
> ./src/backend/access/transam/xact_desc.c
> ./src/backend/access/transam/xlog_desc.c
> ./src/backend/access/transam/mxact_desc.c
>
> and also
> ./src/backend/commands/dbase_desc.c
> ./src/backend/commands/seq_desc.c
> ./src/backend/commands/tablespace_desc.c
>
> Is people okay with that, or should we consider merging each subdir's
> files into a single one? (say transam_desc.c and cmds_desc.c).

One file per rmgr is the right level of modularity.

I'd put these in a separate directory to avoid annoyance. Transam is
already too large.

src/backend/access/rmgrdesc/xlog_desc.c
...
src/backend/access/rmgrdesc/seq_desc.c

No difference between commands and other stuff. Just one file per
rmgr, using the rmgr name as listed in rmgr.c

> The other question is whether the function and struct declarations are
> in the best possible locations considering that we will want the files
> to be compilable without a backend environment. I am using xlogdump as
> a testbed to ensure that everything is kosher (it's not yet there for
> other reasons -- I might end up using something other than
> xlog_internal.h, for example).

--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: splitting *_desc routines
Date: 2012-10-27 02:18:54
Message-ID: CA+TgmobmW9rcYr7YCY5dqeCeA1tE7PZz+g5DiKYQS4Kq39urVw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 25, 2012 at 4:25 AM, Simon Riggs <simon(at)2ndquadrant(dot)com> wrote:
> I'd put these in a separate directory to avoid annoyance. Transam is
> already too large.

+1. A further advantage of that is that it means that that everything
in that new directory will be intended to end up as
all-separately-compilable, which should make it easier to remember
what the rules are, and easier to design an automated framework that
continuously verifies that it still works that way.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: splitting *_desc routines
Date: 2012-11-23 21:52:19
Message-ID: 20121123215219.GB4558@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas escribió:
> On Thu, Oct 25, 2012 at 4:25 AM, Simon Riggs <simon(at)2ndquadrant(dot)com> wrote:
> > I'd put these in a separate directory to avoid annoyance. Transam is
> > already too large.
>
> +1. A further advantage of that is that it means that that everything
> in that new directory will be intended to end up as
> all-separately-compilable, which should make it easier to remember
> what the rules are, and easier to design an automated framework that
> continuously verifies that it still works that way.

So incorporating these ideas, the layout now looks like this:

./commands/seq_desc.c
./commands/dbase_desc.c
./commands/tablespace_desc.c
./catalog/storage_desc.c
./utils/cache/relmap_desc.c
./access/rmgrdesc/mxact_desc.c
./access/rmgrdesc/spgdesc.c
./access/rmgrdesc/xact_desc.c
./access/rmgrdesc/heapdesc.c
./access/rmgrdesc/tupdesc.c
./access/rmgrdesc/xlog_desc.c
./access/rmgrdesc/gistdesc.c
./access/rmgrdesc/clog_desc.c
./access/rmgrdesc/hashdesc.c
./access/rmgrdesc/gindesc.c
./access/rmgrdesc/nbtdesc.c
./storage/ipc/standby_desc.c

There are two files that are two subdirs down from the backend
directory:

./storage/ipc/standby_desc.c
./utils/cache/relmap_desc.c

We could keep them in there, or we could alternatively create more
"rmgrdesc" subdirs for them, so

./storage/rmgrdesc/standby_desc.c
./utils/rmgrdesc/relmap_desc.c

This approach appears more future-proof if we ever want to create desc
routines in other subdirs in storage/ and utils/, though it's a bit
annoying to have subdirs that will only hold a single file each (and a
very tiny file to boot).

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: splitting *_desc routines
Date: 2012-11-23 22:18:00
Message-ID: 20121123221800.GC4558@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


And here's the updated patch.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
splitdesc-2.patch text/x-diff 77.6 KB

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: splitting *_desc routines
Date: 2012-11-23 22:37:31
Message-ID: CA+U5nMLwiuPAtQNk15+6h7uvGXXErkWCjazAur-k0MBFCknDqw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 23 November 2012 22:52, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:

> ./access/rmgrdesc/xact_desc.c
> ./access/rmgrdesc/heapdesc.c

Could we have either all underscores _ or none at all for the naming?

--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Simon Riggs <simon(at)2ndquadrant(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: splitting *_desc routines
Date: 2012-11-23 23:45:32
Message-ID: 27172.1353714332@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
> So incorporating these ideas, the layout now looks like this:

> ./commands/seq_desc.c
> ./commands/dbase_desc.c
> ./commands/tablespace_desc.c
> ./catalog/storage_desc.c
> ./utils/cache/relmap_desc.c
> ./access/rmgrdesc/mxact_desc.c
> ./access/rmgrdesc/spgdesc.c
> ./access/rmgrdesc/xact_desc.c
> ./access/rmgrdesc/heapdesc.c
> ./access/rmgrdesc/tupdesc.c
> ./access/rmgrdesc/xlog_desc.c
> ./access/rmgrdesc/gistdesc.c
> ./access/rmgrdesc/clog_desc.c
> ./access/rmgrdesc/hashdesc.c
> ./access/rmgrdesc/gindesc.c
> ./access/rmgrdesc/nbtdesc.c
> ./storage/ipc/standby_desc.c

FWIW, I'd vote for dumping all of these into *one* rmgrdesc directory
(which may as well be under access/ since that's where the xlog code is),
regardless of where the corresponding replay code is in the source tree.
I don't think splitting them up into half a dozen directories adds
anything except confusion. If you want, the header comment for each
file could mention where the corresponding replay code lives.

regards, tom lane


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: splitting *_desc routines
Date: 2012-11-27 16:10:22
Message-ID: 20121127161022.GJ4227@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Simon Riggs escribió:
> On 23 November 2012 22:52, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:
>
> > ./access/rmgrdesc/xact_desc.c
> > ./access/rmgrdesc/heapdesc.c
>
> Could we have either all underscores _ or none at all for the naming?

Sure, removed them all.

Tom Lane escribió:

> FWIW, I'd vote for dumping all of these into *one* rmgrdesc directory
> (which may as well be under access/ since that's where the xlog code is),
> regardless of where the corresponding replay code is in the source tree.
> I don't think splitting them up into half a dozen directories adds
> anything except confusion. If you want, the header comment for each
> file could mention where the corresponding replay code lives.

Done that way.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
splitdesc-3.patch text/x-diff 75.1 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: splitting *_desc routines
Date: 2012-11-27 16:34:38
Message-ID: 23468.1354034078@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
> Tom Lane escribi:
>> FWIW, I'd vote for dumping all of these into *one* rmgrdesc directory
>> (which may as well be under access/ since that's where the xlog code is),
>> regardless of where the corresponding replay code is in the source tree.
>> I don't think splitting them up into half a dozen directories adds
>> anything except confusion. If you want, the header comment for each
>> file could mention where the corresponding replay code lives.

> Done that way.

Looks pretty sane to me. The only thing that seems worth discussing is
whether to put the smgr-related XLOG record declarations in storage.h
as you have here, or to invent a new, more private header for them.

There are XLOG record declarations cluttering a lot of other fairly
public headers; but given that we've invented files like heapam_xlog.h
of late, maybe we should start trying to push those declarations to
less-visible spots. Or maybe it's not worth the trouble.

regards, tom lane


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: splitting *_desc routines
Date: 2012-11-27 19:54:03
Message-ID: 20121127195403.GN4227@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane escribió:
> Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
> > Tom Lane escribi:
> >> FWIW, I'd vote for dumping all of these into *one* rmgrdesc directory
> >> (which may as well be under access/ since that's where the xlog code is),
> >> regardless of where the corresponding replay code is in the source tree.
> >> I don't think splitting them up into half a dozen directories adds
> >> anything except confusion. If you want, the header comment for each
> >> file could mention where the corresponding replay code lives.
>
> > Done that way.
>
> Looks pretty sane to me. The only thing that seems worth discussing is
> whether to put the smgr-related XLOG record declarations in storage.h
> as you have here, or to invent a new, more private header for them.
>
> There are XLOG record declarations cluttering a lot of other fairly
> public headers; but given that we've invented files like heapam_xlog.h
> of late, maybe we should start trying to push those declarations to
> less-visible spots. Or maybe it's not worth the trouble.

I think it makes sense in the long term to separate things, even if we
don't go out of our ways in the current patch to clean all existing
uses. It's fairly simple for the case at hand (attached). With this
there are a couple of files that don't need storage.h anymore (only
storage_xlog.h). Not a mind-boggling change, I admit.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
splitdesc-4.patch text/x-diff 78.0 KB