Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4c5e810

Browse files
committed
Code review for NOWAIT patch: downgrade NOWAIT from fully reserved keyword
to unreserved keyword, use ereport not elog, assign a separate error code for 'could not obtain lock' so that applications will be able to detect that case cleanly.
1 parent 392b187 commit 4c5e810

File tree

6 files changed

+29
-9
lines changed

6 files changed

+29
-9
lines changed

doc/src/sgml/errcodes.sgml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/errcodes.sgml,v 1.8 2004/08/24 00:06:50 neilc Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/errcodes.sgml,v 1.9 2004/10/01 16:39:46 tgl Exp $ -->
22

33
<appendix id="errcodes-appendix">
44
<title><productname>PostgreSQL</productname> Error Codes</title>
@@ -1099,6 +1099,11 @@
10991099
<entry>CANT CHANGE RUNTIME PARAM</entry>
11001100
</row>
11011101

1102+
<row>
1103+
<entry><literal>55P03</literal></entry>
1104+
<entry>LOCK NOT AVAILABLE</entry>
1105+
</row>
1106+
11021107

11031108
<row>
11041109
<entry>Class 57</entry>

doc/src/sgml/ref/lock.sgml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/lock.sgml,v 1.42 2004/03/12 00:52:23 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/lock.sgml,v 1.43 2004/10/01 16:39:47 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -37,7 +37,7 @@ where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
3737
if necessary for any conflicting locks to be released. If
3838
<literal>NOWAIT</literal> is specified, <command>LOCK
3939
TABLE</command> does not wait to acquire the desired lock: if it
40-
cannot be immediately acquired, the transaction is aborted and an
40+
cannot be acquired immediately, the command is aborted and an
4141
error is emitted. Once obtained, the lock is held for the
4242
remainder of the current transaction. (There is no <command>UNLOCK
4343
TABLE</command> command; locks are always released at transaction

src/backend/access/heap/heapam.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.176 2004/09/17 18:09:55 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.177 2004/10/01 16:39:54 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -465,6 +465,13 @@ relation_open(Oid relationId, LOCKMODE lockmode)
465465
return r;
466466
}
467467

468+
/* ----------------
469+
* conditional_relation_open - open with option not to wait
470+
*
471+
* As above, but if nowait is true, then throw an error rather than
472+
* waiting when the lock is not immediately obtainable.
473+
* ----------------
474+
*/
468475
Relation
469476
conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait)
470477
{
@@ -483,7 +490,10 @@ conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait)
483490
if (nowait)
484491
{
485492
if (!ConditionalLockRelation(r, lockmode))
486-
elog(ERROR, "could not acquire relation lock");
493+
ereport(ERROR,
494+
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
495+
errmsg("could not obtain lock on \"%s\"",
496+
RelationGetRelationName(r))));
487497
}
488498
else
489499
LockRelation(r, lockmode);

src/backend/parser/gram.y

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.477 2004/09/30 00:24:20 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.478 2004/10/01 16:39:59 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -7727,6 +7727,7 @@ unreserved_keyword:
77277727
| NOCREATEUSER
77287728
| NOTHING
77297729
| NOTIFY
7730+
| NOWAIT
77307731
| OBJECT_P
77317732
| OF
77327733
| OIDS
@@ -7944,7 +7945,6 @@ reserved_keyword:
79447945
| LOCALTIMESTAMP
79457946
| NEW
79467947
| NOT
7947-
| NOWAIT
79487948
| NULL_P
79497949
| OFF
79507950
| OFFSET

src/include/utils/errcodes.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* Copyright (c) 2003, PostgreSQL Global Development Group
1313
*
14-
* $PostgreSQL: pgsql/src/include/utils/errcodes.h,v 1.15 2004/08/29 05:06:58 momjian Exp $
14+
* $PostgreSQL: pgsql/src/include/utils/errcodes.h,v 1.16 2004/10/01 16:40:04 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -308,6 +308,7 @@
308308
#define ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE MAKE_SQLSTATE('5','5', '0','0','0')
309309
#define ERRCODE_OBJECT_IN_USE MAKE_SQLSTATE('5','5', '0','0','6')
310310
#define ERRCODE_CANT_CHANGE_RUNTIME_PARAM MAKE_SQLSTATE('5','5', 'P','0','2')
311+
#define ERRCODE_LOCK_NOT_AVAILABLE MAKE_SQLSTATE('5','5', 'P','0','3')
311312

312313
/* Class 57 - Operator Intervention (class borrowed from DB2) */
313314
#define ERRCODE_OPERATOR_INTERVENTION MAKE_SQLSTATE('5','7', '0','0','0')

src/pl/plpgsql/src/plerrcodes.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Copyright (c) 2003, PostgreSQL Global Development Group
1111
*
12-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plerrcodes.h,v 1.4 2004/08/29 05:07:01 momjian Exp $
12+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plerrcodes.h,v 1.5 2004/10/01 16:40:05 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -659,6 +659,10 @@
659659
"cant_change_runtime_param", ERRCODE_CANT_CHANGE_RUNTIME_PARAM
660660
},
661661

662+
{
663+
"lock_not_available", ERRCODE_LOCK_NOT_AVAILABLE
664+
},
665+
662666
{
663667
"operator_intervention", ERRCODE_OPERATOR_INTERVENTION
664668
},

0 commit comments

Comments
 (0)