Idea for better handling of cntxDirty

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Vadim Mikheev <vmikheev(at)sectorbase(dot)com>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Idea for better handling of cntxDirty
Date: 2002-11-12 01:51:39
Message-ID: 20057.1037065899@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Vadim,

In LockBuffer() you wrote

else if (mode == BUFFER_LOCK_EXCLUSIVE)
{
LWLockAcquire(buf->cntx_lock, LW_EXCLUSIVE);

/*
* This is not the best place to set cntxDirty flag (eg indices do
* not always change buffer they lock in excl mode). But please
* remember that it's critical to set cntxDirty *before* logging
* changes with XLogInsert() - see comments in BufferSync().
*/
buf->cntxDirty = true;
}

The comments in BufferSynx are

/*
* We can check bufHdr->cntxDirty here *without* holding any lock
* on buffer context as long as we set this flag in access methods
* *before* logging changes with XLogInsert(): if someone will set
* cntxDirty just after our check we don't worry because of our
* checkpoint.redo points before log record for upcoming changes
* and so we are not required to write such dirty buffer.
*/

Wouldn't it work for cntxDirty to be set not by LockBuffer, but by
XLogInsert for each buffer that is included in its argument list?
This would avoid setting the flag for pages that are not modified
after being locked. XLogInsert would of course set the flag before
doing the actual WAL insertion, so it seems to me that the condition
we want is met, and we still have only a single place that needs to
remember to set the flag.

regards, tom lane

Browse pgsql-hackers by date

  From Date Subject
Next Message Kris Jurka 2002-11-12 03:00:33 Unique functional index and FK constraints
Previous Message Tom Lane 2002-11-12 01:32:05 Re: 500 tpsQL + WAL log implementation