From: | Daniel Gustafsson <daniel(at)yesql(dot)se> |
---|---|
To: | Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> |
Cc: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Optional message to user when terminating/cancelling backend |
Date: | 2017-06-21 14:42:47 |
Message-ID: | 40E2C139-B7F3-474E-A100-9C4BB64D1335@yesql.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
> On 21 Jun 2017, at 16:30, Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> wrote:
>
> On Wed, 21 Jun 2017 12:06:33 +0900
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> wrote:
>
>> On Tue, Jun 20, 2017 at 3:24 AM, Daniel Gustafsson <daniel(at)yesql(dot)se> wrote:
>>> The message is stored in a new shmem area which is checked when the session is
>>> aborted. To keep things simple a small buffer is kept per backend for the
>>> message. If deemed too costly, keeping a central buffer from which slabs are
>>> allocated can be done (but seemed rather complicated for little gain compared
>>> to the quite moderate memory spend.)
>>
>> I think that you are right to take the approach with a per-backend
>> slot. This will avoid complications related to entry removals and
>> locking issues. There would be scaling issues as well if things get
>> very signaled for a lot of backends.
>>
>> +#define MAX_CANCEL_MSG 128
>> That looks enough.
>>
>> + LWLockAcquire(BackendCancelLock, LW_EXCLUSIVE);
>> +
>> + strlcpy(slot->message, message, sizeof(slot->message));
>> + slot->len = strlen(message);
>> Why not using one spin lock per slot and save it in BackendCancelShmemStruct?
>
> +1
>
> I found an example that a spin lock is used during strlcpy in WalReceiverMain().
Yeah I agree as well, will fix.
>> + pid_t pid = PG_GETARG_INT32(0);
>> + char *msg = text_to_cstring(PG_GETARG_TEXT_PP(1));
>> +
>> + PG_RETURN_BOOL(pg_terminate_backend_internal(pid, msg));
>> It would be more solid to add some error handling for messages that
>> are too long, or at least truncate the message if too long.
>
> I agree that error handling for too long messages is needed.
> Although long messages are truncated in SetBackendCancelMessage(),
> it is better to inform users that the message they can read was
> truncated one. Or, maybe we should prohibit too long message
> is passed in pg_teminate_backend()
The message is truncated in SetBackendCancelMessage() for safety, but
pg_{cancel|terminate}_backend() could throw an error on too long message, or
warning truncation, to the caller as well. Personally I think a warning is the
appropriate response, but I don’t really have a strong opinion.
cheers ./daniel
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2017-06-21 14:44:19 | Re: UPDATE of partition key |
Previous Message | Robert Haas | 2017-06-21 14:38:00 | Re: Default Partition for Range |