Commit 4e9b1594 authored by Tom Lane's avatar Tom Lane

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).
parent 9a2e9c68
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* 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? */
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 */
LWLockAcquire(WALWriteLock, LW_EXCLUSIVE);
LogwrtResult = XLogCtl->Write.LogwrtResult;
if (!XLByteLE(record, LogwrtResult.Flush))
{
WriteRqst.Write = WriteRqstPtr;
WriteRqst.Flush = record;
/* try to write/flush later additions to XLOG as well */
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);
}
LWLockRelease(WALWriteLock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment