Re: Patch: Show process IDs of processes holding a lock; show relation and tuple infos of a lock to acquire - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Patch: Show process IDs of processes holding a lock; show relation and tuple infos of a lock to acquire
Date
Msg-id 20140122161729.GO10723@eldon.alvh.no-ip.org
Whole thread Raw
In response to Re: Patch: Show process IDs of processes holding a lock; show relation and tuple infos of a lock to acquire  (Christian Kruse <christian@2ndquadrant.com>)
Responses Re: Patch: Show process IDs of processes holding a lock; show relation and tuple infos of a lock to acquire
List 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



pgsql-hackers by date:

Previous
From: Christian Kruse
Date:
Subject: Re: Patch: Show process IDs of processes holding a lock; show relation and tuple infos of a lock to acquire
Next
From: Andres Freund
Date:
Subject: WAL replay should fdatasync() segments?