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

Commit 2584029

Browse files
committed
Rename locking structure names to be clearer. Add narrative to
backend flowchart.
1 parent f21fa6a commit 2584029

File tree

9 files changed

+324
-311
lines changed

9 files changed

+324
-311
lines changed

src/backend/storage/lmgr/lock.c

+188-188
Large diffs are not rendered by default.

src/backend/storage/lmgr/multi.c

+44-42
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/multi.c,v 1.18 1998/06/28 21:17:35 momjian Exp $
15+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/multi.c,v 1.19 1998/06/30 02:33:31 momjian Exp $
1616
*
1717
* NOTES:
1818
* (1) The lock.c module assumes that the caller here is doing
@@ -30,10 +30,10 @@
3030
#include "miscadmin.h" /* MyDatabaseId */
3131

3232
static bool
33-
MultiAcquire(LockTableId tableId, LOCKTAG *tag, LOCKTYPE locktype,
33+
MultiAcquire(LOCKMETHOD lockmethod, LOCKTAG *tag, LOCKMODE lockmode,
3434
PG_LOCK_LEVEL level);
3535
static bool
36-
MultiRelease(LockTableId tableId, LOCKTAG *tag, LOCKTYPE locktype,
36+
MultiRelease(LOCKMETHOD lockmethod, LOCKTAG *tag, LOCKMODE lockmode,
3737
PG_LOCK_LEVEL level);
3838

3939
/*
@@ -78,25 +78,27 @@ static int MultiPrios[] = {
7878
* Lock table identifier for this lock table. The multi-level
7979
* lock table is ONE lock table, not three.
8080
*/
81-
LockTableId MultiTableId = (LockTableId) NULL;
82-
LockTableId ShortTermTableId = (LockTableId) NULL;
81+
LOCKMETHOD MultiTableId = (LOCKMETHOD) NULL;
82+
#ifdef NOT_USED
83+
LOCKMETHOD ShortTermTableId = (LOCKMETHOD) NULL;
84+
#endif
8385

8486
/*
8587
* Create the lock table described by MultiConflicts and Multiprio.
8688
*/
87-
LockTableId
89+
LOCKMETHOD
8890
InitMultiLevelLocks()
8991
{
90-
int tableId;
92+
int lockmethod;
9193

92-
tableId = LockTableInit("LockTable", MultiConflicts, MultiPrios, 5);
93-
MultiTableId = tableId;
94+
lockmethod = LockMethodTableInit("MultiLevelLockTable", MultiConflicts, MultiPrios, 5);
95+
MultiTableId = lockmethod;
9496
if (!(MultiTableId))
9597
elog(ERROR, "InitMultiLocks: couldnt initialize lock table");
9698
/* -----------------------
9799
* No short term lock table for now. -Jeff 15 July 1991
98100
*
99-
* ShortTermTableId = LockTableRename(tableId);
101+
* ShortTermTableId = LockTableRename(lockmethod);
100102
* if (! (ShortTermTableId)) {
101103
* elog(ERROR,"InitMultiLocks: couldnt rename lock table");
102104
* }
@@ -111,7 +113,7 @@ InitMultiLevelLocks()
111113
* Returns: TRUE if the lock can be set, FALSE otherwise.
112114
*/
113115
bool
114-
MultiLockReln(LockInfo linfo, LOCKTYPE locktype)
116+
MultiLockReln(LockInfo linfo, LOCKMODE lockmode)
115117
{
116118
LOCKTAG tag;
117119

@@ -122,7 +124,7 @@ MultiLockReln(LockInfo linfo, LOCKTYPE locktype)
122124
MemSet(&tag, 0, sizeof(tag));
123125
tag.relId = linfo->lRelId.relId;
124126
tag.dbId = linfo->lRelId.dbId;
125-
return (MultiAcquire(MultiTableId, &tag, locktype, RELN_LEVEL));
127+
return (MultiAcquire(MultiTableId, &tag, lockmode, RELN_LEVEL));
126128
}
127129

128130
/*
@@ -134,7 +136,7 @@ MultiLockReln(LockInfo linfo, LOCKTYPE locktype)
134136
* at the page and relation level.
135137
*/
136138
bool
137-
MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
139+
MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode)
138140
{
139141
LOCKTAG tag;
140142

@@ -149,14 +151,14 @@ MultiLockTuple(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
149151

150152
/* not locking any valid Tuple, just the page */
151153
tag.tupleId = *tidPtr;
152-
return (MultiAcquire(MultiTableId, &tag, locktype, TUPLE_LEVEL));
154+
return (MultiAcquire(MultiTableId, &tag, lockmode, TUPLE_LEVEL));
153155
}
154156

155157
/*
156158
* same as above at page level
157159
*/
158160
bool
159-
MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
161+
MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode)
160162
{
161163
LOCKTAG tag;
162164

@@ -179,7 +181,7 @@ MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
179181
tag.relId = linfo->lRelId.relId;
180182
tag.dbId = linfo->lRelId.dbId;
181183
BlockIdCopy(&(tag.tupleId.ip_blkid), &(tidPtr->ip_blkid));
182-
return (MultiAcquire(MultiTableId, &tag, locktype, PAGE_LEVEL));
184+
return (MultiAcquire(MultiTableId, &tag, lockmode, PAGE_LEVEL));
183185
}
184186

185187
/*
@@ -189,12 +191,12 @@ MultiLockPage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
189191
* Side Effects:
190192
*/
191193
static bool
192-
MultiAcquire(LockTableId tableId,
194+
MultiAcquire(LOCKMETHOD lockmethod,
193195
LOCKTAG *tag,
194-
LOCKTYPE locktype,
196+
LOCKMODE lockmode,
195197
PG_LOCK_LEVEL level)
196198
{
197-
LOCKTYPE locks[N_LEVELS];
199+
LOCKMODE locks[N_LEVELS];
198200
int i,
199201
status;
200202
LOCKTAG xxTag,
@@ -213,19 +215,19 @@ MultiAcquire(LockTableId tableId,
213215
switch (level)
214216
{
215217
case RELN_LEVEL:
216-
locks[0] = locktype;
218+
locks[0] = lockmode;
217219
locks[1] = NO_LOCK;
218220
locks[2] = NO_LOCK;
219221
break;
220222
case PAGE_LEVEL:
221-
locks[0] = locktype + INTENT;
222-
locks[1] = locktype;
223+
locks[0] = lockmode + INTENT;
224+
locks[1] = lockmode;
223225
locks[2] = NO_LOCK;
224226
break;
225227
case TUPLE_LEVEL:
226-
locks[0] = locktype + INTENT;
227-
locks[1] = locktype + INTENT;
228-
locks[2] = locktype;
228+
locks[0] = lockmode + INTENT;
229+
locks[1] = lockmode + INTENT;
230+
locks[2] = lockmode;
229231
break;
230232
default:
231233
elog(ERROR, "MultiAcquire: bad lock level");
@@ -274,7 +276,7 @@ MultiAcquire(LockTableId tableId,
274276
break;
275277
}
276278

277-
status = LockAcquire(tableId, tmpTag, locks[i]);
279+
status = LockAcquire(lockmethod, tmpTag, locks[i]);
278280
if (!status)
279281
{
280282

@@ -285,7 +287,7 @@ MultiAcquire(LockTableId tableId,
285287
* the last level lock we successfully acquired
286288
*/
287289
retStatus = FALSE;
288-
MultiRelease(tableId, tag, locktype, i);
290+
MultiRelease(lockmethod, tag, lockmode, i);
289291
/* now leave the loop. Don't try for any more locks */
290292
break;
291293
}
@@ -300,7 +302,7 @@ MultiAcquire(LockTableId tableId,
300302
*/
301303
#ifdef NOT_USED
302304
bool
303-
MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
305+
MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKMODE lockmode)
304306
{
305307
LOCKTAG tag;
306308

@@ -316,7 +318,7 @@ MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
316318
tag.dbId = linfo->lRelId.dbId;
317319
BlockIdCopy(&(tag.tupleId.ip_blkid), &(tidPtr->ip_blkid));
318320

319-
return (MultiRelease(MultiTableId, &tag, locktype, PAGE_LEVEL));
321+
return (MultiRelease(MultiTableId, &tag, lockmode, PAGE_LEVEL));
320322
}
321323

322324
#endif
@@ -326,7 +328,7 @@ MultiReleasePage(LockInfo linfo, ItemPointer tidPtr, LOCKTYPE locktype)
326328
* ------------------
327329
*/
328330
bool
329-
MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype)
331+
MultiReleaseReln(LockInfo linfo, LOCKMODE lockmode)
330332
{
331333
LOCKTAG tag;
332334

@@ -340,7 +342,7 @@ MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype)
340342
tag.relId = linfo->lRelId.relId;
341343
tag.dbId = linfo->lRelId.dbId;
342344

343-
return (MultiRelease(MultiTableId, &tag, locktype, RELN_LEVEL));
345+
return (MultiRelease(MultiTableId, &tag, lockmode, RELN_LEVEL));
344346
}
345347

346348
/*
@@ -349,12 +351,12 @@ MultiReleaseReln(LockInfo linfo, LOCKTYPE locktype)
349351
* Returns: TRUE if successful, FALSE otherwise.
350352
*/
351353
static bool
352-
MultiRelease(LockTableId tableId,
354+
MultiRelease(LOCKMETHOD lockmethod,
353355
LOCKTAG *tag,
354-
LOCKTYPE locktype,
356+
LOCKMODE lockmode,
355357
PG_LOCK_LEVEL level)
356358
{
357-
LOCKTYPE locks[N_LEVELS];
359+
LOCKMODE locks[N_LEVELS];
358360
int i,
359361
status;
360362
LOCKTAG xxTag,
@@ -366,22 +368,22 @@ MultiRelease(LockTableId tableId,
366368
switch (level)
367369
{
368370
case RELN_LEVEL:
369-
locks[0] = locktype;
371+
locks[0] = lockmode;
370372
locks[1] = NO_LOCK;
371373
locks[2] = NO_LOCK;
372374
break;
373375
case PAGE_LEVEL:
374-
locks[0] = locktype + INTENT;
375-
locks[1] = locktype;
376+
locks[0] = lockmode + INTENT;
377+
locks[1] = lockmode;
376378
locks[2] = NO_LOCK;
377379
break;
378380
case TUPLE_LEVEL:
379-
locks[0] = locktype + INTENT;
380-
locks[1] = locktype + INTENT;
381-
locks[2] = locktype;
381+
locks[0] = lockmode + INTENT;
382+
locks[1] = lockmode + INTENT;
383+
locks[2] = lockmode;
382384
break;
383385
default:
384-
elog(ERROR, "MultiRelease: bad locktype");
386+
elog(ERROR, "MultiRelease: bad lockmode");
385387
}
386388

387389
/*
@@ -423,7 +425,7 @@ MultiRelease(LockTableId tableId,
423425
ItemPointerCopy(&tmpTag->tupleId, &tag->tupleId);
424426
break;
425427
}
426-
status = LockRelease(tableId, tmpTag, locks[i]);
428+
status = LockRelease(lockmethod, tmpTag, locks[i]);
427429
if (!status)
428430
elog(ERROR, "MultiRelease: couldn't release after error");
429431
}

src/backend/storage/lmgr/proc.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.38 1998/06/27 15:47:46 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.39 1998/06/30 02:33:32 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -46,7 +46,7 @@
4646
* This is so that we can support more backends. (system-wide semaphore
4747
* sets run out pretty fast.) -ay 4/95
4848
*
49-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.38 1998/06/27 15:47:46 momjian Exp $
49+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.39 1998/06/30 02:33:32 momjian Exp $
5050
*/
5151
#include <sys/time.h>
5252
#include <unistd.h>
@@ -580,7 +580,7 @@ ProcWakeup(PROC *proc, int errType)
580580
* released.
581581
*/
582582
int
583-
ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock)
583+
ProcLockWakeup(PROC_QUEUE *queue, LOCKMETHOD lockmethod, LOCK *lock)
584584
{
585585
PROC *proc;
586586
int count;
@@ -590,8 +590,8 @@ ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock)
590590

591591
proc = (PROC *) MAKE_PTR(queue->links.prev);
592592
count = 0;
593-
while ((LockResolveConflicts((LOCKTAB *) ltable,
594-
(LOCK *) lock,
593+
while ((LockResolveConflicts(lockmethod,
594+
lock,
595595
proc->token,
596596
proc->xid) == STATUS_OK))
597597
{
@@ -602,7 +602,7 @@ ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock)
602602
* between the time we release the lock master (spinlock) and the
603603
* time that the awoken process begins executing again.
604604
*/
605-
GrantLock((LOCK *) lock, proc->token);
605+
GrantLock(lock, proc->token);
606606
queue->size--;
607607

608608
/*

src/backend/storage/lmgr/single.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/single.c,v 1.6 1998/06/28 21:17:35 momjian Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/single.c,v 1.7 1998/06/30 02:33:32 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -32,7 +32,7 @@
3232
* Returns: TRUE if the lock can be set, FALSE otherwise.
3333
*/
3434
bool
35-
SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action)
35+
SingleLockReln(LockInfo linfo, LOCKMODE lockmode, int action)
3636
{
3737
LOCKTAG tag;
3838

@@ -47,9 +47,9 @@ SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action)
4747
tag.tupleId.ip_posid = InvalidOffsetNumber;
4848

4949
if (action == UNLOCK)
50-
return (LockRelease(MultiTableId, &tag, locktype));
50+
return (LockRelease(MultiTableId, &tag, lockmode));
5151
else
52-
return (LockAcquire(MultiTableId, &tag, locktype));
52+
return (LockAcquire(MultiTableId, &tag, lockmode));
5353
}
5454

5555
/*
@@ -63,7 +63,7 @@ SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action)
6363
bool
6464
SingleLockPage(LockInfo linfo,
6565
ItemPointer tidPtr,
66-
LOCKTYPE locktype,
66+
LOCKMODE lockmode,
6767
int action)
6868
{
6969
LOCKTAG tag;
@@ -80,7 +80,7 @@ SingleLockPage(LockInfo linfo,
8080

8181

8282
if (action == UNLOCK)
83-
return (LockRelease(MultiTableId, &tag, locktype));
83+
return (LockRelease(MultiTableId, &tag, lockmode));
8484
else
85-
return (LockAcquire(MultiTableId, &tag, locktype));
85+
return (LockAcquire(MultiTableId, &tag, lockmode));
8686
}

src/include/storage/lmgr.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: lmgr.h,v 1.11 1998/06/28 21:17:35 momjian Exp $
9+
* $Id: lmgr.h,v 1.12 1998/06/30 02:33:32 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -72,10 +72,10 @@ extern void RelationSetWIntentLock(Relation relation);
7272
extern void RelationUnsetWIntentLock(Relation relation);
7373

7474
/* single.c */
75-
extern bool SingleLockReln(LockInfo linfo, LOCKTYPE locktype, int action);
75+
extern bool SingleLockReln(LockInfo linfo, LOCKMODE lockmode, int action);
7676
extern bool
7777
SingleLockPage(LockInfo linfo, ItemPointer tidPtr,
78-
LOCKTYPE locktype, int action);
78+
LOCKMODE lockmode, int action);
7979

8080
/* proc.c */
8181
extern void InitProcGlobal(IPCKey key);

0 commit comments

Comments
 (0)