From d40d34863e23bbfce2fbdc05e85b92e7ae321ecd Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 22 Sep 2006 23:20:14 +0000 Subject: [PATCH] Fix pg_locks view to call advisory locks advisory locks, while preserving backward compatibility for anyone using the old userlock code that's now on pgfoundry --- locks from that code still show as 'userlock'. --- doc/src/sgml/catalogs.sgml | 12 +++++++----- src/backend/storage/lmgr/deadlock.c | 12 ++++++++++-- src/backend/storage/lmgr/lmgr.c | 3 ++- src/backend/utils/adt/lockfuncs.c | 16 +++++++++------- src/include/storage/lock.h | 9 +++++---- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index bc5592ce74..ff4fb64bca 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -1,4 +1,4 @@ - + @@ -4890,8 +4890,9 @@ page, tuple, transactionid, - object, or - userlock + object, + userlock, or + advisory @@ -5029,14 +5030,15 @@ - User-defined locks can be acquired on keys consisting of either a single + Advisory locks can be acquired on keys consisting of either a single bigint value or two integer values. A bigint key is displayed with its high-order half in the classid column, its low-order half in the objid column, and objsubid equal to 1. Integer keys are displayed with the first key in the classid column, the second key in the objid column, and objsubid equal to 2. The actual meaning of - the keys is up to the user. + the keys is up to the user. Advisory locks are local to each database, + so the database column is meaningful for an advisory lock. diff --git a/src/backend/storage/lmgr/deadlock.c b/src/backend/storage/lmgr/deadlock.c index f75ca1da4c..de8f8fe99c 100644 --- a/src/backend/storage/lmgr/deadlock.c +++ b/src/backend/storage/lmgr/deadlock.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.42 2006/09/18 22:40:36 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.43 2006/09/22 23:20:13 tgl Exp $ * * Interface: * @@ -872,8 +872,16 @@ DescribeLockTag(StringInfo buf, const LOCKTAG *lock) lock->locktag_field1); break; case LOCKTAG_USERLOCK: + /* reserved for old contrib code, now on pgfoundry */ appendStringInfo(buf, - _("user lock [%u,%u,%u,%u]"), + _("user lock [%u,%u,%u]"), + lock->locktag_field1, + lock->locktag_field2, + lock->locktag_field3); + break; + case LOCKTAG_ADVISORY: + appendStringInfo(buf, + _("advisory lock [%u,%u,%u,%u]"), lock->locktag_field1, lock->locktag_field2, lock->locktag_field3, diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c index 4442d3909f..28e862533d 100644 --- a/src/backend/storage/lmgr/lmgr.c +++ b/src/backend/storage/lmgr/lmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.87 2006/08/18 16:09:09 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.88 2006/09/22 23:20:13 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -629,6 +629,7 @@ LockTagIsTemp(const LOCKTAG *tag) /* there are currently no non-table temp objects */ break; case LOCKTAG_USERLOCK: + case LOCKTAG_ADVISORY: /* assume these aren't temp */ break; } diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c index f7c7deca8d..a9d8b8b88f 100644 --- a/src/backend/utils/adt/lockfuncs.c +++ b/src/backend/utils/adt/lockfuncs.c @@ -6,7 +6,7 @@ * Copyright (c) 2002-2006, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.25 2006/09/18 22:40:37 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.26 2006/09/22 23:20:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -28,7 +28,8 @@ static const char *const LockTagTypeNames[] = { "tuple", "transactionid", "object", - "userlock" + "userlock", + "advisory" }; /* Working status for pg_lock_status */ @@ -181,7 +182,7 @@ pg_lock_status(PG_FUNCTION_ARGS) MemSet(values, 0, sizeof(values)); MemSet(nulls, ' ', sizeof(nulls)); - if (lock->tag.locktag_type <= LOCKTAG_USERLOCK) + if (lock->tag.locktag_type <= LOCKTAG_ADVISORY) locktypename = LockTagTypeNames[lock->tag.locktag_type]; else { @@ -238,6 +239,7 @@ pg_lock_status(PG_FUNCTION_ARGS) break; case LOCKTAG_OBJECT: case LOCKTAG_USERLOCK: + case LOCKTAG_ADVISORY: default: /* treat unknown locktags like OBJECT */ values[1] = ObjectIdGetDatum(lock->tag.locktag_field1); values[6] = ObjectIdGetDatum(lock->tag.locktag_field2); @@ -270,7 +272,7 @@ pg_lock_status(PG_FUNCTION_ARGS) /* - * Functions for manipulating USERLOCK locks + * Functions for manipulating advisory locks * * We make use of the locktag fields as follows: * @@ -280,13 +282,13 @@ pg_lock_status(PG_FUNCTION_ARGS) * field4: 1 if using an int8 key, 2 if using 2 int4 keys */ #define SET_LOCKTAG_INT64(tag, key64) \ - SET_LOCKTAG_USERLOCK(tag, \ + SET_LOCKTAG_ADVISORY(tag, \ MyDatabaseId, \ (uint32) ((key64) >> 32), \ (uint32) (key64), \ 1) #define SET_LOCKTAG_INT32(tag, key1, key2) \ - SET_LOCKTAG_USERLOCK(tag, MyDatabaseId, key1, key2, 2) + SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key1, key2, 2) /* * pg_advisory_lock(int8) - acquire exclusive lock on an int8 key @@ -511,7 +513,7 @@ pg_advisory_unlock_shared_int4(PG_FUNCTION_ARGS) } /* - * pg_advisory_unlock_all() - release all userlocks + * pg_advisory_unlock_all() - release all advisory locks */ Datum pg_advisory_unlock_all(PG_FUNCTION_ARGS) diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h index ac9a71b876..9717c3f255 100644 --- a/src/include/storage/lock.h +++ b/src/include/storage/lock.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.99 2006/09/18 22:40:40 tgl Exp $ + * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.100 2006/09/22 23:20:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -146,7 +146,8 @@ typedef enum LockTagType * pg_description, but notice that we are constraining SUBID to 16 bits. * Also, we use DB OID = 0 for shared objects such as tablespaces. */ - LOCKTAG_USERLOCK /* advisory "user" locks */ + LOCKTAG_USERLOCK, /* reserved for old contrib/userlock code */ + LOCKTAG_ADVISORY /* advisory user locks */ } LockTagType; /* @@ -220,12 +221,12 @@ typedef struct LOCKTAG (locktag).locktag_type = LOCKTAG_OBJECT, \ (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) -#define SET_LOCKTAG_USERLOCK(locktag,id1,id2,id3,id4) \ +#define SET_LOCKTAG_ADVISORY(locktag,id1,id2,id3,id4) \ ((locktag).locktag_field1 = (id1), \ (locktag).locktag_field2 = (id2), \ (locktag).locktag_field3 = (id3), \ (locktag).locktag_field4 = (id4), \ - (locktag).locktag_type = LOCKTAG_USERLOCK, \ + (locktag).locktag_type = LOCKTAG_ADVISORY, \ (locktag).locktag_lockmethodid = USER_LOCKMETHOD)