Widen the nLocks counts in local lock tables from int to int64. This

forestalls potential overflow when the same table (or other object, but
usually tables) is accessed by very many successive queries within a single
transaction.  Per report from Michael Milligan.

Back-patch to 8.0, which is as far back as the patch conveniently applies.
There have been no reports of overflow in pre-8.3 releases, but clearly the
risk existed all along.  (Michael's report suggests that 8.3 may consume lock
counts faster than prior releases, but with no test case to look at it's hard
to be sure about that.  Widening the counts seems a good future-proofing
measure in any event.)
This commit is contained in:
Tom Lane 2008-09-16 01:56:26 +00:00
parent 8948ee37e5
commit 30df79a70b

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.113 2008/05/12 00:00:54 alvherre Exp $ * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.114 2008/09/16 01:56:26 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -391,7 +391,7 @@ typedef struct LOCALLOCKOWNER
* Must use a forward struct reference to avoid circularity. * Must use a forward struct reference to avoid circularity.
*/ */
struct ResourceOwnerData *owner; struct ResourceOwnerData *owner;
int nLocks; /* # of times held by this owner */ int64 nLocks; /* # of times held by this owner */
} LOCALLOCKOWNER; } LOCALLOCKOWNER;
typedef struct LOCALLOCK typedef struct LOCALLOCK
@ -403,7 +403,7 @@ typedef struct LOCALLOCK
LOCK *lock; /* associated LOCK object in shared mem */ LOCK *lock; /* associated LOCK object in shared mem */
PROCLOCK *proclock; /* associated PROCLOCK object in shmem */ PROCLOCK *proclock; /* associated PROCLOCK object in shmem */
uint32 hashcode; /* copy of LOCKTAG's hash value */ uint32 hashcode; /* copy of LOCKTAG's hash value */
int nLocks; /* total number of times lock is held */ int64 nLocks; /* total number of times lock is held */
int numLockOwners; /* # of relevant ResourceOwners */ int numLockOwners; /* # of relevant ResourceOwners */
int maxLockOwners; /* allocated size of array */ int maxLockOwners; /* allocated size of array */
LOCALLOCKOWNER *lockOwners; /* dynamically resizable array */ LOCALLOCKOWNER *lockOwners; /* dynamically resizable array */