Re: Patch: Show process IDs of processes holding a lock; show relation and tuple infos of a lock to acquire

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Christian Kruse <christian(at)2ndquadrant(dot)com>
Cc: Simon Riggs <simon(at)2ndQuadrant(dot)com>, Rajeev rastogi <rajeev(dot)rastogi(at)huawei(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch: Show process IDs of processes holding a lock; show relation and tuple infos of a lock to acquire
Date: 2014-01-22 16:17:29
Message-ID: 20140122161729.GO10723@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Christian Kruse wrote:

I think this could use some more comments -- for instance at the top of
the while loop, explain what's its purpose.

> if (deadlock_state == DS_SOFT_DEADLOCK)
> ereport(LOG,
> (errmsg("process %d avoided deadlock for %s on %s by rearranging queue order after %ld.%03d ms",
> - MyProcPid, modename, buf.data, msecs, usecs)));
> + MyProcPid, modename, buf.data, msecs, usecs),
> + (errcontext(ngettext("process owning lock: %s request queue: %s",
> + "processes owning lock: %s request queue: %s",
> + lockHoldersNum), lock_holders_sbuf.data, lock_waiters_sbuf.data))));

This ngettext() call is repeated four times in the new code, which is a
bit annoying because it's not trivial. I think you could assign the
ngettext() to a char * at the bottom of the loop, and then in the
ereport() calls use it:

char *errcxt = NULL;

while ( ... )
{
...
errcxt = ngettext("processes owning lock: ..");
}

ereport(LOG,
(errmsg("blah blah"),
errcxt != NULL ? errcontext(errcxt) : 0));

That would avoid the repetition.

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-01-22 16:21:15 WAL replay should fdatasync() segments?
Previous Message Christian Kruse 2014-01-22 16:04:42 Re: Patch: Show process IDs of processes holding a lock; show relation and tuple infos of a lock to acquire