Re: Use stack-allocated StringInfoData - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Use stack-allocated StringInfoData
Date
Msg-id 1032332.1762441863@sss.pgh.pa.us
Whole thread Raw
In response to Re: Use stack-allocated StringInfoData  (Álvaro Herrera <alvherre@kurilemu.de>)
List pgsql-hackers
=?utf-8?Q?=C3=81lvaro?= Herrera <alvherre@kurilemu.de> writes:
> Yeah, I came across this a few weeks ago as well.  I was thinking maybe
> we can expand the ereport() macro instead of duplicating things.  It
> looks a bit ugly and I don't think we do it anywhere else ...  I mean
> something like

> errstart(WARNING, NULL);
> if (cond)
>     errmsg( ... );
> else
>     errmsg( ... );
> // and so on
> errfinish(__FILE__, __LINE__, __func__);

> Is this too ugly to live?  (I swear I had this on a branch already, but
> can't find it right this instant.)

I really dislike exposing errstart/errfinish to calling code like
that.  I agree that check_publications_origin_tables is not pretty
as-is, but it's better than breaking open the ereport abstraction.

In the particular case at hand, it seems best to just write
two separate ereport calls for the check_table_sync and
not-check_table_sync cases, as David mentioned.  Duplicating
the errdetail_plural call is slightly annoying but it's net less
code and less surprise than what's there now.

In general, in most other places where we have conditional message
text, it's done via ?: operators within the ereport macro,
for example this decades-old bit in sysv_shmem.c:

        ereport(FATAL,
                (errmsg("could not create shared memory segment: %m"),
                 errdetail("Failed system call was shmget(key=%lu, size=%zu, 0%o).",
                           (unsigned long) memKey, size,
                           IPC_CREAT | IPC_EXCL | IPCProtection),
                 (shmget_errno == EINVAL) ?
                 errhint("This error usually means that PostgreSQL's request for a shared memory "
                         "segment exceeded your kernel's SHMMAX parameter, or possibly that "
                         "it is less than "
                         "your kernel's SHMMIN parameter.\n"
                         "The PostgreSQL documentation contains more information about shared "
                         "memory configuration.") : 0,
                 (shmget_errno == ENOMEM) ?
                 errhint("This error usually means that PostgreSQL's request for a shared "
                         "memory segment exceeded your kernel's SHMALL parameter.  You might need "
                         "to reconfigure the kernel with larger SHMALL.\n"
                         "The PostgreSQL documentation contains more information about shared "
                         "memory configuration.") : 0,
                 (shmget_errno == ENOSPC) ?
                 errhint("This error does *not* mean that you have run out of disk space.  "
                         "It occurs either if all available shared memory IDs have been taken, "
                         "in which case you need to raise the SHMMNI parameter in your kernel, "
                         "or because the system's overall limit for shared memory has been "
                         "reached.\n"
                         "The PostgreSQL documentation contains more information about shared "
                         "memory configuration.") : 0));

We could do something similar here, but I'm not convinced
it's better than just writing two ereport's.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Vaibhav Dalvi
Date:
Subject: Re: [PATCH] Add pg_get_subscription_ddl() function
Next
From: Arseniy Mukhin
Date:
Subject: Re: LISTEN/NOTIFY bug: VACUUM sets frozenxid past a xid in async queue