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

Commit 819b69a

Browse files
committed
bufmgr: Add some more error checking [infrastructure] around pinning
This adds a few more assertions against a buffer being local in places we don't expect, and extracts the check for a buffer being pinned exactly once from LockBufferForCleanup() into its own function. Later commits will use this function. Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Reviewed-by: Melanie Plageman <melanieplageman@gmail.com> Discussion: http://postgr.es/m/419312fd-9255-078c-c3e3-f0525f911d7f@iki.fi
1 parent 4d330a6 commit 819b69a

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,8 @@ PinBuffer(BufferDesc *buf, BufferAccessStrategy strategy)
17351735
bool result;
17361736
PrivateRefCountEntry *ref;
17371737

1738+
Assert(!BufferIsLocal(b));
1739+
17381740
ref = GetPrivateRefCountEntry(b, true);
17391741

17401742
if (ref == NULL)
@@ -1880,6 +1882,8 @@ UnpinBuffer(BufferDesc *buf)
18801882
PrivateRefCountEntry *ref;
18811883
Buffer b = BufferDescriptorGetBuffer(buf);
18821884

1885+
Assert(!BufferIsLocal(b));
1886+
18831887
/* not moving as we're likely deleting it soon anyway */
18841888
ref = GetPrivateRefCountEntry(b, false);
18851889
Assert(ref != NULL);
@@ -4253,6 +4257,29 @@ ConditionalLockBuffer(Buffer buffer)
42534257
LW_EXCLUSIVE);
42544258
}
42554259

4260+
/*
4261+
* Verify that this backend is pinning the buffer exactly once.
4262+
*
4263+
* NOTE: Like in BufferIsPinned(), what we check here is that *this* backend
4264+
* holds a pin on the buffer. We do not care whether some other backend does.
4265+
*/
4266+
void
4267+
CheckBufferIsPinnedOnce(Buffer buffer)
4268+
{
4269+
if (BufferIsLocal(buffer))
4270+
{
4271+
if (LocalRefCount[-buffer - 1] != 1)
4272+
elog(ERROR, "incorrect local pin count: %d",
4273+
LocalRefCount[-buffer - 1]);
4274+
}
4275+
else
4276+
{
4277+
if (GetPrivateRefCount(buffer) != 1)
4278+
elog(ERROR, "incorrect local pin count: %d",
4279+
GetPrivateRefCount(buffer));
4280+
}
4281+
}
4282+
42564283
/*
42574284
* LockBufferForCleanup - lock a buffer in preparation for deleting items
42584285
*
@@ -4280,20 +4307,11 @@ LockBufferForCleanup(Buffer buffer)
42804307
Assert(BufferIsPinned(buffer));
42814308
Assert(PinCountWaitBuf == NULL);
42824309

4310+
CheckBufferIsPinnedOnce(buffer);
4311+
4312+
/* Nobody else to wait for */
42834313
if (BufferIsLocal(buffer))
4284-
{
4285-
/* There should be exactly one pin */
4286-
if (LocalRefCount[-buffer - 1] != 1)
4287-
elog(ERROR, "incorrect local pin count: %d",
4288-
LocalRefCount[-buffer - 1]);
4289-
/* Nobody else to wait for */
42904314
return;
4291-
}
4292-
4293-
/* There should be exactly one local pin */
4294-
if (GetPrivateRefCount(buffer) != 1)
4295-
elog(ERROR, "incorrect local pin count: %d",
4296-
GetPrivateRefCount(buffer));
42974315

42984316
bufHdr = GetBufferDescriptor(buffer - 1);
42994317

@@ -4794,6 +4812,8 @@ LockBufHdr(BufferDesc *desc)
47944812
SpinDelayStatus delayStatus;
47954813
uint32 old_buf_state;
47964814

4815+
Assert(!BufferIsLocal(BufferDescriptorGetBuffer(desc)));
4816+
47974817
init_local_spin_delay(&delayStatus);
47984818

47994819
while (true)

src/include/storage/bufmgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ extern void ReleaseBuffer(Buffer buffer);
134134
extern void UnlockReleaseBuffer(Buffer buffer);
135135
extern void MarkBufferDirty(Buffer buffer);
136136
extern void IncrBufferRefCount(Buffer buffer);
137+
extern void CheckBufferIsPinnedOnce(Buffer buffer);
137138
extern Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation,
138139
BlockNumber blockNum);
139140

0 commit comments

Comments
 (0)