1- $PostgreSQL: pgsql/src/backend/storage/lmgr/README,v 1.14 2003/11/29 19:51:56 pgsql Exp $
1+ $PostgreSQL: pgsql/src/backend/storage/lmgr/README,v 1.15 2004/08/27 17:07:41 tgl Exp $
22
33
44LOCKING OVERVIEW
@@ -47,19 +47,27 @@ The rest of this README file discusses the regular lock manager in detail.
4747
4848LOCK DATA STRUCTURES
4949
50- There are two fundamental lock structures: the per-lockable-object LOCK
51- struct, and the per-lock PROCLOCK struct. A LOCK object exists
52- for each lockable object that currently has locks held or requested on it.
53- A PROCLOCK struct exists for each transaction that is holding or requesting
54- lock(s) on each LOCK object.
55-
5650Lock methods describe the overall locking behavior. Currently there are
5751two lock methods: DEFAULT and USER. (USER locks are non-blocking.)
5852
5953Lock modes describe the type of the lock (read/write or shared/exclusive).
6054See src/tools/backend/index.html and src/include/storage/lock.h for more
6155details.
6256
57+ There are two fundamental lock structures in shared memory: the
58+ per-lockable-object LOCK struct, and the per-lock-and-requestor PROCLOCK
59+ struct. A LOCK object exists for each lockable object that currently has
60+ locks held or requested on it. A PROCLOCK struct exists for each transaction
61+ that is holding or requesting lock(s) on each LOCK object.
62+
63+ In addition to these, each backend maintains an unshared LOCALLOCK structure
64+ for each lockable object and lock mode that it is currently holding or
65+ requesting. The shared lock structures only allow a single lock grant to
66+ be made per lockable object/lock mode/transaction. Internally to a backend,
67+ however, the same lock may be requested and perhaps released multiple times
68+ in a transaction. The internal request counts are held in LOCALLOCK so that
69+ the shared LockMgrLock need not be obtained to alter them.
70+
6371---------------------------------------------------------------------------
6472
6573The lock manager's LOCK objects contain:
@@ -103,7 +111,7 @@ waitMask -
103111 This bitmask shows the types of locks being waited for. Bit i of waitMask
104112 is 1 if and only if requested[i] > granted[i].
105113
106- lockHolders -
114+ procLocks -
107115 This is a shared memory queue of all the PROCLOCK structs associated with
108116 the lock object. Note that both granted and waiting PROCLOCKs are in this
109117 list (indeed, the same PROCLOCK might have some already-granted locks and
@@ -120,7 +128,10 @@ nRequested -
120128 acquired. The count includes attempts by processes which were put
121129 to sleep due to conflicts. It also counts the same backend twice
122130 if, for example, a backend process first acquires a read and then
123- acquires a write, or acquires a read lock twice.
131+ acquires a write, or acquires the lock under two different transaction
132+ IDs. (But multiple acquisitions of the same lock/lock mode under the
133+ same transaction ID are not multiply counted here; they are recorded
134+ only in the backend's LOCALLOCK structure.)
124135
125136requested -
126137 Keeps a count of how many locks of each type have been attempted. Only
@@ -130,9 +141,8 @@ requested -
130141
131142nGranted -
132143 Keeps count of how many times this lock has been successfully acquired.
133- This count does not include attempts that are waiting due to conflicts,
134- but can count the same backend twice (e.g. a read then a write -- since
135- its the same transaction this won't cause a conflict).
144+ This count does not include attempts that are waiting due to conflicts.
145+ Otherwise the counting rules are the same as for nRequested.
136146
137147granted -
138148 Keeps count of how many locks of each type are currently held. Once again
@@ -164,18 +174,17 @@ tag -
164174 if the PROCLOCK is for session-level locking.
165175
166176 Note that this structure will support multiple transactions running
167- concurrently in one backend, which may be handy if we someday decide
168- to support nested transactions. Currently, the XID field is only needed
169- to distinguish per-transaction locks from session locks. User locks
170- are always session locks, and we also use session locks for multi-
171- transaction operations like VACUUM.
172-
173- holding -
174- The number of successfully acquired locks of each type for this PROCLOCK.
175- This should be <= the corresponding granted[] value of the lock object!
176-
177- nHolding -
178- Sum of the holding[] array.
177+ concurrently in one backend. Currently we do not use it for that
178+ purpose: subtransactions acquire locks in the name of their top parent
179+ transaction, to simplify reassigning lock ownership at subtransaction end.
180+ So the XID field is really only needed to distinguish per-transaction
181+ locks from session locks. User locks are always session locks, and we
182+ also use session locks for multi-transaction operations like VACUUM.
183+
184+ holdMask -
185+ A bitmask for the lock types successfully acquired by this PROCLOCK.
186+ This should be a subset of the LOCK object's grantMask, and also a
187+ subset of the PGPROC object's heldLocks mask.
179188
180189lockLink -
181190 List link for shared memory queue of all the PROCLOCK objects for the
0 commit comments