Re: [PATCHES] NO WAIT ...

Поиск
Список
Период
Сортировка
От Tatsuo Ishii
Тема Re: [PATCHES] NO WAIT ...
Дата
Msg-id 20040309.215315.71084669.t-ishii@sra.co.jp
обсуждение исходный текст
Ответ на Re: [PATCHES] NO WAIT ...  (Tatsuo Ishii <t-ishii@sra.co.jp>)
Ответы Re: [PATCHES] NO WAIT ...  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Here is the patch I promised (against current). Regression tests all
passed. One thing I have not checked is the doc(lock.sgml). For some
reason I failed to install docbook V4.2 (I have working docbook V3.1
though), and I couldn't test the correctness of the file. Also, it
would be nice if some one checks my English grammer:-)
--
Tatsuo Ishii

> It seems "NOWAIT" is the winner...
> --
> Tatsuo Ishii
> 
> > Oracle uses "NOWAIT" so we should go for that one.
> >     
> >     Regards,
> > 
> >         Hans
> > 
> > 
> > 
> > Tatsuo Ishii wrote:
> > > If "NOWAIT" is the choice, I could live with it. If there's no
> > > objection, I will go with "NOWAIT", not "NO WAIT".
> > > --
> > > Tatsuo Ishii
> > > 
> > > 
> > >>Tatsuo Ishii <t-ishii@sra.co.jp> writes:
> > >>
> > >>>LOCK TABLE table NO WAIT is OK for 7.5? If ok, I will make patches
> > >>>against current with some docs changes.
> > >>
> > >>Dept of minor gripes: can we do this without turning "NO" into a
> > >>keyword?  Even as a nonreserved word, I think that would be annoying.
> > >>"no" is a common abbreviation for "number" so I think it's likely to
> > >>get used as a column name.
> > >>
> > >>If Oracle spells it "NOWAIT" then I'd be much happier with that...
> > >>
> > >>            regards, tom lane
> > >>
> > > 
> > > 
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 6: Have you searched our list archives?
> > > 
> > >                http://archives.postgresql.org
> > 
> > 
> > -- 
> > Cybertec Geschwinde u Schoenig
> > Schoengrabern 134, A-2020 Hollabrunn, Austria
> > Tel: +43/2952/30706 or +43/664/233 90 75
> > www.cybertec.at, www.postgresql.at, kernel.cybertec.at
> > 
> > 
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: Have you checked our extensive FAQ?
> > 
> >                http://www.postgresql.org/docs/faqs/FAQ.html
> > 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
Index: doc/src/sgml/ref/lock.sgml
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/ref/lock.sgml,v
retrieving revision 1.40
diff -c -r1.40 lock.sgml
*** doc/src/sgml/ref/lock.sgml    14 Dec 2003 00:05:29 -0000    1.40
--- doc/src/sgml/ref/lock.sgml    9 Mar 2004 12:42:31 -0000
***************
*** 20,26 ****   <refsynopsisdiv> <synopsis>
! LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ IN <replaceable
class="PARAMETER">lockmode</replaceable>MODE ]  where <replaceable class="PARAMETER">lockmode</replaceable> is one of:

--- 20,26 ----   <refsynopsisdiv> <synopsis>
! LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ IN <replaceable
class="PARAMETER">lockmode</replaceable>MODE ] [ NOWAIT ]  where <replaceable class="PARAMETER">lockmode</replaceable>
isone of: 
 
***************
*** 34,41 ****    <para>    <command>LOCK TABLE</command> obtains a table-level lock, waiting if
!    necessary for any conflicting locks to be released.  Once obtained,
!    the lock is held for the remainder of the current transaction.    (There is no <command>UNLOCK TABLE</command>
command;locks are always    released at transaction end.)   </para>
 
--- 34,43 ----    <para>    <command>LOCK TABLE</command> obtains a table-level lock, waiting if
!    necessary for any conflicting locks to be released.
!    If <literal>NOWAIT</literal> is given, <command>LOCK TABLE</command>
!    does not wait for acquiring lock, and throws an error instead.
!    Once obtained, the lock is held for the remainder of the current transaction.    (There is no <command>UNLOCK
TABLE</command>command; locks are always    released at transaction end.)   </para>
 
Index: src/backend/access/heap/heapam.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/access/heap/heapam.c,v
retrieving revision 1.162
diff -c -r1.162 heapam.c
*** src/backend/access/heap/heapam.c    16 Jan 2004 20:51:30 -0000    1.162
--- src/backend/access/heap/heapam.c    9 Mar 2004 12:42:33 -0000
***************
*** 464,469 ****
--- 464,496 ----     return r; } 
+ Relation
+ conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait)
+ {
+     Relation    r;
+ 
+     Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES);
+ 
+     /* The relcache does all the real work... */
+     r = RelationIdGetRelation(relationId);
+ 
+     if (!RelationIsValid(r))
+         elog(ERROR, "could not open relation with OID %u", relationId);
+ 
+     if (lockmode != NoLock)
+     {
+         if (nowait)
+         {
+             if (!ConditionalLockRelation(r, lockmode))
+                 elog(ERROR, "could not aquire relation lock");
+         }
+         else
+             LockRelation(r, lockmode);
+     }
+ 
+     return r;
+ }
+  /* ----------------  *        relation_openrv - open any relation specified by a RangeVar  *
Index: src/backend/commands/lockcmds.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/commands/lockcmds.c,v
retrieving revision 1.8
diff -c -r1.8 lockcmds.c
*** src/backend/commands/lockcmds.c    29 Nov 2003 19:51:47 -0000    1.8
--- src/backend/commands/lockcmds.c    9 Mar 2004 12:42:34 -0000
***************
*** 59,65 ****             aclcheck_error(aclresult, ACL_KIND_CLASS,                            get_rel_name(reloid));

!         rel = relation_open(reloid, lockstmt->mode);          /* Currently, we only allow plain tables to be locked
*/        if (rel->rd_rel->relkind != RELKIND_RELATION)
 
--- 59,65 ----             aclcheck_error(aclresult, ACL_KIND_CLASS,                            get_rel_name(reloid));

!         rel = conditional_relation_open(reloid, lockstmt->mode, lockstmt->nowait);          /* Currently, we only
allowplain tables to be locked */         if (rel->rd_rel->relkind != RELKIND_RELATION)
 
Index: src/backend/parser/gram.y
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/parser/gram.y,v
retrieving revision 2.447
diff -c -r2.447 gram.y
*** src/backend/parser/gram.y    9 Mar 2004 05:05:41 -0000    2.447
--- src/backend/parser/gram.y    9 Mar 2004 12:42:37 -0000
***************
*** 169,174 ****
--- 169,175 ---- %type <ival>    opt_lock lock_type cast_context %type <boolean>    opt_force opt_or_replace
transaction_access_mode                opt_grant_grant_option opt_revoke_grant_option
 
+                 opt_nowait  %type <boolean>    like_including_defaults 
***************
*** 375,381 ****     MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE      NAMES NATIONAL NATURAL NCHAR NEW NEXT NO
NOCREATEDB
!     NOCREATEUSER NONE NOT NOTHING NOTIFY NOTNULL NULL_P     NULLIF NUMERIC      OBJECT_P OF OFF OFFSET OIDS OLD ON
ONLYOPERATOR OPTION OR
 
--- 376,382 ----     MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE      NAMES NATIONAL NATURAL NCHAR NEW NEXT NO
NOCREATEDB
!     NOCREATEUSER NONE NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P     NULLIF NUMERIC      OBJECT_P OF OFF OFFSET OIDS
OLDON ONLY OPERATOR OPTION OR
 
***************
*** 4347,4358 ****                 }         ; 
! LockStmt:    LOCK_P opt_table qualified_name_list opt_lock                 {                     LockStmt *n =
makeNode(LockStmt);                     n->relations = $3;                     n->mode = $4;                     $$ =
(Node*)n;                 }         ;
 
--- 4348,4360 ----                 }         ; 
! LockStmt:    LOCK_P opt_table qualified_name_list opt_lock opt_nowait                 {                     LockStmt
*n= makeNode(LockStmt);                      n->relations = $3;                     n->mode = $4;
 
+                     n->nowait = $5;                     $$ = (Node *)n;                 }         ;
***************
*** 4369,4374 ****
--- 4371,4380 ----             | SHARE ROW EXCLUSIVE            { $$ = ShareRowExclusiveLock; }             | EXCLUSIVE
                      { $$ = ExclusiveLock; }             | ACCESS EXCLUSIVE                { $$ = AccessExclusiveLock;
}
+         ;
+ 
+ opt_nowait:    NOWAIT             { $$ = TRUE; }
+             | /*EMPTY*/                        { $$ = FALSE; }         ;  
Index: src/backend/parser/keywords.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/parser/keywords.c,v
retrieving revision 1.146
diff -c -r1.146 keywords.c
*** src/backend/parser/keywords.c    9 Mar 2004 05:05:41 -0000    1.146
--- src/backend/parser/keywords.c    9 Mar 2004 12:42:37 -0000
***************
*** 213,218 ****
--- 213,219 ----     {"nothing", NOTHING},     {"notify", NOTIFY},     {"notnull", NOTNULL},
+     {"nowait", NOWAIT},     {"null", NULL_P},     {"nullif", NULLIF},     {"numeric", NUMERIC},
Index: src/include/access/heapam.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/access/heapam.h,v
retrieving revision 1.86
diff -c -r1.86 heapam.h
*** src/include/access/heapam.h    29 Nov 2003 22:40:55 -0000    1.86
--- src/include/access/heapam.h    9 Mar 2004 12:42:38 -0000
***************
*** 129,134 ****
--- 129,135 ---- /* heapam.c */  extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
+ extern Relation conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait); extern Relation
relation_openrv(constRangeVar *relation, LOCKMODE lockmode); extern Relation relation_openr(const char
*sysRelationName,LOCKMODE lockmode); extern void relation_close(Relation relation, LOCKMODE lockmode);
 
Index: src/include/nodes/parsenodes.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/nodes/parsenodes.h,v
retrieving revision 1.253
diff -c -r1.253 parsenodes.h
*** src/include/nodes/parsenodes.h    14 Jan 2004 23:01:55 -0000    1.253
--- src/include/nodes/parsenodes.h    9 Mar 2004 12:42:39 -0000
***************
*** 1619,1624 ****
--- 1619,1625 ----     NodeTag        type;     List       *relations;        /* relations to lock */     int
mode;            /* lock mode */
 
+     bool        nowait;        /* no wait mode */ } LockStmt;  /* ----------------------

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: PITR Functional Design v2 for 7.5
Следующее
От: Robert Treat
Дата:
Сообщение: Re: raising the default default_statistics_target