Change order of operations during XLogFlush so that we try to include
in our write/flush operation any WAL entries that got queued while we were waiting to get the WALWriteLock. This improves throughput when transactions are small enough that several can be committed per WAL write (ie, per disk revolution).
This commit is contained in:
parent
9a2e9c6804
commit
4e9b159484
|
@ -7,7 +7,7 @@
|
||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.107 2002/09/26 22:58:33 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.108 2002/10/07 17:04:30 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -1252,28 +1252,33 @@ XLogFlush(XLogRecPtr record)
|
||||||
/* done already? */
|
/* done already? */
|
||||||
if (!XLByteLE(record, LogwrtResult.Flush))
|
if (!XLByteLE(record, LogwrtResult.Flush))
|
||||||
{
|
{
|
||||||
/* if something was added to log cache then try to flush this too */
|
|
||||||
if (LWLockConditionalAcquire(WALInsertLock, LW_EXCLUSIVE))
|
|
||||||
{
|
|
||||||
XLogCtlInsert *Insert = &XLogCtl->Insert;
|
|
||||||
uint32 freespace = INSERT_FREESPACE(Insert);
|
|
||||||
|
|
||||||
if (freespace < SizeOfXLogRecord) /* buffer is full */
|
|
||||||
WriteRqstPtr = XLogCtl->xlblocks[Insert->curridx];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
WriteRqstPtr = XLogCtl->xlblocks[Insert->curridx];
|
|
||||||
WriteRqstPtr.xrecoff -= freespace;
|
|
||||||
}
|
|
||||||
LWLockRelease(WALInsertLock);
|
|
||||||
}
|
|
||||||
/* now wait for the write lock */
|
/* now wait for the write lock */
|
||||||
LWLockAcquire(WALWriteLock, LW_EXCLUSIVE);
|
LWLockAcquire(WALWriteLock, LW_EXCLUSIVE);
|
||||||
LogwrtResult = XLogCtl->Write.LogwrtResult;
|
LogwrtResult = XLogCtl->Write.LogwrtResult;
|
||||||
if (!XLByteLE(record, LogwrtResult.Flush))
|
if (!XLByteLE(record, LogwrtResult.Flush))
|
||||||
{
|
{
|
||||||
WriteRqst.Write = WriteRqstPtr;
|
/* try to write/flush later additions to XLOG as well */
|
||||||
WriteRqst.Flush = record;
|
if (LWLockConditionalAcquire(WALInsertLock, LW_EXCLUSIVE))
|
||||||
|
{
|
||||||
|
XLogCtlInsert *Insert = &XLogCtl->Insert;
|
||||||
|
uint32 freespace = INSERT_FREESPACE(Insert);
|
||||||
|
|
||||||
|
if (freespace < SizeOfXLogRecord) /* buffer is full */
|
||||||
|
WriteRqstPtr = XLogCtl->xlblocks[Insert->curridx];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WriteRqstPtr = XLogCtl->xlblocks[Insert->curridx];
|
||||||
|
WriteRqstPtr.xrecoff -= freespace;
|
||||||
|
}
|
||||||
|
LWLockRelease(WALInsertLock);
|
||||||
|
WriteRqst.Write = WriteRqstPtr;
|
||||||
|
WriteRqst.Flush = WriteRqstPtr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WriteRqst.Write = WriteRqstPtr;
|
||||||
|
WriteRqst.Flush = record;
|
||||||
|
}
|
||||||
XLogWrite(WriteRqst);
|
XLogWrite(WriteRqst);
|
||||||
}
|
}
|
||||||
LWLockRelease(WALWriteLock);
|
LWLockRelease(WALWriteLock);
|
||||||
|
|
Loading…
Reference in New Issue