Correction re existing WAL behavior

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Curtis Faith <curtis(at)galtair(dot)com>, Hannu Krosing <hannu(at)tm(dot)ee>, Pgsql-Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Correction re existing WAL behavior
Date: 2002-10-05 23:45:49
Message-ID: 6269.1033861549@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I spent a little time reviewing the xlog.c logic, which I hadn't looked
at in awhile. I see I made a mistake earlier: I claimed that only when
a backend wanted to commit or ran out of space in the WAL buffers would
it issue any write(). This is not true: there is code in XLogInsert()
that will try to issue write() if the WAL buffers are more than half
full:

/*
* If cache is half filled then try to acquire write lock and do
* XLogWrite. Ignore any fractional blocks in performing this check.
*/
LogwrtRqst.Write.xrecoff -= LogwrtRqst.Write.xrecoff % BLCKSZ;
if (LogwrtRqst.Write.xlogid != LogwrtResult.Write.xlogid ||
(LogwrtRqst.Write.xrecoff >= LogwrtResult.Write.xrecoff +
XLogCtl->XLogCacheByte / 2))
{
if (LWLockConditionalAcquire(WALWriteLock, LW_EXCLUSIVE))
{
LogwrtResult = XLogCtl->Write.LogwrtResult;
if (XLByteLT(LogwrtResult.Write, LogwrtRqst.Write))
XLogWrite(LogwrtRqst);
LWLockRelease(WALWriteLock);
}
}

Because of the "conditional acquire" call, this will not block if
someone else is currently doing a WAL write or fsync, but will just
fall through in that case. However, if the code does acquire the
lock then the backend will issue some writes --- synchronously, if
O_SYNC or O_DSYNC mode is being used. It would be better to remove
this code and allow a background process to issue writes for filled
WAL pages.

Note this is done before acquiring WALInsertLock, so it does not block
other would-be inserters of WAL records.

regards, tom lane

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2002-10-05 23:53:51 Re: New lock types
Previous Message Mitch 2002-10-05 23:31:46 Mailing list unsubscribe - hackers isn't there?