public inbox for [email protected]  
help / color / mirror / Atom feed
advisory locks: documentation hint and  feature request
2+ messages / 2 participants
[nested] [flat]

* advisory locks: documentation hint and  feature request
@ 2008-01-07 11:28 Marc Mamin <[email protected]>
  2008-03-06 18:50 ` Re: [GENERAL] advisory locks: documentation hint and feature request Bruce Momjian <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Marc Mamin @ 2008-01-07 11:28 UTC (permalink / raw)
  To: [email protected]

 Hello,
 
 I have defined some functions to manage advisory locks in a more
restrictive way than the default usage.
 
 here my requirements:
 
 - a session cannot stack write locks 
 - a session cannot aquire a shared lock if it already holds the write
locks
 - there is a maximum allowed shared locks (per lock id).

As I coun't find a way to count all current share locks for a given key
I also added the restriction that a given session can not get more than
one instance of a given shared lock.
This is a "strange" restriction for share locks, but this fits to our
lock usage.

 
 
doing this, I missed an information in the documentation that would be
useful to add:
 
 
pg_locks columns definition
---------------------------
 
current definition:
 
objid : OID of the object within its system catalog, 
        or NULL if the object is not a general database object
        
to add: "For advisory locks it is used to distinguish  the two key
spaces (one int8 or two int4 keys)


Table 9-56. Advisory Lock Functions (8.3 Beta)
-----------------------------------
 current: (note that these two key spaces do not overlap)
 
 to add: "; The two key spaces are separated on the column objid in the
pg_locks view"
 
 
 
 
 Moreover I missed some function that would allow a cleaner
implementation of my features 
 (reducing the need to query the pg_locks view)
 
 For example:
  
 --current shared lock count (owned / all)
 pg_advisory_lock_shared_count_my(key bigint)
 pg_advisory_lock_shared_count_all(key bigint)
 
 
 --enforce exclusive locks so that they cannot be stacked
 pg_try_advisory_lock_single(key bigint)
 
 --enforce shared locks so that they cannot be acquired if the current
session already holds the exclusive lock
I guess this should be the dafault behaviour for
   pg_advisory_lock_shared (..) and pg_try_advisory_lock_shared (...)
 
 --and possibly define a max number of allowed shared locks (over all
sessions)
 pg_[try_]advisory_lock_shared_max(key bigint, max_count int)
 
 
regards,
 
Marc Mamin
 
 
 
 


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [GENERAL] advisory locks: documentation hint and feature request
  2008-01-07 11:28 advisory locks: documentation hint and  feature request Marc Mamin <[email protected]>
@ 2008-03-06 18:50 ` Bruce Momjian <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Bruce Momjian @ 2008-03-06 18:50 UTC (permalink / raw)
  To: Marc Mamin <[email protected]>; +Cc: pgsql-docs

Marc Mamin wrote:
> doing this, I missed an information in the documentation that would be
> useful to add:
>  
>  
> pg_locks columns definition
> ---------------------------
>  
> current definition:
>  
> objid : OID of the object within its system catalog, 
>         or NULL if the object is not a general database object
>         
> to add: "For advisory locks it is used to distinguish  the two key
> spaces (one int8 or two int4 keys)
> 
> 
> Table 9-56. Advisory Lock Functions (8.3 Beta)
> -----------------------------------
>  current: (note that these two key spaces do not overlap)
>  
>  to add: "; The two key spaces are separated on the column objid in the
> pg_locks view"
>  

I have added your suggested changes to the docs with the attached patch.
Thanks.

>  Moreover I missed some function that would allow a cleaner
> implementation of my features 
>  (reducing the need to query the pg_locks view)
>  
>  For example:
>   
>  --current shared lock count (owned / all)
>  pg_advisory_lock_shared_count_my(key bigint)
>  pg_advisory_lock_shared_count_all(key bigint)
>  
>  
>  --enforce exclusive locks so that they cannot be stacked
>  pg_try_advisory_lock_single(key bigint)

Sorry, I am afraid they would not have general-enough usefulness.

-- 
  Bruce Momjian  <[email protected]>        http://momjian.us
  EnterpriseDB                             http://postgres.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +


Attachments:

  [text/x-diff] /rtmp/diff (2.3K, 2-%2Frtmp%2Fdiff)
  download | inline diff:
Index: doc/src/sgml/catalogs.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v
retrieving revision 2.161
diff -c -c -r2.161 catalogs.sgml
*** doc/src/sgml/catalogs.sgml	31 Jan 2008 18:40:02 -0000	2.161
--- doc/src/sgml/catalogs.sgml	6 Mar 2008 18:48:54 -0000
***************
*** 5691,5697 ****
        <entry>any OID column</entry>
        <entry>
         OID of the object within its system catalog, or NULL if the
!        object is not a general database object
        </entry>
       </row>
       <row>
--- 5691,5700 ----
        <entry>any OID column</entry>
        <entry>
         OID of the object within its system catalog, or NULL if the
!        object is not a general database object.
!        For advisory locks it is used to distinguish the two key
!        spaces (<literal>1</> for an int8 key, <literal>2</> for two
!        int4 keys).
        </entry>
       </row>
       <row>
Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.422
diff -c -c -r1.422 func.sgml
*** doc/src/sgml/func.sgml	3 Mar 2008 18:09:02 -0000	1.422
--- doc/src/sgml/func.sgml	6 Mar 2008 18:48:58 -0000
***************
*** 12378,12384 ****
     <para>
      <function>pg_advisory_lock</> locks an application-defined resource,
      which can be identified either by a single 64-bit key value or two
!     32-bit key values (note that these two key spaces do not overlap).  If
      another session already holds a lock on the same resource, the
      function will wait until the resource becomes available.  The lock
      is exclusive.  Multiple lock requests stack, so that if the same resource
--- 12378,12385 ----
     <para>
      <function>pg_advisory_lock</> locks an application-defined resource,
      which can be identified either by a single 64-bit key value or two
!     32-bit key values (note that these two key spaces do not overlap). 
!     The key type is specified in <literal>pg_locks.objid</>.  If
      another session already holds a lock on the same resource, the
      function will wait until the resource becomes available.  The lock
      is exclusive.  Multiple lock requests stack, so that if the same resource


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2008-03-06 18:50 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-01-07 11:28 advisory locks: documentation hint and  feature request Marc Mamin <[email protected]>
2008-03-06 18:50 ` Re: [GENERAL] advisory locks: documentation hint and feature request Bruce Momjian <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox