mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
Assert that buffers are marked dirty before XLogRegisterBuffer().
Enforce the rule from transam/README in XLogRegisterBuffer(), and update callers to follow the rule. Hash indexes sometimes register clean pages as a part of the locking protocol, so provide a REGBUF_NO_CHANGE flag to support that use. Discussion: https://postgr.es/m/c84114f8-c7f1-5b57-f85a-3adc31e1a904@iki.fi Reviewed-by: Heikki Linnakangas
This commit is contained in:
@ -2098,6 +2098,65 @@ ExtendBufferedRelShared(BufferManagerRelation bmr,
|
||||
return first_block;
|
||||
}
|
||||
|
||||
/*
|
||||
* BufferIsExclusiveLocked
|
||||
*
|
||||
* Checks if buffer is exclusive-locked.
|
||||
*
|
||||
* Buffer must be pinned.
|
||||
*/
|
||||
bool
|
||||
BufferIsExclusiveLocked(Buffer buffer)
|
||||
{
|
||||
BufferDesc *bufHdr;
|
||||
|
||||
if (BufferIsLocal(buffer))
|
||||
{
|
||||
int bufid = -buffer - 1;
|
||||
|
||||
bufHdr = GetLocalBufferDescriptor(bufid);
|
||||
}
|
||||
else
|
||||
{
|
||||
bufHdr = GetBufferDescriptor(buffer - 1);
|
||||
}
|
||||
|
||||
Assert(BufferIsPinned(buffer));
|
||||
return LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
|
||||
LW_EXCLUSIVE);
|
||||
}
|
||||
|
||||
/*
|
||||
* BufferIsDirty
|
||||
*
|
||||
* Checks if buffer is already dirty.
|
||||
*
|
||||
* Buffer must be pinned and exclusive-locked. (Without an exclusive lock,
|
||||
* the result may be stale before it's returned.)
|
||||
*/
|
||||
bool
|
||||
BufferIsDirty(Buffer buffer)
|
||||
{
|
||||
BufferDesc *bufHdr;
|
||||
|
||||
if (BufferIsLocal(buffer))
|
||||
{
|
||||
int bufid = -buffer - 1;
|
||||
|
||||
bufHdr = GetLocalBufferDescriptor(bufid);
|
||||
}
|
||||
else
|
||||
{
|
||||
bufHdr = GetBufferDescriptor(buffer - 1);
|
||||
}
|
||||
|
||||
Assert(BufferIsPinned(buffer));
|
||||
Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
|
||||
LW_EXCLUSIVE));
|
||||
|
||||
return pg_atomic_read_u32(&bufHdr->state) & BM_DIRTY;
|
||||
}
|
||||
|
||||
/*
|
||||
* MarkBufferDirty
|
||||
*
|
||||
|
Reference in New Issue
Block a user