Skip to content

Commit d40d348

Browse files
committed
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'.
1 parent beca984 commit d40d348

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.133 2006/09/18 22:40:36 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.134 2006/09/22 23:20:13 tgl Exp $ -->
22
<!--
33
Documentation of the system catalogs, directed toward PostgreSQL developers
44
-->
@@ -4890,8 +4890,9 @@
48904890
<literal>page</>,
48914891
<literal>tuple</>,
48924892
<literal>transactionid</>,
4893-
<literal>object</>, or
4894-
<literal>userlock</>
4893+
<literal>object</>,
4894+
<literal>userlock</>, or
4895+
<literal>advisory</>
48954896
</entry>
48964897
</row>
48974898
<row>
@@ -5029,14 +5030,15 @@
50295030
</para>
50305031

50315032
<para>
5032-
User-defined locks can be acquired on keys consisting of either a single
5033+
Advisory locks can be acquired on keys consisting of either a single
50335034
bigint value or two integer values. A bigint key is displayed with its
50345035
high-order half in the <structfield>classid</> column, its low-order half
50355036
in the <structfield>objid</> column, and <structfield>objsubid</> equal
50365037
to 1. Integer keys are displayed with the first key in the
50375038
<structfield>classid</> column, the second key in the <structfield>objid</>
50385039
column, and <structfield>objsubid</> equal to 2. The actual meaning of
5039-
the keys is up to the user.
5040+
the keys is up to the user. Advisory locks are local to each database,
5041+
so the <structfield>database</> column is meaningful for an advisory lock.
50405042
</para>
50415043

50425044
<para>

src/backend/storage/lmgr/deadlock.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.42 2006/09/18 22:40:36 tgl Exp $
15+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.43 2006/09/22 23:20:13 tgl Exp $
1616
*
1717
* Interface:
1818
*
@@ -872,8 +872,16 @@ DescribeLockTag(StringInfo buf, const LOCKTAG *lock)
872872
lock->locktag_field1);
873873
break;
874874
case LOCKTAG_USERLOCK:
875+
/* reserved for old contrib code, now on pgfoundry */
875876
appendStringInfo(buf,
876-
_("user lock [%u,%u,%u,%u]"),
877+
_("user lock [%u,%u,%u]"),
878+
lock->locktag_field1,
879+
lock->locktag_field2,
880+
lock->locktag_field3);
881+
break;
882+
case LOCKTAG_ADVISORY:
883+
appendStringInfo(buf,
884+
_("advisory lock [%u,%u,%u,%u]"),
877885
lock->locktag_field1,
878886
lock->locktag_field2,
879887
lock->locktag_field3,

src/backend/storage/lmgr/lmgr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.87 2006/08/18 16:09:09 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.88 2006/09/22 23:20:13 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -629,6 +629,7 @@ LockTagIsTemp(const LOCKTAG *tag)
629629
/* there are currently no non-table temp objects */
630630
break;
631631
case LOCKTAG_USERLOCK:
632+
case LOCKTAG_ADVISORY:
632633
/* assume these aren't temp */
633634
break;
634635
}

src/backend/utils/adt/lockfuncs.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2002-2006, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.25 2006/09/18 22:40:37 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.26 2006/09/22 23:20:14 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -28,7 +28,8 @@ static const char *const LockTagTypeNames[] = {
2828
"tuple",
2929
"transactionid",
3030
"object",
31-
"userlock"
31+
"userlock",
32+
"advisory"
3233
};
3334

3435
/* Working status for pg_lock_status */
@@ -181,7 +182,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
181182
MemSet(values, 0, sizeof(values));
182183
MemSet(nulls, ' ', sizeof(nulls));
183184

184-
if (lock->tag.locktag_type <= LOCKTAG_USERLOCK)
185+
if (lock->tag.locktag_type <= LOCKTAG_ADVISORY)
185186
locktypename = LockTagTypeNames[lock->tag.locktag_type];
186187
else
187188
{
@@ -238,6 +239,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
238239
break;
239240
case LOCKTAG_OBJECT:
240241
case LOCKTAG_USERLOCK:
242+
case LOCKTAG_ADVISORY:
241243
default: /* treat unknown locktags like OBJECT */
242244
values[1] = ObjectIdGetDatum(lock->tag.locktag_field1);
243245
values[6] = ObjectIdGetDatum(lock->tag.locktag_field2);
@@ -270,7 +272,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
270272

271273

272274
/*
273-
* Functions for manipulating USERLOCK locks
275+
* Functions for manipulating advisory locks
274276
*
275277
* We make use of the locktag fields as follows:
276278
*
@@ -280,13 +282,13 @@ pg_lock_status(PG_FUNCTION_ARGS)
280282
* field4: 1 if using an int8 key, 2 if using 2 int4 keys
281283
*/
282284
#define SET_LOCKTAG_INT64(tag, key64) \
283-
SET_LOCKTAG_USERLOCK(tag, \
285+
SET_LOCKTAG_ADVISORY(tag, \
284286
MyDatabaseId, \
285287
(uint32) ((key64) >> 32), \
286288
(uint32) (key64), \
287289
1)
288290
#define SET_LOCKTAG_INT32(tag, key1, key2) \
289-
SET_LOCKTAG_USERLOCK(tag, MyDatabaseId, key1, key2, 2)
291+
SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key1, key2, 2)
290292

291293
/*
292294
* pg_advisory_lock(int8) - acquire exclusive lock on an int8 key
@@ -511,7 +513,7 @@ pg_advisory_unlock_shared_int4(PG_FUNCTION_ARGS)
511513
}
512514

513515
/*
514-
* pg_advisory_unlock_all() - release all userlocks
516+
* pg_advisory_unlock_all() - release all advisory locks
515517
*/
516518
Datum
517519
pg_advisory_unlock_all(PG_FUNCTION_ARGS)

src/include/storage/lock.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.99 2006/09/18 22:40:40 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.100 2006/09/22 23:20:14 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -146,7 +146,8 @@ typedef enum LockTagType
146146
* pg_description, but notice that we are constraining SUBID to 16 bits.
147147
* Also, we use DB OID = 0 for shared objects such as tablespaces.
148148
*/
149-
LOCKTAG_USERLOCK /* advisory "user" locks */
149+
LOCKTAG_USERLOCK, /* reserved for old contrib/userlock code */
150+
LOCKTAG_ADVISORY /* advisory user locks */
150151
} LockTagType;
151152

152153
/*
@@ -220,12 +221,12 @@ typedef struct LOCKTAG
220221
(locktag).locktag_type = LOCKTAG_OBJECT, \
221222
(locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
222223

223-
#define SET_LOCKTAG_USERLOCK(locktag,id1,id2,id3,id4) \
224+
#define SET_LOCKTAG_ADVISORY(locktag,id1,id2,id3,id4) \
224225
((locktag).locktag_field1 = (id1), \
225226
(locktag).locktag_field2 = (id2), \
226227
(locktag).locktag_field3 = (id3), \
227228
(locktag).locktag_field4 = (id4), \
228-
(locktag).locktag_type = LOCKTAG_USERLOCK, \
229+
(locktag).locktag_type = LOCKTAG_ADVISORY, \
229230
(locktag).locktag_lockmethodid = USER_LOCKMETHOD)
230231

231232

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy