Skip to content

Commit e6cba71

Browse files
committed
Add some code to Assert that when we release pin on a buffer, we are
not holding the buffer's cntx_lock or io_in_progress_lock. A recent report from Litao Wu makes me wonder whether it is ever possible for us to drop a buffer and forget to release its cntx_lock. The Assert does not fire in the regression tests, but that proves little ...
1 parent 8d64b56 commit e6cba71

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.169 2004/05/31 20:31:33 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.170 2004/06/11 16:43:23 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -611,7 +611,12 @@ UnpinBuffer(BufferDesc *buf)
611611
Assert(PrivateRefCount[b] > 0);
612612
PrivateRefCount[b]--;
613613
if (PrivateRefCount[b] == 0)
614+
{
614615
buf->refcount--;
616+
/* I'd better not still hold any locks on the buffer */
617+
Assert(!LWLockHeldByMe(buf->cntx_lock));
618+
Assert(!LWLockHeldByMe(buf->io_in_progress_lock));
619+
}
615620

616621
if ((buf->flags & BM_PIN_COUNT_WAITER) != 0 &&
617622
buf->refcount == 1)

src/backend/storage/lmgr/lwlock.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.19 2003/12/20 17:31:21 momjian Exp $
18+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.20 2004/06/11 16:43:24 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -519,3 +519,23 @@ LWLockReleaseAll(void)
519519
LWLockRelease(held_lwlocks[num_held_lwlocks - 1]);
520520
}
521521
}
522+
523+
524+
/*
525+
* LWLockHeldByMe - test whether my process currently holds a lock
526+
*
527+
* This is meant as debug support only. We do not distinguish whether the
528+
* lock is held shared or exclusive.
529+
*/
530+
bool
531+
LWLockHeldByMe(LWLockId lockid)
532+
{
533+
int i;
534+
535+
for (i = 0; i < num_held_lwlocks; i++)
536+
{
537+
if (held_lwlocks[i] == lockid)
538+
return true;
539+
}
540+
return false;
541+
}

src/include/storage/lwlock.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/lwlock.h,v 1.11 2004/05/31 03:48:10 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/lwlock.h,v 1.12 2004/06/11 16:43:24 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -62,6 +62,7 @@ extern void LWLockAcquire(LWLockId lockid, LWLockMode mode);
6262
extern bool LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode);
6363
extern void LWLockRelease(LWLockId lockid);
6464
extern void LWLockReleaseAll(void);
65+
extern bool LWLockHeldByMe(LWLockId lockid);
6566

6667
extern int NumLWLocks(void);
6768
extern int LWLockShmemSize(void);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy