mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-24 18:55:04 +08:00
Skip extraneous locking in XLogCheckBuffer().
Heikki reported comment was wrong, so fixed code to match the comment: we only need to take additional locking precautions when we have a shared lock on the buffer.
This commit is contained in:
parent
47c4333189
commit
5787c6730e
@ -646,7 +646,7 @@ static void CreateEndOfRecoveryRecord(void);
|
|||||||
static void CheckPointGuts(XLogRecPtr checkPointRedo, int flags);
|
static void CheckPointGuts(XLogRecPtr checkPointRedo, int flags);
|
||||||
static void KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo);
|
static void KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo);
|
||||||
|
|
||||||
static bool XLogCheckBuffer(XLogRecData *rdata, bool doPageWrites,
|
static bool XLogCheckBuffer(XLogRecData *rdata, bool holdsExclusiveLock,
|
||||||
XLogRecPtr *lsn, BkpBlock *bkpb);
|
XLogRecPtr *lsn, BkpBlock *bkpb);
|
||||||
static Buffer RestoreBackupBlockContents(XLogRecPtr lsn, BkpBlock bkpb,
|
static Buffer RestoreBackupBlockContents(XLogRecPtr lsn, BkpBlock bkpb,
|
||||||
char *blk, bool get_cleanup_lock, bool keep_buffer);
|
char *blk, bool get_cleanup_lock, bool keep_buffer);
|
||||||
@ -822,7 +822,7 @@ begin:;
|
|||||||
{
|
{
|
||||||
/* OK, put it in this slot */
|
/* OK, put it in this slot */
|
||||||
dtbuf[i] = rdt->buffer;
|
dtbuf[i] = rdt->buffer;
|
||||||
if (XLogCheckBuffer(rdt, doPageWrites,
|
if (doPageWrites && XLogCheckBuffer(rdt, true,
|
||||||
&(dtbuf_lsn[i]), &(dtbuf_xlg[i])))
|
&(dtbuf_lsn[i]), &(dtbuf_xlg[i])))
|
||||||
{
|
{
|
||||||
dtbuf_bkp[i] = true;
|
dtbuf_bkp[i] = true;
|
||||||
@ -1243,7 +1243,7 @@ begin:;
|
|||||||
* save the buffer's LSN at *lsn.
|
* save the buffer's LSN at *lsn.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
XLogCheckBuffer(XLogRecData *rdata, bool doPageWrites,
|
XLogCheckBuffer(XLogRecData *rdata, bool holdsExclusiveLock,
|
||||||
XLogRecPtr *lsn, BkpBlock *bkpb)
|
XLogRecPtr *lsn, BkpBlock *bkpb)
|
||||||
{
|
{
|
||||||
Page page;
|
Page page;
|
||||||
@ -1251,15 +1251,17 @@ XLogCheckBuffer(XLogRecData *rdata, bool doPageWrites,
|
|||||||
page = BufferGetPage(rdata->buffer);
|
page = BufferGetPage(rdata->buffer);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX We assume page LSN is first data on *every* page that can be passed
|
* We assume page LSN is first data on *every* page that can be passed
|
||||||
* to XLogInsert, whether it otherwise has the standard page layout or
|
* to XLogInsert, whether it has the standard page layout or not. We
|
||||||
* not. We don't need the buffer header lock for PageGetLSN because we
|
* don't need to take the buffer header lock for PageGetLSN if we hold
|
||||||
* have exclusive lock on the page and/or the relation.
|
* an exclusive lock on the page and/or the relation.
|
||||||
*/
|
*/
|
||||||
*lsn = BufferGetLSNAtomic(rdata->buffer);
|
if (holdsExclusiveLock)
|
||||||
|
*lsn = PageGetLSN(page);
|
||||||
|
else
|
||||||
|
*lsn = BufferGetLSNAtomic(rdata->buffer);
|
||||||
|
|
||||||
if (doPageWrites &&
|
if (*lsn <= RedoRecPtr)
|
||||||
*lsn <= RedoRecPtr)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* The page needs to be backed up, so set up *bkpb
|
* The page needs to be backed up, so set up *bkpb
|
||||||
@ -7683,7 +7685,10 @@ XLogSaveBufferForHint(Buffer buffer)
|
|||||||
rdata[0].buffer = buffer;
|
rdata[0].buffer = buffer;
|
||||||
rdata[0].buffer_std = true;
|
rdata[0].buffer_std = true;
|
||||||
|
|
||||||
if (XLogCheckBuffer(rdata, true, &lsn, &bkpb))
|
/*
|
||||||
|
* Check buffer while not holding an exclusive lock.
|
||||||
|
*/
|
||||||
|
if (XLogCheckBuffer(rdata, false, &lsn, &bkpb))
|
||||||
{
|
{
|
||||||
char copied_buffer[BLCKSZ];
|
char copied_buffer[BLCKSZ];
|
||||||
char *origdata = (char *) BufferGetBlock(buffer);
|
char *origdata = (char *) BufferGetBlock(buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user