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

Commit f6ff75f

Browse files
committed
Make BufferIsExclusiveLocked and BufferIsDirty work for local buffers.
These functions tried to check the state of the buffer's content lock even for local buffers. Since we don't use the content lock for a local buffer, that would lead to a "false" result from LWLockHeldByMeInMode, which would mean a misleading "false" answer from BufferIsExclusiveLocked (we'd rather that case always return "true") or an assertion failure in BufferIsDirty. The core code never applies these two functions to local buffers, and apparently no extensions do either, since we've not heard complaints. Still, in the name of future-proofing, let's fix them to act as though a pinned local buffer is content-locked. Author: Srinath Reddy <srinath2133@gmail.com> Discussion: https://postgr.es/m/19396ef77f8.1098c4a1810508.2255483659262451647@zohocorp.com
1 parent 128897b commit f6ff75f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,20 +2472,19 @@ BufferIsExclusiveLocked(Buffer buffer)
24722472
{
24732473
BufferDesc *bufHdr;
24742474

2475+
Assert(BufferIsPinned(buffer));
2476+
24752477
if (BufferIsLocal(buffer))
24762478
{
2477-
int bufid = -buffer - 1;
2478-
2479-
bufHdr = GetLocalBufferDescriptor(bufid);
2479+
/* Content locks are not maintained for local buffers. */
2480+
return true;
24802481
}
24812482
else
24822483
{
24832484
bufHdr = GetBufferDescriptor(buffer - 1);
2485+
return LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
2486+
LW_EXCLUSIVE);
24842487
}
2485-
2486-
Assert(BufferIsPinned(buffer));
2487-
return LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
2488-
LW_EXCLUSIVE);
24892488
}
24902489

24912490
/*
@@ -2501,21 +2500,22 @@ BufferIsDirty(Buffer buffer)
25012500
{
25022501
BufferDesc *bufHdr;
25032502

2503+
Assert(BufferIsPinned(buffer));
2504+
25042505
if (BufferIsLocal(buffer))
25052506
{
25062507
int bufid = -buffer - 1;
25072508

25082509
bufHdr = GetLocalBufferDescriptor(bufid);
2510+
/* Content locks are not maintained for local buffers. */
25092511
}
25102512
else
25112513
{
25122514
bufHdr = GetBufferDescriptor(buffer - 1);
2515+
Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
2516+
LW_EXCLUSIVE));
25132517
}
25142518

2515-
Assert(BufferIsPinned(buffer));
2516-
Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
2517-
LW_EXCLUSIVE));
2518-
25192519
return pg_atomic_read_u32(&bufHdr->state) & BM_DIRTY;
25202520
}
25212521

0 commit comments

Comments
 (0)