Re: Support for XLogRecPtr in expand_fmt_string?

Lists: pgsql-hackers
From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-03 17:35:47
Message-ID: 201207031935.47901.andres@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

I wonder if we just should add a format code like %R or something similar as a
replacement for the %X/%X notion. Having to type something like "(uint32)
(state->curptr >> 32), (uint32)state->curptr" everywhere is somewhat annoying.

Opinions?

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-03 18:09:40
Message-ID: 11194.1341338980@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> I wonder if we just should add a format code like %R or something similar as a
> replacement for the %X/%X notion.

Only if you can explain how to teach gcc what it means for elog argument
match checking. %m is a special case in that it matches up with a
longstanding glibc-ism that gcc knows about. Adding format codes of our
own invention would be problematic.

> Having to type something like "(uint32)
> (state->curptr >> 32), (uint32)state->curptr" everywhere is somewhat annoying.

If we really feel this is worth doing something about, we could invent a
formatting subroutine that converts XLogRecPtr to string (and then we
just use %s in the messages).

regards, tom lane


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-03 18:45:51
Message-ID: 1341341151.21530.22.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tis, 2012-07-03 at 19:35 +0200, Andres Freund wrote:
> I wonder if we just should add a format code like %R or something similar as a
> replacement for the %X/%X notion. Having to type something like "(uint32)
> (state->curptr >> 32), (uint32)state->curptr" everywhere is somewhat annoying.

Maybe just print it as a single 64-bit value from now on.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-03 18:52:51
Message-ID: 12050.1341341571@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> On tis, 2012-07-03 at 19:35 +0200, Andres Freund wrote:
>> I wonder if we just should add a format code like %R or something similar as a
>> replacement for the %X/%X notion.

> Maybe just print it as a single 64-bit value from now on.

That'd be problematic also, because of the lack of standardization of
the format code for uint64. We could write things like
"message... " UINT64_FORMAT " ...more message"
but I wonder how well the translation tools would work with that;
and anyway it would at least double the translation effort for
messages containing such things.

regards, tom lane


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-03 18:59:00
Message-ID: 201207032059.00518.andres@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tuesday, July 03, 2012 08:09:40 PM Tom Lane wrote:
> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> > I wonder if we just should add a format code like %R or something similar
> > as a replacement for the %X/%X notion.
> Only if you can explain how to teach gcc what it means for elog argument
> match checking. %m is a special case in that it matches up with a
> longstanding glibc-ism that gcc knows about. Adding format codes of our
> own invention would be problematic.
Ah. Yes. That kills the idea.

> > Having to type something like "(uint32)
> > (state->curptr >> 32), (uint32)state->curptr" everywhere is somewhat
> > annoying.
> If we really feel this is worth doing something about, we could invent a
> formatting subroutine that converts XLogRecPtr to string (and then we
> just use %s in the messages).
I think that would make memory management annoying. Using a static buffer
isn't going to work very well either because its valid to pass two recptr's to
elog/ereport/....

I think at that point the current state is not worth the hassle, sorry for the
noise.

Greetings,

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-03 19:10:31
Message-ID: 12449.1341342631@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg토토 사이트SQL

Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> On Tuesday, July 03, 2012 08:09:40 PM Tom Lane wrote:
>> If we really feel this is worth doing something about, we could invent a
>> formatting subroutine that converts XLogRecPtr to string (and then we
>> just use %s in the messages).

> I think that would make memory management annoying. Using a static buffer
> isn't going to work very well either because its valid to pass two recptr's to
> elog/ereport/....

Hm. I was assuming that we could probably get away with the
static-buffer trick, but if you think not ...

One possibility is to make call sites that need this pass local-variable
buffers to the formatting subroutine:

char xrp_buffer[XLOGRECPTR_BUF_LEN];
char xrp_buffer2[XLOGRECPTR_BUF_LEN];

ereport(....,
format_xlogrecptr(xrp_buffer, xlogval1),
format_xlogrecptr(xrp_buffer2, xlogval2));

but it may not be worth the trouble.

regards, tom lane


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-06 22:03:19
Message-ID: 1341612199.7092.36.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tis, 2012-07-03 at 14:52 -0400, Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > On tis, 2012-07-03 at 19:35 +0200, Andres Freund wrote:
> >> I wonder if we just should add a format code like %R or something similar as a
> >> replacement for the %X/%X notion.
>
> > Maybe just print it as a single 64-bit value from now on.
>
> That'd be problematic also, because of the lack of standardization of
> the format code for uint64. We could write things like
> "message... " UINT64_FORMAT " ...more message"
> but I wonder how well the translation tools would work with that;
> and anyway it would at least double the translation effort for
> messages containing such things.

The existing uses of INT64_FORMAT and UINT64_FORMAT show how this is
done: You print the value in a temporary buffer and use %s in the final
string. It's not terribly pretty, but it's been done this way forever,
including in xlog code, so there shouldn't be a reason to hesitate about
the use for this particular case.


From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-12 07:13:21
Message-ID: 4FFE7911.60208@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 07.07.2012 01:03, Peter Eisentraut wrote:
> On tis, 2012-07-03 at 14:52 -0400, Tom Lane wrote:
>> Peter Eisentraut<peter_e(at)gmx(dot)net> writes:
>>> On tis, 2012-07-03 at 19:35 +0200, Andres Freund wrote:
>>>> I wonder if we just should add a format code like %R or something similar as a
>>>> replacement for the %X/%X notion.
>>
>>> Maybe just print it as a single 64-bit value from now on.
>>
>> That'd be problematic also, because of the lack of standardization of
>> the format code for uint64. We could write things like
>> "message... " UINT64_FORMAT " ...more message"
>> but I wonder how well the translation tools would work with that;
>> and anyway it would at least double the translation effort for
>> messages containing such things.
>
> The existing uses of INT64_FORMAT and UINT64_FORMAT show how this is
> done: You print the value in a temporary buffer and use %s in the final
> string. It's not terribly pretty, but it's been done this way forever,
> including in xlog code, so there shouldn't be a reason to hesitate about
> the use for this particular case.

That's hardly any simpler than what we have now.

On 03.07.2012 21:09, Tom Lane wrote:
> Andres Freund<andres(at)2ndquadrant(dot)com> writes:
>> I wonder if we just should add a format code like %R or something
similar as a
>> replacement for the %X/%X notion.
>
> Only if you can explain how to teach gcc what it means for elog argument
> match checking. %m is a special case in that it matches up with a
> longstanding glibc-ism that gcc knows about. Adding format codes of our
> own invention would be problematic.

One idea would be to use a macro, like this:

#define XLOGRECPTR_FMT_ARGS(recptr) (uint32) ((recptr) >> 32), (uint32)
(recptr)

elog(LOG, "current WAL location is %X/%X", XLOGRECPTR_FMT_ARGS(RecPtr));

One downside is that at first glance, that elog() looks broken, because
the number of arguments don't appear to match the format string.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-13 19:34:35
Message-ID: 1342208075.23760.1.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tor, 2012-07-12 at 10:13 +0300, Heikki Linnakangas wrote:
> One idea would be to use a macro, like this:
>
> #define XLOGRECPTR_FMT_ARGS(recptr) (uint32) ((recptr) >> 32),
> (uint32)
> (recptr)
>
> elog(LOG, "current WAL location is %X/%X",
> XLOGRECPTR_FMT_ARGS(RecPtr));
>
I would rather get rid of this %X/%X notation. I know we have all grown
to like it, but it's always been a workaround. We're now making the
move to simplify this whole business by saying, the WAL location is an
unsigned 64-bit number -- which everyone can understand -- but then why
is it printed in some funny format?


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-13 19:47:56
Message-ID: 20120713194756.GD15443@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jul 13, 2012 at 10:34:35PM +0300, Peter Eisentraut wrote:
> On tor, 2012-07-12 at 10:13 +0300, Heikki Linnakangas wrote:
> > One idea would be to use a macro, like this:
> >
> > #define XLOGRECPTR_FMT_ARGS(recptr) (uint32) ((recptr) >> 32),
> > (uint32)
> > (recptr)
> >
> > elog(LOG, "current WAL location is %X/%X",
> > XLOGRECPTR_FMT_ARGS(RecPtr));
> >
> I would rather get rid of this %X/%X notation. I know we have all grown
> to like it, but it's always been a workaround. We're now making the
> move to simplify this whole business by saying, the WAL location is an
> unsigned 64-bit number -- which everyone can understand -- but then why
> is it printed in some funny format?

+1

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-13 20:01:55
Message-ID: 23720.1342209715@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> On Fri, Jul 13, 2012 at 10:34:35PM +0300, Peter Eisentraut wrote:
>> I would rather get rid of this %X/%X notation.

> +1

I'm for it if we can find a less messy way of dealing with the
platform-specific-format-code issue. I don't want to be plugging
UINT64_FORMAT into string literals in a pile of places.

Personally I think that a function returning a static string
buffer is probably good enough for this. If there are places
where we need to print more than one XLogRecPtr value in a message,
we could have two of them. (Yeah, it's ugly, but less so than
dealing with platform-specific format codes everywhere.)

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Support for XLogRecPtr in expand_fmt_string?
Date: 2012-07-14 17:29:25
Message-ID: 31B790A5-9357-430F-B402-D71C76EE11AA@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Jul 13, 2012, at 2:34 PM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> I would rather get rid of this %X/%X notation. I know we have all grown
> to like it, but it's always been a workaround. We're now making the
> move to simplify this whole business by saying, the WAL location is an
> unsigned 64-bit number -- which everyone can understand -- but then why
> is it printed in some funny format?

We should take care that whatever format we pick can be easily matched to a WAL file name. So a 64-bit number printed as 16 hex digits would perhaps be OK, but a 64-bit number printed in base 10 would be a large usability regression.

Personally, I'm not convinced we should change anything at all. It's not that easy to visually parse a string of many digits; a little punctuation in the middle is not a bad thing.

...Robert